-
Notifications
You must be signed in to change notification settings - Fork 9
/
lever_lp.py
61 lines (54 loc) · 2.37 KB
/
lever_lp.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
import matplotlib.pyplot as plt
import numpy as np
from option_pricing import vanilla_option
if __name__ == '__main__':
plt.figure(figsize=(16, 8))
# plt.rcParams['font.sans-serif'] = ['SimHei']
# plt.rcParams['axes.unicode_minus'] = False
# # plt.title("杠杆挖矿收益曲线", fontsize=16)
# # plt.xlabel("现价相对开仓价", fontsize=14)
# plt.title("Profit and loss of leveraged yield farming", fontsize=16)
plt.title("Impermanent loss", fontsize=16)
plt.xlabel("Price relative to entry", fontsize=14)
plt.ylabel("Relative PnL in stablecoin", fontsize=14)
x = np.arange(0, 4, 0.01)
lp = np.sqrt(x)
hold = (1 + x) / 2
plt.plot(x, lp, label='LP')
plt.plot(x, hold, label='Hodl')
plt.plot(x, hold - lp, label='Impermanent loss')
plt.gca().yaxis.set_major_formatter('{x:.0%}')
plt.gca().xaxis.set_major_formatter('{x:.0%}')
plt.legend(loc="best", prop={'size': 14})
plt.grid(linestyle='--')
plt.show()
exit()
# plt.ylabel("以法币计相对盈亏", fontsize=14)
# plt.ylabel("Relative PnL in stablecoin", fontsize=14)
# x = np.arange(0, 2, 0.01)
# for L in range(1, 4):
# lp = L * np.sqrt(x) - L * x + x - 1
# plt.plot(x, lp, label='{}倍杠杆借币'.format(L))
# plt.plot(x, lp, label='Borrow crypto at {} leverage'.format(L))
# # plt.ylabel("以法币计相对盈亏", fontsize=14)
# plt.ylabel("Relative PnL in stablecoin", fontsize=14)
# L = 2
# x = np.arange(0, 4, 0.01)
# lp = L * (np.sqrt(x) - 1)
# # plt.plot(x, lp, label='{}倍杠杆借U'.format(L))
# plt.plot(x, lp, label='Borrow stablecoin at {} leverage'.format(L))
# plt.ylabel("以法币计相对盈亏", fontsize=14)
# plt.ylabel("Relative PnL in stablecoin", fontsize=14)
# L = 3
# LTVi = (L - 1) / L
# LTVf = 5. / 6
# liquidation = (LTVf / LTVi) ** 2
# x = np.arange(1. / liquidation, liquidation + 0.01, 0.01)
# a = L / 2 / (L - 1)
# lp = a * (L * np.sqrt(x) - L * x + x - 1) + (1 - a) * L * (np.sqrt(x) - 1)
# # plt.plot(x, lp, label='{}倍杠杆中性策略'.format(L))
# plt.plot(x, lp, label='Pseudo delta neutral at leverage {}'.format(L))
plt.gca().yaxis.set_major_formatter('{x:.0%}')
plt.legend(loc="best", prop={'size': 14})
plt.grid(linestyle='--')
plt.show()