Skip to content

Commit 2dddcc7

Browse files
committed
added more strats
1 parent d35e033 commit 2dddcc7

File tree

3 files changed

+197
-49
lines changed

3 files changed

+197
-49
lines changed

checker.py

Lines changed: 72 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,96 @@
1-
from strats.custom_strats import MartingaleStrat, AntiMartingaleStrat
21

2+
from strats.custom_strats import MartingaleStrat, AntiMartingaleStrat, DAlembertStrat, ParoliStrat, one_3_2_6Strat
33
from stratchecker.stratchecker import Strat_checker
44

55
import logging
66

7-
logging.basicConfig(format='%(message)s', level=logging.INFO, datefmt='%m/%d/%Y %I:%M:%S')
7+
logging.basicConfig(format='%(message)s', level=logging.ERROR, datefmt='%m/%d/%Y %I:%M:%S')
88

99

1010
#set logger format
1111

1212

1313

14+
start_balance=25
15+
base_bet=0.1
16+
max_bet=1
17+
multiplier=2
18+
max_bets=1000
19+
runs_per_strat=5
20+
21+
22+
23+
def read_results(results_filename):
24+
#read file
25+
with open(results_filename) as f:
26+
file_content = f.readlines()
27+
28+
#remove timestamp and newline
29+
results = [float(x.split(",")[1].replace("\n","")) for x in file_content]
30+
#invert list
31+
results.reverse()
32+
33+
return results
34+
35+
36+
1437
def main():
1538
slices = []
39+
strats = []
1640

17-
strat = MartingaleStrat("Martingale",
18-
start_balance=25,
19-
base_bet=0.1,
20-
max_bet=1,
21-
multiplier=2,
22-
max_bets=1000 )
23-
print(strat.describe())
41+
strats.append(MartingaleStrat("Martingale",
42+
start_balance=start_balance,
43+
base_bet=base_bet,
44+
max_bet=max_bet,
45+
multiplier=multiplier,
46+
max_bets=max_bets ))
2447

2548

26-
strat2 = AntiMartingaleStrat("AntiMartingale",
27-
start_balance=25,
28-
base_bet=0.1,
29-
max_bet=1,
30-
multiplier=2,
31-
max_bets=1000 )
49+
strats.append(AntiMartingaleStrat("AntiMartingale",
50+
start_balance=start_balance,
51+
base_bet=base_bet,
52+
max_bet=max_bet,
53+
multiplier=multiplier,
54+
max_bets=max_bets ))
3255

33-
34-
35-
strat_checker = Strat_checker(strat, "results.txt")
36-
strat_checker.read_results()
37-
strat_checker.run(count=5,random_slice=True)
38-
slices = strat_checker.get_slices()
56+
strats.append(DAlembertStrat("DAlembert",
57+
start_balance=start_balance,
58+
base_bet=base_bet,
59+
max_bet=max_bet,
60+
multiplier=multiplier,
61+
max_bets=max_bets ))
3962

40-
strat_checker2 = Strat_checker(strat2, "results.txt")
41-
strat_checker2.read_results()
42-
strat_checker2.set_slices(slices)
43-
strat_checker2.run(count=5,random_slice=False)
44-
63+
strats.append(ParoliStrat("Paroli",
64+
start_balance=start_balance,
65+
base_bet=base_bet,
66+
max_bet=max_bet,
67+
multiplier=multiplier,
68+
max_bets=max_bets ))
69+
strats.append(one_3_2_6Strat("one_3_2_6",
70+
start_balance=start_balance,
71+
base_bet=base_bet,
72+
max_bet=max_bet,
73+
multiplier=multiplier,
74+
max_bets=max_bets ))
75+
4576

46-
strat_checker.report()
77+
results = read_results("results.txt")
78+
slices = Strat_checker.slice_results(count=5,max_bets=max_bets,results_length=len(results))
4779

48-
strat_checker2.report()
80+
strat_runners = []
81+
for strat in strats:
82+
strat_runners.append(Strat_checker(strat, results, slices=slices))
4983

50-
print(strat.balance)
84+
85+
for strat_runner in strat_runners:
86+
strat_runner.run(count=runs_per_strat)
87+
88+
89+
90+
for strat_runner in strat_runners:
91+
strat_runner.report()
92+
93+
5194

5295

5396

stratchecker/stratchecker.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,37 @@
44
import logging
55

66
import random
7+
from rich import print
78

89
logger = logging.getLogger(__name__)
910

1011

1112

1213
class Strat_checker():
13-
def __init__(self, strat:Strat, results_filename:str, slices=[]) -> None:
14+
def __init__(self, strat:Strat, results, slices=[]) -> None:
1415
self.strat = strat
15-
self.results_filename = results_filename
1616
self.slices = slices
17+
self.strat_reports = []
18+
self.results = results
1719

18-
19-
def read_results(self):
20-
#read file
21-
with open(self.results_filename) as f:
22-
file_content = f.readlines()
23-
24-
#remove timestamp and newline
25-
self.results = [float(x.split(",")[1].replace("\n","")) for x in file_content]
26-
#invert list
27-
self.results.reverse()
2820

21+
2922

30-
def slice_results(self,max_length,count):
23+
@staticmethod
24+
def slice_results(count,max_bets,results_length):
3125

3226
'''
3327
slice results in a random place making sure that
3428
the max_length of the slice is not exceeded
35-
return the slice
29+
return the slice indexes
3630
'''
3731
slices = []
3832
for i in range(count):
3933
#get random start index
40-
start_index = random.randint(0,len(self.results)-max_length)
34+
start_index = random.randint(0,results_length-max_bets)
4135

