-
Notifications
You must be signed in to change notification settings - Fork 1
/
4cw.py
167 lines (163 loc) · 4.2 KB
/
4cw.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import numpy as np
import matplotlib.pyplot as plt
import random
slista=[]
blista=[]
plista=[]
splista=[]
jlist=[0,1,2,3]
cwlist=[0.05, 0.075, 0.08, 0.1]
totalyr=3
for j in jlist:
slista.append([])
blista.append([])
plista.append([])
splista.append([])
s0=4.96*10**8
mtop=10*10**8
stop=10**9-s0
oneday=24*60*60
oneyear=365
t=[i for i in range(1,oneyear*2*totalyr)]
bprice=bprice0=45
bprice=bprice0
b0=bnum0=10**6
realmine=0
cw=cwlist[j]
plist=[]
blist=[]
slist=[]
splist=[]
b=b0*1.0
p0=b0/(cw*s0)
percentforbancor=0.08
dotpersec=2
s=1.0*s0
newprice=p=p0
sp=s0*p0
feerate=0.05
allmine=0
buymoney=sellmoney=0
staked=0
toBP=0.5
for i in t:
l=(i/2)/(oneyear*8+2)
stakeperday=4*10**5
if staked<s:
if s>stakeperday:
staked+=stakeperday
s-=stakeperday
elif staked>stakeperday/2:
staked-=stakeperday/2
s+=stakeperday/2
mineperhalfday=(1.0*dotpersec/(2**l))*oneday/2
if allmine+mineperhalfday>mtop:
realmine=mtop-allmine
else:
realmine=mineperhalfday
allmine+=realmine
s+=realmine
newprice=b/(cw*s)
b+=realmine*percentforbancor*0.9*newprice
newprice=b/(cw*s)
bprice=bprice0*random.uniform(0.88,1.15)
if i%30==0:
buymoney=bprice*1050000.0
sellmoney=bprice*50000.0
elif i%31==0:
buymoney=bprice*800000.0
sellmoney=buymoney*random.uniform(0.9,1.78)
elif newprice>1.05:
buymoney=bprice*110000.0
sellmoney=buymoney*random.uniform(0.91,2.1)
else:
buymoney=bprice*130000.0
sellmoney=buymoney*random.uniform(0.8,1.1)
buy=buymoney*1.0/bprice
if buy<=0:
blista[j].append(b/10**6)
slista[j].append(s/10**6)
plista[j].append(newprice)
splista[j].append((s0+stop+allmine)*newprice*bprice/10**9)
continue
if i%2==0:#buy
fee=buy*feerate
realbuybeforerate=buy
buyafterrate=buy-fee
token=-1*s*(1-(1+buyafterrate/b)**cw)
nowtop=s0+allmine+stop
if (s+token>nowtop):
realtoken=nowtop-s
realbuybeforerate=-1*b*(1-(1+realtoken/s)**(1/cw))
fee=realbuybeforerate*feerate
realbuy=realbuybeforerate-fee
realtoken=-1*s*(1-(1+realbuy/b)**cw)
else:
realtoken=token
realbuy=buyafterrate
s+=realtoken
b+=realbuybeforerate
#tokentobp=realtoken*feerate*toBP
#newprice=realbuybeforerate/realtoken
newprice=b/(cw*s)
blista[j].append(b/10**6)
slista[j].append(s/10**6)
plista[j].append(newprice)
splista[j].append((s0+stop+allmine)*newprice*bprice/10**9)
else:#sell
sell=sellmoney/bprice/newprice
sell*=1-feerate*toBP
#btcdownmaybe=random.uniform(0.33,3)
#if btcdownmaybe>0.8 and btcdownmaybe<1.0:
# sell=sell*3
# bprice*=0.5
if sell>s:
realsell=s
else:
realsell=sell
e=b*(1-(1-realsell/s)**(1/cw))
if b<e:
newprice=b/(cw*s)
blista[j].append(b/10**6)
slista[j].append(s/10**6)
plista[j].append(newprice*10**3)
splista[j].append((s0+stop+allmine)*newprice*bprice/10**9)
continue
s-=realsell
reale=e*(1-feerate*toBP)
b-=reale
#if (e>0):
#newprice=reale/realsell
newprice=b/(cw*s)
blista[j].append(b/10**6)
slista[j].append(s/10**6)
plista[j].append(newprice)
splista[j].append((s0+stop+allmine)*newprice*bprice/10**9)
colorlist=["red","green","yellow","grey"]
sp=plt.subplot(411)
for j in jlist:
sp.plot(t,np.array(slista[j]), color=colorlist[j])
bp=plt.subplot(412)
for j in jlist:
bp.plot(t,np.array(blista[j]), color=colorlist[j])
pp=plt.subplot(413)
for j in jlist:
pp.plot(t,np.array(plista[j]), color=colorlist[j])
spp=plt.subplot(414)
for j in jlist:
spp.plot(t,np.array(splista[j]), color=colorlist[j])
plt.legend()
pp.set_title("Price-1/2Day")
pp.set_ylabel("EOS")
p0=b0/(cwlist[0]*s0)
p3=b0/(cwlist[3]*s0)
ibo0=p0*1.8*10**8
ibo3=p3*1.8*10**8
sp.set_title("cw="+str(round(cwlist[0]*100,1))+"%-"+str(round(cwlist[3]*100,1))+"% rate="+str(round(100*percentforbancor,1))+"% fee="+str(round(100*feerate,1))+"%("+str(round(toBP*100,1))+"% to BP)\nIBO:"+str(round(ibo0/10**6,2))+"mEOS/Reserve:"+str(round(b0/ibo0*100,2))+"%-"+str(round(ibo3/10**6,2))+"mEOS/Reserve:"+str(round(b0/ibo3*100,2))+"%\nSupply-1/2Day")
sp.set_ylabel("mDOT")
bp.set_title("Reserve-1/2Day")
bp.set_ylabel("mEOS")
spp.set_title("Market Cap-1/2Day")
spp.set_ylabel("bRMB")
plt.tight_layout()
plt.show()