-
Notifications
You must be signed in to change notification settings - Fork 0
/
comparisons.py
110 lines (96 loc) · 2.53 KB
/
comparisons.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
from impl.curveswap import CurveSwap_1
from scipy.misc import derivative
import matplotlib
import matplotlib.pyplot as plt
matplotlib.interactive(True)
A = 3645
gamma = 0.00007
p = CurveSwap_1(['A', 'B'], [2], A, gamma)
p.add_liquidity([1000, 500])
# make sure to miss 0
#dxs = range(-975, 977, 2)
#dxs = range(-501, 503, 2)
#dxs = range(-301, 303, 2)
dxs = range(-101, 103, 2)
def y_curveswap(x):
xp = p.balances.copy()
xp[0] = x
xp = p.calc_scaled_bals(xp)
yp = p.calc_y(p.A, p.gamma, xp, p.D, 1)
return yp / p.price_scale[1]
def y_stableswap(x):
xp = p.balances.copy()
xp[0] = x
xp = p.calc_scaled_bals(xp)
yp = p.calc_y_stableswap(p.A, xp, p.D, 1)
return yp / p.price_scale[1]
def reserves(show_ss=False):
x = []
y = []
y_uni = []
y_ss = []
b = p.balances
k = b[0] * b[1]
for dx in dxs:
new_x = b[0] + dx
x.append(new_x)
y.append(y_curveswap(new_x))
y_uni.append(k / new_x)
y_ss.append(y_stableswap(new_x))
if show_ss:
plt.plot(x, y, 'r', x, y_uni, 'b', x, y_ss, 'g')
else:
plt.plot(x, y, 'r', x, y_uni, 'b')
def price(show_ss=False):
x = []
price = []
price_uni = []
price_ss = []
b = p.balances
k = b[0] * b[1]
for dx in dxs:
new_x = b[0] + dx
x.append(new_x)
price.append(-1. * derivative(y_curveswap, new_x))
price_uni.append(k / new_x**2)
price_ss.append(-1. * derivative(y_stableswap, new_x))
plt.plot(x, price_uni, 'b', label="xy = k")
if show_ss:
plt.plot(x, price_ss, 'g', label="StableSwap")
plt.plot(x, price, 'r', label="CurveSwap")
plt.xlabel("Token 0 Reserves", fontsize=16)
plt.ylabel("Token 0 Price", fontsize=16)
plt.legend(loc='upper right')
plt.title("$A={}$ $\gamma={:.5f}$".format(A, gamma), fontsize=20)
def gamma_price():
x = []
price = []
price_g1 = []
price_g2 = []
b = p.balances
k = b[0] * b[1]
for dx in dxs:
new_x = b[0] + dx
x.append(new_x)
price.append(-1. * derivative(y_curveswap, new_x))
p.gamma = 10 * p.gamma
price_g1.append(-1. * derivative(y_curveswap, new_x))
p.gamma = 10 * p.gamma
price_g2.append(-1. * derivative(y_curveswap, new_x))
p.gamma = gamma
plt.plot(x, price, 'r', x, price_g1, 'b', x, price_g2, 'g')
def A_price():
x = []
price = []
price_g1 = []
price_g2 = []
b = p.balances
k = b[0] * b[1]
for dx in dxs:
new_x = b[0] + dx
x.append(new_x)
price.append(-1. * derivative(y_curveswap, new_x))
p.A = 10 * p.A
price_g1.append(-1. * derivative(y_curveswap, new_x))
p.A = A
plt.plot(x, price, 'r', x, price_g1, 'b')