4236
#get random end index
43-
end_index = start_index+max_length
37+
end_index = start_index+max_bets
4438

4539
slices.append((start_index,end_index))
4640

@@ -72,14 +66,15 @@ def run(self,count:int=1,random_slice:bool=True):
7266
count must be greater than 1 if random_slice is True
7367
'''
7468

69+
70+
7571
if random_slice is True and count == 1:
7672
logging.warning("random_slice is True and count is 1, setting random_slice to False")
7773
random_slice = False
7874

7975
if self.strat.max_bets > len(self.results):
8076
logging.warning(f"max bets {self.strat.max_bets} is greater than the number of results {len(self.results)}, setting max bets to {len(self.results)}")
8177
self.strat.max_bets = len(self.results)
82-
self.strat_reports = []
8378

8479

8580
if len(self.slices) == 0:
@@ -89,9 +84,7 @@ def run(self,count:int=1,random_slice:bool=True):
8984

9085
for i in range(count):
9186

92-
9387
self.strat.reset()
94-
9588
try:
9689
for result in self.results[self.slices[i][0]:self.slices[i][1]]:
9790
self.strat.gamble()

strats/custom_strats.py

Lines changed: 113 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,116 @@ def on_lose(self):
4545
super().on_lose()
4646

4747
self.bet = self.base_bet
48-
48+
49+
50+
class DAlembertStrat(Strat):
51+
'''
52+
D Alembert System | Increase your bet amount by 1 unit whenever you lose and decrease by 1 unit if you win.
53+
1 unit = base_bet
54+
'''
55+
def __init__(self,description,start_balance, base_bet, max_bet, multiplier ,max_bets):
56+
super().__init__(description,start_balance, base_bet, max_bet, multiplier ,max_bets)
57+
58+
59+
def on_win(self):
60+
super().on_win()
61+
if self.bet > self.base_bet:
62+
self.bet = self.bet - self.base_bet
63+
else:
64+
self.bet = self.base_bet
65+
66+
def on_lose(self):
67+
super().on_lose()
68+
69+
if self.bet < self.max_bet:
70+
self.bet = self.bet + self.base_bet
71+
else:
72+
self.bet = self.max_bet
73+
74+
class ParoliStrat(Strat):
75+
'''
76+
Paroli System | Increase your bet amount by 1 unit whenever you win. If you win three times in a row, go back to the start and bet 1 unit again. 1 unit = base_bet
77+
'''
78+
def __init__(self,description,start_balance, base_bet, max_bet, multiplier ,max_bets):
79+
super().__init__(description,start_balance, base_bet, max_bet, multiplier ,max_bets)
80+
81+
82+
def on_win(self):
83+
super().on_win()
84+
85+
if self.win_streak == 3:
86+
self.bet = self.base_bet
87+
else:
88+
self.bet = self.bet + self.base_bet
89+
90+
def on_lose(self):
91+
super().on_lose()
92+
93+
self.bet = self.base_bet
94+
95+
class OscarGrindStrat(Strat):
96+
'''
97+
Oscar Grind | Increase your bet amount by 1 unit after each win. Keep it the same when you lose. When you end up with at least 1 unit of profit, go back to the start and bet 1 unit again.
98+
1 unit = base_bet
99+
100+
needs work
101+
'''
102+
103+
def __init__(self,description,start_balance, base_bet, max_bet, multiplier ,max_bets):
104+
super().__init__(description,start_balance, base_bet, max_bet, multiplier ,max_bets)
105+
106+
107+
def on_win(self):
108+
super().on_win()
109+
110+
self.bet = self.bet + self.base_bet
111+
112+
def on_lose(self):
113+
super().on_lose()
114+
115+
self.bet = self.base_bet
116+
117+
class FibonacciStrat(Strat):
118+
'''
119+
Fibonacci | Increase your bet amount by the sum of the previous two bets after each loss. When you win, go back two numbers in the sequence and bet that amount.
120+
1 unit = base_bet
121+
122+
needs work
123+
124+
'''
125+
126+
def __init__(self,description,start_balance, base_bet, max_bet, multiplier ,max_bets):
127+
super().__init__(description,start_balance, base_bet, max_bet, multiplier ,max_bets)
128+
129+
130+
def on_win(self):
131+
super().on_win()
132+
133+
self.bet = self.bet + self.base_bet
134+
135+
def on_lose(self):
136+
super().on_lose()
137+
138+
self.bet = self.base_bet
139+
140+
141+
class one_3_2_6Strat(Strat):
142+
'''
143+
1-3-2-6 System | Start by betting 1 unit, followed by 3 units, 2 units, and 6 units, before starting again, but only move up the sequence when you win.
144+
1 unit = base_bet
145+
146+
not sure if this is implemented correctly
147+
'''
148+
149+
def __init__(self,description,start_balance, base_bet, max_bet, multiplier ,max_bets):
150+
super().__init__(description,start_balance, base_bet, max_bet, multiplier ,max_bets)
151+
self.bet_sequence = [1,3,2,6]
152+
153+
def on_win(self):
154+
super().on_win()
155+
self.bet = self.bet_sequence[self.win_streak % len(self.bet_sequence)] * self.base_bet
156+
157+
def on_lose(self):
158+
super().on_lose()
159+
160+
self.bet = self.base_bet

0 commit comments

Comments
 (0)