-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathanalysis.py
131 lines (123 loc) · 4.93 KB
/
analysis.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
import pandas as pd
import numpy as np
import os.path as path
class analysis():
def __init__(self, f):
self.cp = "('Crash Point',)"
self.cl = 'consec_loss'
self.cw = 'consec_wins'
self.file = f
self.loss = 0
self.wins = 0
self.df = pd.DataFrame()
self.groupedLoss = None
self.countLoss = None
self.countWins = None
self.optimal = pd.DataFrame()
self.arr = None
self.cl_arr = None
self.cw_arr = None
def main(self, curr, max_cash_out):
if (self.optimal.empty):
if path.exists('optimal.csv'):
self.optimal = pd.read_csv('optimal.csv')
self.df = self.prepData(max_cash_out)
self.arr = (np.arange(1.01, 2.01, 0.01))
self.cl_arr = (np.zeros(len(self.arr)))
self.cw_arr = (np.zeros(len(self.arr)))
else:
self.optimalBets(2)
self.arr = (np.arange(1.01, 2.01, 0.01))
self.cl_arr = (np.zeros(len(self.arr)))
self.cw_arr = (np.zeros(len(self.arr)))
i = 0
best = -9999
best_price = 0
while i < len(self.arr):
if self.arr[i] < curr:
self.cl_arr[i] += 1
self.cw_arr[i] = 0
else:
self.cl_arr[i] = 0
self.cw_arr[i] += 1
a = self.optimal[self.optimal['cash_out_loss'] == round(self.arr[i], 2)]
a = a[a['loss'] == self.cl_arr[i]]
if not a.empty:
m = max(a['loss_profit'])
if m > best:
best = m
best_price = round(self.arr[i], 2)
else:
b = self.optimal[self.optimal['win'] == self.wins]
b = b[b['win'] == self.cl_arr[i]]
if not b.empty:
m = max(b['win_profit'])
if m > best:
best = m
best_price = round(self.arr[i], 2)
i += 1
print("Best cash out point " + str(best_price) + " at profit of " + str(best))
print("_________________________________________________________")
#breakEven(cp)
def prepData(self, cash_out):
df = pd.read_csv(self.file)
a = df[self.cp].str.rstrip("x")
df[self.cp] = a.astype(float)
df[self.cl] = 0
df[self.cw] = 0
for i in range(len(df[self.cp])):
if df[self.cp][i] < cash_out:
self.loss += 1
self.wins = 0
else:
self.loss = 0
self.wins += 1
df[self.cl][i] = self.loss
df[self.cw][i] = self.wins
return df
def stats(self, column):
print("Median: "+ str(np.median(column)))
# Checks if there's a point where you make money regularly
def breakEven(column):
for i in range(1, 101):
bet = 10
diff = (bet * (i/100) * np.percentile(column, i)) - ((1 - (i/100)) * bet)
if (diff > bet):
print("Percentile " + str(i) + " is: " + str(np.percentile(column, i)))
def optimalBets(self, point=2):
cash = 1.01
index = 0
self.optimal = pd.DataFrame(index=range(4000))
self.optimal['cash_out_loss'] = 0.0
self.optimal['loss'] = 0
self.optimal['loss_profit'] = 0.0
self.optimal['cash_out_win'] = 0.0
self.optimal['win'] = 0
self.optimal['win_profit'] = 0.0
while cash <= point:
self.df = self.prepData(cash)
self.groupedLoss = self.df.groupby(self.cl)
self.countLoss = self.groupedLoss.agg("count")
self.countLoss = self.countLoss.drop(self.countLoss.columns[[1,2,3]], axis=1)
for i in range(1, len(self.countLoss)-1):
perc = self.countLoss["Unnamed: 0.1"][i+1] / self.countLoss["Unnamed: 0.1"][i]
self.optimal['cash_out_loss'][index] = round(cash, 2)
self.optimal['loss'][index] = i
self.optimal['loss_profit'][index] = round((1-perc)*(cash - 1) - (perc * 1), 2)
index += 1
cash += 0.01
index = 0
cash = 1.01
while cash <= point:
self.df = self.prepData(cash)
self.groupedWins = self.df.groupby(self.cw)
self.countWins= self.groupedWins.agg("count")
self.countWins = self.countWins.drop(self.countWins.columns[[1,2,3]], axis=1)
for i in range(1, len(self.countWins)-1):
perc = self.countWins["Unnamed: 0.1"][i+1] / self.countWins["Unnamed: 0.1"][i]
self.optimal['cash_out_win'][index] = round(cash, 2)
self.optimal['win'][index] = i
self.optimal['win_profit'][index] = round((perc)*(cash - 1) - ((1-perc) * 1), 2)
index += 1
cash += 0.01
self.optimal.to_csv("optimal.csv")