Commit 6e990dfd authored by exofri's avatar exofri
Browse files

init commit time step=26

parent be5ed4f6
%% Cell type:code id: tags:
``` python
import pandas as pd
import random
import csv
NUMBER_TRADERS=6
# input_file="https://raw.githubusercontent.com/exofri/TestAction/main/ENSIM_trade.csv"
input_file="../ENSIM_trade.csv"
df = pd.read_csv(input_file)
input_trade=df.to_numpy()
time_step=0
buyer_values=[10000,10000,10000,10000]
seller_values=[10000,10000,10000,10000]
rand_values=[10000,10000,10000,10000]
header=["Time step","ratio1","ratio2","ratio3"]
out_str=[time_step,input_trade[time_step][0],input_trade[time_step][1],input_trade[time_step][2]]
out_str=input_trade[time_step]
with open('ENSIM_trade_ratio.csv', 'w') as f:
wr = csv.writer(f,delimiter=",")
wr.writerow(header)
wr.writerow(out_str)
print(out_str)
header=["Time step",
"random_money","random_p1","random_p2","random_p3","random_total_values",
"buyer_money","buyer_p1","buyer_p2","buyer_p3","buyer_total_values",
"seller_money","seller_p1","seller_p2","seller_p3","seller_total_values"]
with open('ENSIM_trade_log_general.csv', 'w') as f:
wr = csv.writer(f,delimiter=",")
wr.writerow(header)
p_values=[]
for trdr in range(NUMBER_TRADERS):
p_values.append([10000,10000,10000,10000])
header_trader=["Time step",
f"trader_{trdr}_money",
f"trader_{trdr}_p1",
f"trader_{trdr}_p2",
f"trader_{trdr}_p3",
f"trader_{trdr}_total_values"]
with open(f"ENSIM_trade_log_trader_{trdr}.csv", 'w') as f:
wr = csv.writer(f,delimiter=",")
wr.writerow(header_trader)
def new_val_old(rate,values_total,x):
values_total[0]=values_total[0]-rate[1]*x[0]*100-rate[2]*x[1]*100-rate[3]*x[2]*100
values_total[1]=values_total[1]+(x[0]/rate[1])*100
values_total[2]=values_total[2]+(x[1]/rate[2])*100
values_total[3]=values_total[3]+(x[2]/rate[3])*100
return values_total,values_total[0]+values_total[1]*rate[1]+values_total[2]*rate[2]+values_total[3]*rate[3]
def new_val(rate,values_total,x):
values_total[0]=values_total[0]-rate[1]*x[0]*100-rate[2]*x[1]*100-rate[3]*x[2]*100
values_total[1]=values_total[1]+(x[0])*100
values_total[2]=values_total[2]+(x[1])*100
values_total[3]=values_total[3]+(x[2])*100
return values_total,values_total[0]+values_total[1]*rate[1]+values_total[2]*rate[2]+values_total[3]*rate[3]
for i in range(20):
out_str=[time_step+1,input_trade[time_step+1][0],input_trade[time_step+1][1],input_trade[time_step+1][2]]
out_str=input_trade[time_step+1]
with open('ENSIM_trade_ratio.csv', 'a') as f:
wr = csv.writer(f,delimiter=",")
wr.writerow(out_str)
print(out_str)
rate1=input_trade[time_step][1]
rate2=input_trade[time_step][2]
rate3=input_trade[time_step][3]
rand_trade=[2*random.random()-1,2*random.random()-1,2*random.random()-1]
buyer_trade=[random.random(),random.random(),random.random()]
seller_trade=[-1*random.random(),-1*random.random(),-1*random.random()]
rand_values,rand_total = new_val(input_trade[time_step],rand_values,rand_trade)
buyer_values,buyer_total = new_val(input_trade[time_step],buyer_values,buyer_trade)
seller_values,seller_total = new_val(input_trade[time_step],seller_values,seller_trade)
trade_record=[time_step]
trade_record+=rand_values+[rand_total]
trade_record+=buyer_values+[buyer_total]
trade_record+=seller_values+[seller_total]
with open('ENSIM_trade_log_general.csv', 'a') as f:
wr = csv.writer(f,delimiter=",")
wr.writerow(trade_record)
for trdr in range(NUMBER_TRADERS):
p_trade=[0,0,0]
p_values[trdr],p_total = new_val(input_trade[time_step],p_values[trdr],p_trade)
trade_record_p = [time_step]+p_values[trdr]+[p_total]
with open(f"ENSIM_trade_log_trader_{trdr}.csv", 'a') as f:
wr = csv.writer(f,delimiter=",")
wr.writerow(trade_record_p)
time_step+=1
```
%% Output
[0. 1.16567143 1.12907365 0.46749942]
[1. 1.27828894 1.36377368 1.01719636]
[2. 1.44194117 1.30215687 1.35894264]
[3. 1.42618353 1.4321547 1.45894688]
[4. 1.52280101 1.51068944 1.81721461]
[5. 1.63140666 1.48757506 1.89978754]
[6. 1.79475194 1.42327759 1.987904 ]
[7. 1.8256988 1.40493666 1.86164337]
[8. 1.93594007 1.5742566 1.51232882]
[9. 1.90852086 1.54525636 1.33586944]
[10. 1.97654446 1.5745468 0.63010167]
[11. 2.04970247 1.69888377 0.39247847]
[12. 2.08125305 1.73434514 0.21765463]
[13. 2.0948874 1.63737951 0.3318933 ]
[14. 2.08844149 1.80643341 0.68768353]
[15. 2.09995016 1.83695447 0.95719272]
[16. 2.09882876 1.74379267 1.09755195]
[17. 2.05223098 1.80484972 1.08899036]
[18. 2.05531019 1.92010157 1.23941048]
[19. 1.97730832 1.94169506 1.02591638]
[20. 1.91755202 1.89176219 0.90381614]
%% Cell type:code id: tags:
``` python
!git add .
!git commit -m "init commit time step=20"
!git push
```
%% Output
[main c1fdf49] init commit time step=20
9 files changed, 168 insertions(+), 165 deletions(-)
rewrite ENSIM_trade_log_general.csv (96%)
rewrite ENSIM_trade_log_trader_0.csv (93%)
rewrite ENSIM_trade_log_trader_1.csv (93%)
rewrite ENSIM_trade_log_trader_2.csv (93%)
rewrite ENSIM_trade_log_trader_3.csv (93%)
rewrite ENSIM_trade_log_trader_4.csv (93%)
rewrite ENSIM_trade_log_trader_5.csv (93%)
[main 2ca7186] init commit time step=20
9 files changed, 44 insertions(+), 102 deletions(-)
rewrite ENSIM_trade_log_general.csv (97%)
Enumerating objects: 21, done.
Counting objects: 100% (21/21), done.
Delta compression using up to 8 threads
Compressing objects: 100% (10/10), done.
Writing objects: 100% (11/11), 3.97 KiB | 1.98 MiB/s, done.
Total 11 (delta 9), reused 1 (delta 1)
Compressing objects: 100% (11/11), done.
Writing objects: 100% (11/11), 3.87 KiB | 1.93 MiB/s, done.
Total 11 (delta 9), reused 0 (delta 0)
To https://git-lium.univ-lemans.fr/mshamsi/ensim_trade_center.git
3d1d69a..c1fdf49 main -> main
1557021..2ca7186 main -> main
%% Cell type:markdown id: tags:
# Start
%% Cell type:code id: tags:
``` python
# out_str=[time_step+1]+[input_trade[time_step+1][0],input_trade[time_step+1][1],input_trade[time_step+1][2]]
print("time_step",time_step)
out_str=input_trade[time_step+1]
with open('ENSIM_trade_ratio.csv', 'a') as f:
wr = csv.writer(f,delimiter=",")
wr.writerow(out_str)
rate1=input_trade[time_step][1]
rate2=input_trade[time_step][2]
rate3=input_trade[time_step][3]
rand_trade=[2*random.random()-1,2*random.random()-1,2*random.random()-1]
buyer_trade=[random.random(),random.random(),random.random()]
seller_trade=[-1*random.random(),-1*random.random(),-1*random.random()]
rand_values,rand_total = new_val(input_trade[time_step],rand_values,rand_trade)
buyer_values,buyer_total = new_val(input_trade[time_step],buyer_values,buyer_trade)
seller_values,seller_total = new_val(input_trade[time_step],seller_values,seller_trade)
trade_record=[time_step]
trade_record+=rand_values+[rand_total]
trade_record+=buyer_values+[buyer_total]
trade_record+=seller_values+[seller_total]
with open('ENSIM_trade_log_general.csv', 'a') as f:
wr = csv.writer(f,delimiter=",")
wr.writerow(trade_record)
dic_trad={
0:[0,0,0],
1:[0,0,0],
2:[-1,-1,-1],
3:[-1,0,0],
4:[0,0,0],
5:[0,0,1]
}
for trdr in range(NUMBER_TRADERS):
p_trade=dic_trad[trdr]
p_values[trdr],p_total = new_val(input_trade[time_step],p_values[trdr],p_trade)
trade_record_p = [time_step]+p_values[trdr]+[p_total]
with open(f"ENSIM_trade_log_trader_{trdr}.csv", 'a') as f:
wr = csv.writer(f,delimiter=",")
wr.writerow(trade_record_p)
time_step+=1
print("time_step",time_step)
```
%% Output
time_step 20
time_step 21
%% Cell type:code id: tags:
``` python
!git add .
!git commit -m "init commit time step=21"
!git push
```
%% Output
[main abaefe7] init commit time step=21
[main b308ef1] init commit time step=21
8 files changed, 8 insertions(+)
Enumerating objects: 19, done.
Counting objects: 100% (19/19), done.
Delta compression using up to 8 threads
Compressing objects: 100% (10/10), done.
Writing objects: 100% (10/10), 1.16 KiB | 1.16 MiB/s, done.
Total 10 (delta 9), reused 0 (delta 0)
To https://git-lium.univ-lemans.fr/mshamsi/ensim_trade_center.git
c1fdf49..abaefe7 main -> main
2ca7186..b308ef1 main -> main
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
print("time_step",time_step)
out_str=input_trade[time_step+1]
with open('ENSIM_trade_ratio.csv', 'a') as f:
wr = csv.writer(f,delimiter=",")
wr.writerow(out_str)
rate1=input_trade[time_step][1]
rate2=input_trade[time_step][2]
rate3=input_trade[time_step][3]
rand_trade=[2*random.random()-1,2*random.random()-1,2*random.random()-1]
buyer_trade=[random.random(),random.random(),random.random()]
seller_trade=[-1*random.random(),-1*random.random(),-1*random.random()]
rand_values,rand_total = new_val(input_trade[time_step],rand_values,rand_trade)
buyer_values,buyer_total = new_val(input_trade[time_step],buyer_values,buyer_trade)
seller_values,seller_total = new_val(input_trade[time_step],seller_values,seller_trade)
trade_record=[time_step]
trade_record+=rand_values+[rand_total]
trade_record+=buyer_values+[buyer_total]
trade_record+=seller_values+[seller_total]
with open('ENSIM_trade_log_general.csv', 'a') as f:
wr = csv.writer(f,delimiter=",")
wr.writerow(trade_record)
dic_trad={
0:[1,1,-1],
1:[-1,-1,0],
2:[-1,-1,-1],
3:[-1,0,-1],
4:[0,0,0],
5:[1,-1,1]
}
for trdr in range(NUMBER_TRADERS):
p_trade=dic_trad[trdr]
p_values[trdr],p_total = new_val(input_trade[time_step],p_values[trdr],p_trade)
trade_record_p = [time_step]+p_values[trdr]+[p_total]
with open(f"ENSIM_trade_log_trader_{trdr}.csv", 'a') as f:
wr = csv.writer(f,delimiter=",")
wr.writerow(trade_record_p)
time_step+=1
print("time_step",time_step)
```
%% Output
time_step 21
time_step 22
%% Cell type:code id: tags:
``` python
!git add .
!git commit -m "init commit time step=22"
!git push
```
%% Output
[main eac6d67] init commit time step=22
[main ea2a5c6] init commit time step=22
8 files changed, 8 insertions(+)
Enumerating objects: 19, done.
Counting objects: 100% (19/19), done.
Delta compression using up to 8 threads
Compressing objects: 100% (10/10), done.
Writing objects: 100% (10/10), 1.22 KiB | 1.22 MiB/s, done.
Total 10 (delta 9), reused 0 (delta 0)
To https://git-lium.univ-lemans.fr/mshamsi/ensim_trade_center.git
abaefe7..eac6d67 main -> main
b308ef1..ea2a5c6 main -> main
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
print("time_step",time_step)
out_str=input_trade[time_step+1]
with open('ENSIM_trade_ratio.csv', 'a') as f:
wr = csv.writer(f,delimiter=",")
wr.writerow(out_str)
rate1=input_trade[time_step][1]
rate2=input_trade[time_step][2]
rate3=input_trade[time_step][3]
rand_trade=[2*random.random()-1,2*random.random()-1,2*random.random()-1]
buyer_trade=[random.random(),random.random(),random.random()]
seller_trade=[-1*random.random(),-1*random.random(),-1*random.random()]
rand_values,rand_total = new_val(input_trade[time_step],rand_values,rand_trade)
buyer_values,buyer_total = new_val(input_trade[time_step],buyer_values,buyer_trade)
seller_values,seller_total = new_val(input_trade[time_step],seller_values,seller_trade)
trade_record=[time_step]
trade_record+=rand_values+[rand_total]
trade_record+=buyer_values+[buyer_total]
trade_record+=seller_values+[seller_total]
with open('ENSIM_trade_log_general.csv', 'a') as f:
wr = csv.writer(f,delimiter=",")
wr.writerow(trade_record)
dic_trad={
0:[1,-1,-1],
1:[-1,-1,-1],
2:[-1,-1,1],
3:[-1,0,-1],
4:[0,0,0],
5:[-1,0,-1]
}
for trdr in range(NUMBER_TRADERS):
p_trade=dic_trad[trdr]
p_values[trdr],p_total = new_val(input_trade[time_step],p_values[trdr],p_trade)
trade_record_p = [time_step]+p_values[trdr]+[p_total]
with open(f"ENSIM_trade_log_trader_{trdr}.csv", 'a') as f:
wr = csv.writer(f,delimiter=",")
wr.writerow(trade_record_p)
time_step+=1
print("time_step",time_step)
```
%% Output
time_step 22
time_step 23
%% Cell type:code id: tags:
``` python
!git add .
!git commit -m "init commit time step=23"
!git push
```
%% Output
[main 8d5bb9d] init commit time step=23
9 files changed, 54 insertions(+), 33 deletions(-)
Enumerating objects: 21, done.
Counting objects: 100% (21/21), done.
[main bf7057f] init commit time step=23
8 files changed, 8 insertions(+)
Enumerating objects: 19, done.
Counting objects: 100% (19/19), done.
Delta compression using up to 8 threads
Compressing objects: 100% (11/11), done.
Writing objects: 100% (11/11), 1.69 KiB | 863.00 KiB/s, done.
Total 11 (delta 10), reused 0 (delta 0)
Compressing objects: 100% (10/10), done.
Writing objects: 100% (10/10), 1.21 KiB | 621.00 KiB/s, done.
Total 10 (delta 9), reused 0 (delta 0)
To https://git-lium.univ-lemans.fr/mshamsi/ensim_trade_center.git
eac6d67..8d5bb9d main -> main
ea2a5c6..bf7057f main -> main
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
print("time_step",time_step)
out_str=input_trade[time_step+1]
with open('ENSIM_trade_ratio.csv', 'a') as f:
wr = csv.writer(f,delimiter=",")
wr.writerow(out_str)
rate1=input_trade[time_step][1]
rate2=input_trade[time_step][2]
rate3=input_trade[time_step][3]
rand_trade=[2*random.random()-1,2*random.random()-1,2*random.random()-1]
buyer_trade=[random.random(),random.random(),random.random()]
seller_trade=[-1*random.random(),-1*random.random(),-1*random.random()]
rand_values,rand_total = new_val(input_trade[time_step],rand_values,rand_trade)
buyer_values,buyer_total = new_val(input_trade[time_step],buyer_values,buyer_trade)
seller_values,seller_total = new_val(input_trade[time_step],seller_values,seller_trade)
trade_record=[time_step]
trade_record+=rand_values+[rand_total]
trade_record+=buyer_values+[buyer_total]
trade_record+=seller_values+[seller_total]
with open('ENSIM_trade_log_general.csv', 'a') as f:
wr = csv.writer(f,delimiter=",")
wr.writerow(trade_record)
dic_trad={
0:[1,-1,1],
1:[0,0,1],
2:[-1,-1,1],
3:[1,-1,-1],
4:[0,0,0],
5:[1,0,1]
}
for trdr in range(NUMBER_TRADERS):
p_trade=dic_trad[trdr]
p_values[trdr],p_total = new_val(input_trade[time_step],p_values[trdr],p_trade)
trade_record_p = [time_step]+p_values[trdr]+[p_total]
with open(f"ENSIM_trade_log_trader_{trdr}.csv", 'a') as f:
wr = csv.writer(f,delimiter=",")
wr.writerow(trade_record_p)
time_step+=1
print("time_step",time_step)
```
%% Output
time_step 23
time_step 24
%% Cell type:code id: tags:
``` python
!git add .
!git commit -m "init commit time step=24"
!git push
```
%% Output
[main 47b753b] init commit time step=24
9 files changed, 44 insertions(+), 10 deletions(-)
Enumerating objects: 21, done.
Counting objects: 100% (21/21), done.
[main 5e87fad] init commit time step=24
8 files changed, 8 insertions(+)
Enumerating objects: 19, done.
Counting objects: 100% (19/19), done.
Delta compression using up to 8 threads
Compressing objects: 100% (11/11), done.
Writing objects: 100% (11/11), 1.49 KiB | 760.00 KiB/s, done.
Total 11 (delta 10), reused 0 (delta 0)
Compressing objects: 100% (10/10), done.
Writing objects: 100% (10/10), 1.21 KiB | 618.00 KiB/s, done.
Total 10 (delta 9), reused 0 (delta 0)
To https://git-lium.univ-lemans.fr/mshamsi/ensim_trade_center.git
8d5bb9d..47b753b main -> main
bf7057f..5e87fad main -> main
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
print("time_step",time_step)
out_str=input_trade[time_step+1]
with open('ENSIM_trade_ratio.csv', 'a') as f:
wr = csv.writer(f,delimiter=",")
wr.writerow(out_str)
rate1=input_trade[time_step][1]
rate2=input_trade[time_step][2]
rate3=input_trade[time_step][3]
rand_trade=[2*random.random()-1,2*random.random()-1,2*random.random()-1]
buyer_trade=[random.random(),random.random(),random.random()]
seller_trade=[-1*random.random(),-1*random.random(),-1*random.random()]
rand_values,rand_total = new_val(input_trade[time_step],rand_values,rand_trade)
buyer_values,buyer_total = new_val(input_trade[time_step],buyer_values,buyer_trade)
seller_values,seller_total = new_val(input_trade[time_step],seller_values,seller_trade)
trade_record=[time_step]
trade_record+=rand_values+[rand_total]
trade_record+=buyer_values+[buyer_total]
trade_record+=seller_values+[seller_total]
with open('ENSIM_trade_log_general.csv', 'a') as f:
wr = csv.writer(f,delimiter=",")
wr.writerow(trade_record)
dic_trad={
0:[0,1,-1],
1:[-1,-1,1],
2:[-1,-1,1],
3:[1,-1,1],
4:[0,0,0],
5:[1,-1,1]
}
for trdr in range(NUMBER_TRADERS):
p_trade=dic_trad[trdr]
p_values[trdr],p_total = new_val(input_trade[time_step],p_values[trdr],p_trade)
trade_record_p = [time_step]+p_values[trdr]+[p_total]
with open(f"ENSIM_trade_log_trader_{trdr}.csv", 'a') as f:
wr = csv.writer(f,delimiter=",")
wr.writerow(trade_record_p)
time_step+=1
print("time_step",time_step)
```
%% Output
time_step 24
time_step 25
%% Cell type:code id: tags:
``` python
!git add .
!git commit -m "init commit time step=25"
!git push
```
%% Output
[main d50db6a] init commit time step=25
9 files changed, 43 insertions(+), 9 deletions(-)
Enumerating objects: 21, done.
Counting objects: 100% (21/21), done.
[main 5dafac1] init commit time step=25
8 files changed, 8 insertions(+)
Enumerating objects: 19, done.
Counting objects: 100% (19/19), done.
Delta compression using up to 8 threads
Compressing objects: 100% (11/11), done.
Writing objects: 100% (11/11), 1.45 KiB | 494.00 KiB/s, done.
Total 11 (delta 10), reused 0 (delta 0)
Compressing objects: 100% (10/10), done.
Writing objects: 100% (10/10), 1.21 KiB | 621.00 KiB/s, done.
Total 10 (delta 9), reused 0 (delta 0)
To https://git-lium.univ-lemans.fr/mshamsi/ensim_trade_center.git
47b753b..d50db6a main -> main
5e87fad..5dafac1 main -> main
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
print("time_step",time_step)
out_str=input_trade[time_step+1]
with open('ENSIM_trade_ratio.csv', 'a') as f:
wr = csv.writer(f,delimiter=",")
wr.writerow(out_str)
rate1=input_trade[time_step][1]
rate2=input_trade[time_step][2]
rate3=input_trade[time_step][3]
rand_trade=[2*random.random()-1,2*random.random()-1,2*random.random()-1]
buyer_trade=[random.random(),random.random(),random.random()]
seller_trade=[-1*random.random(),-1*random.random(),-1*random.random()]
rand_values,rand_total = new_val(input_trade[time_step],rand_values,rand_trade)
buyer_values,buyer_total = new_val(input_trade[time_step],buyer_values,buyer_trade)
seller_values,seller_total = new_val(input_trade[time_step],seller_values,seller_trade)
trade_record=[time_step]
trade_record+=rand_values+[rand_total]
trade_record+=buyer_values+[buyer_total]
trade_record+=seller_values+[seller_total]
with open('ENSIM_trade_log_general.csv', 'a') as f:
wr = csv.writer(f,delimiter=",")
wr.writerow(trade_record)
dic_trad={
0:[0,1,-1],
1:[0,1,0],
2:[0,-1,1],
3:[0,-1,1],
4:[0,0,0],
5:[-1,-1,-1]
}
for trdr in range(NUMBER_TRADERS):
p_trade=dic_trad[trdr]
p_values[trdr],p_total = new_val(input_trade[time_step],p_values[trdr],p_trade)
trade_record_p = [time_step]+p_values[trdr]+[p_total]
with open(f"ENSIM_trade_log_trader_{trdr}.csv", 'a') as f:
wr = csv.writer(f,delimiter=",")
wr.writerow(trade_record_p)
time_step+=1
print("time_step",time_step)
```
%% Output
time_step 25
time_step 26
%% Cell type:code id: tags:
``` python
!git add .
!git commit -m "init commit time step=26"
!git push
```
%% Output
[main 1557021] init commit time step=26
9 files changed, 93 insertions(+), 16 deletions(-)
Enumerating objects: 21, done.
Counting objects: 100% (21/21), done.
[main be5ed4f] init commit time step=26
8 files changed, 8 insertions(+)
Enumerating objects: 19, done.
Counting objects: 100% (19/19), done.
Delta compression using up to 8 threads
Compressing objects: 100% (11/11), done.
Writing objects: 100% (11/11), 2.44 KiB | 625.00 KiB/s, done.
Total 11 (delta 10), reused 0 (delta 0)
Compressing objects: 100% (10/10), done.
Writing objects: 100% (10/10), 1.22 KiB | 1.22 MiB/s, done.
Total 10 (delta 9), reused 0 (delta 0)
To https://git-lium.univ-lemans.fr/mshamsi/ensim_trade_center.git
d50db6a..1557021 main -> main
5dafac1..be5ed4f main -> main
%% Cell type:code id: tags:
``` python