-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph_spread.py
65 lines (51 loc) · 1.74 KB
/
graph_spread.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
import glob
import pandas as pd
import matplotlib.pyplot as plt
from scipy import stats
import math
from matplotlib2tikz import save as tikz_save
#print(pd.concat([df1,df2],axis=1, join_axes=[df1.index], keys=['foo', 'bar']))
'''
surplus_df_av = surplus_df.groupby(0).mean()
time_sum_df = time_df.groupby(0).sum()
num_trades_sum_df = num_trades_df.groupby(0).sum()
av_time_df = time_sum_df / num_trades_sum_df
'''
def plot_data(df, dof, t, name):
#group = df.groupby(0)
#mean_df = group.mean()
std_df = group.std(ddof=1)
err_df = t * (std_df / math.sqrt(dof))
print(err_df)
mean_df.plot()
plt.show()
#tikz_save(name + ".tex")
#av_time_df.plot()
#plt.show()
if __name__ == "__main__":
dfs = {}
std = {}
result_files = glob.glob("results/tmp/*.csv")
for r in result_files:
results = pd.read_csv(r, header=None, index_col=0)
std[r] = results.groupby(0).std(ddof=1)
dfs[r] = results.groupby(0).mean()
dof = 999#spread_df.groupby(0).count().iloc[0].iloc[0]-1 # Degrees of freedom
t = stats.t.ppf(0.95, dof)
all_results = pd.concat(dfs,axis=1)
all_std = pd.concat(std, axis=1)
all_err = t * (all_std / math.sqrt(dof))
print(all_results)
print(all_std)
spread_df = all_results.xs(1, axis=1, level=1)
volatility_df = all_results.xs(2, axis=1, level=1)
spread_err_df = all_err.xs(1, axis=1, level=1)
volatility_err_df = all_err.xs(2, axis=1, level=1)
spread_df.plot(yerr=spread_err_df, capsize=1)
#plt.show()
tikz_save("spread.tex")
volatility_df.plot(yerr=volatility_err_df, capsize=1)
#plt.show()
tikz_save("volatility.tex")
#plot_data(spread_df, dof, t, "surplus")
#plot_data(volatility_df, dof, t, "num_trades")