-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmontecarlo7.py
110 lines (92 loc) · 2.65 KB
/
montecarlo7.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
import random
import matplotlib
import matplotlib.pyplot as plt
import time
from matplotlib import style
style.use("ggplot")
def rollDice():
roll = random.randint(1,100)
if roll == 100:
return False
elif roll <= 50:
return False
elif 100 > roll >= 50:
return True
def doubler_bettor(funds,initial_wager,wager_count):
global broke_count
value = funds
wager = initial_wager
wX = []
vY = []
currentWager = 1
previousWager = 'win'
previousWagerAmount = initial_wager
while currentWager <= wager_count:
if previousWager == 'win':
if rollDice():
value += wager
wX.append(currentWager)
vY.append(value)
else:
value -= wager
previousWager = 'loss'
previousWagerAmount = wager
wX.append(currentWager)
vY.append(value)
if value < 0:
broke_count += 1
currentWager += 10000000000000000
elif previousWager == 'loss':
if rollDice():
wager = previousWagerAmount * 2
value += wager
wager = initial_wager
previousWager = 'win'
wX.append(currentWager)
vY.append(value)
else:
wager = previousWagerAmount * 2
value -= wager
previousWager = 'loss'
previousWagerAmount = wager
wX.append(currentWager)
vY.append(value)
if value < 0:
currentWager += 10000000000000000
broke_count += 1
currentWager += 1
plt.plot(wX,vY)
def simple_bettor(funds,initial_wager,wager_count):
####
global broke_count
value = funds
wager = initial_wager
wX = []
vY = []
currentWager = 1
while currentWager <= wager_count:
if rollDice():
value += wager
wX.append(currentWager)
vY.append(value)
else:
value -= wager
wX.append(currentWager)
vY.append(value)
###add me
if value < 0:
currentWager += 10000000000000000
broke_count += 1
currentWager += 1
plt.plot(wX,vY)
x = 0
broke_count = 0
while x < 1000:
simple_bettor(10000,100,1000)
x+=1
print(('death rate:',(broke_count/float(x)) * 100))
print(('survival rate:',100 - ((broke_count/float(x)) * 100)))
plt.axhline(0, color = 'r')
plt.ylabel('Account Value')
plt.xlabel('Wager Count')
plt.show()