-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_result.py
89 lines (72 loc) · 2.98 KB
/
plot_result.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
def plot_computed_result():
data = pd.read_csv("computed_result.csv")
rebalancer = data[data['0'] == "Rebalancer"].reset_index()
balancer = data[data['0'] == "Balancer"].reset_index()
fig, ax = plt.subplots(1, 1, figsize=(16, 9), dpi=90)
plt.grid()
for name, df in [("Rebalancer", rebalancer), ("Balancer", balancer)]:
x = df['swap-mean']
y = -df['avg loss']
plt.plot(x, y, label=name)
plt.title("Price impact average loss", fontsize=16)
plt.gcf().autofmt_xdate()
plt.ylim(0, None)
plt.xlim(0, None)
plt.legend(fontsize=12, ncol=5)
plt.ylabel("average loss (USD)")
plt.xlabel("swap value (USD)")
fig.tight_layout()
def plot_cache_result():
data = pd.read_csv("cache_result.csv")
rebalancer = data[data['0'] == "Rebalancer"].reset_index()
balancer = data[data['0'] == "Balancer"].reset_index()
x = rebalancer['cache']
y = -rebalancer['avg loss']
model2 = np.poly1d(np.polyfit(x, y, 2))
X_ = np.linspace(x.min(), x.max(), 500)
Y_ = model2(X_)
fig, ax = plt.subplots(1, 1, figsize=(16, 9), dpi=90)
plt.grid()
plt.plot(x, y, "bo", label="Rebalancer results", linestyle='--', alpha=0.7)
plt.plot(X_, Y_, label="Rebalancer approximation", c='r')
plt.axhline(y=-balancer.iloc[0]["avg loss"],
label='Balancer', color="orange")
plt.ylim(0.95 * min(-rebalancer['avg loss']
), -balancer.iloc[0]["avg loss"] * 1.05)
ax.set_yticks([y.min(), y.max(), -balancer.iloc[0]["avg loss"]])
plt.legend(fontsize=12)
plt.xlim(min(rebalancer['cache']), max(rebalancer['cache']))
plt.ylabel("price impact average loss (USD)")
plt.xlabel("trading volume cache size in days")
fig.tight_layout()
def plot_interval_result():
data = pd.read_csv("interval_result.csv")
rebalancer = data[data['0'] == "Rebalancer"].reset_index()
balancer = data[data['0'] == "Balancer"].reset_index()
x = rebalancer['interval']
y = -rebalancer['avg loss']
model2 = np.poly1d(np.polyfit(x, y, 2))
X_ = np.linspace(x.min(), x.max(), 500)
Y_ = model2(X_)
fig, ax = plt.subplots(1, 1, figsize=(16, 9), dpi=90)
plt.grid()
plt.plot(x, y, "bo", label="Rebalancer results", linestyle='--', alpha=0.7)
plt.plot(X_, Y_, label="Rebalancer approximation", c='r')
plt.axhline(y=-balancer.iloc[0]["avg loss"],
label='Balancer', color="orange")
plt.ylim(0.95 * min(-rebalancer['avg loss']
), -balancer.iloc[0]["avg loss"] * 1.05)
plt.legend(fontsize=12)
plt.xlim(min(rebalancer['interval']), max(rebalancer['interval']))
plt.ylabel("price impact average loss (USD)")
plt.xlabel("update interval length in days")
ax.set_yticks([y.min(), y.max(), max(Y_), min(
Y_), -balancer.iloc[0]["avg loss"]])
fig.tight_layout()
plot_computed_result()
plot_cache_result()
plot_interval_result()
plt.show()