-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaggregateResults.py
71 lines (56 loc) · 2.26 KB
/
aggregateResults.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import csv
import matplotlib.pyplot as plt
import numpy as np
def moving_average(arr, window_size):
window_size = 2
i = 0
moving_averages = []
while i < len(arr) - window_size + 1:
window = arr[i : i + window_size]
window_average = round(sum(window) / window_size, 2)
moving_averages.append(window_average)
i += 1
return moving_averages
k_values = [4] #, 5, 6, 7]
F_values = [round(i * 0.1, 2) for i in range(21)]
resdump = open('exp_results.csv', 'w')
for f in F_values:
resdump.write('F%2.2f,' % f)
resdump.write('\n')
n_eval_periods = 7 * 24 / 2
for kval in k_values:
for trial in [i for i in range(1,28)]:
base_y = []
new_y = []
time = []
with open('Trial_k%02d_F%2.2f_d07_%02d_strats.csv' % (kval, 1.8, trial), 'r') as file:
reader = csv.reader(file)
for row in reader:
base_pps = 0
new_pps = 0
for k, elem in enumerate(row):
if 'actvprof' in elem:
if k % 2 == 0:
new_pps += float(row[k+1])
else:
base_pps += float(row[k+1])
base_y = np.append(base_y, float(base_pps))
new_y = np.append(new_y, float(new_pps))
time = np.append(time, float(row[1]))
# print('PPS for all trades at time: ', row[1], 'is: ', seller_pps + buyer_pps)
# print('PPS for seller trades at time: ', row[1], 'is: ', seller_pps)
# print('PPS for buyer trades at time: ', row[1], 'is: ', buyer_pps)
# print('--------------------------------------------')
# for i in range(1, len(base_y)-1):
# if base_y[i] == 0:
# base_y[i] = (base_y[i-1] + base_y[i+1]) / 2
# if new_y[i] == 0:
# new_y[i] = (new_y[i-1] + new_y[i+1]) / 2
# base_y = moving_average(base_y, 2)
# new_y = moving_average(new_y, 2)
change = (np.sum(new_y)/15) / (np.sum(base_y)/15) - 1
# nt = len(base_y) - 2
# change = (new_y[nt]) / (base_y[nt]) - 1
resdump.write('%2.3f,' % (change))
resdump.write('\n')
resdump.close()