from pandas import Series, DataFrame
import numpy as np
import pandas as pd
from IPython.display import Image
# Betting table screenshot
Image("/Users/jasonchan/images/sicbo.png")
info = DataFrame({
"Small": [0.486, 0.0278, -0.0278],
"Big": [0.486, 0.0278, -0.0278]
}, index = ["P(Win)", "House Edge", "Return"])
#information on bets
info
Big | Small | |
---|---|---|
P(Win) | 0.4860 | 0.4860 |
House Edge | 0.0278 | 0.0278 |
Return | -0.0278 | -0.0278 |
# Minimum bet: 200
# 1 to 1 pay
# Rulea:
# - loss if any triple
# - 3 or 18 is considered loss because only achievable with triples
#simulation code
simnum = 500
all_data = DataFrame(index = np.arange(1,simnum + 1), columns = ["Sum", "Verdict"])
all_data.index.name = "Trials"
for i in range(1, simnum + 1):
a = np.random.randint(1,7,3)
if a[0]==a[1]==a[2]:
all_data.Sum[i] = None
all_data.Verdict[i] = "Lose"
else:
all_data.Sum[i] = a.sum()
if all_data.Sum[i] >= 11:
all_data.Verdict[i] = "Big"
else:
all_data.Verdict[i] = "Small"
all_data.head()
Sum | Verdict | |
---|---|---|
Trials | ||
1 | 9 | Small |
2 | 13 | Big |
3 | 5 | Small |
4 | 15 | Big |
5 | 10 | Small |
verdict = all_data["Verdict"]
verdict_data = Series.to_dict(verdict.value_counts())
verdict_data
{'Big': 234, 'Lose': 11, 'Small': 255}
import plotly
plotly.tools.set_credentials_file(username='JasonChanJinAn', api_key='g71g5chawk')
import plotly.plotly as py
import plotly.graph_objs as go
data = [go.Bar(
x=['Small', 'Big', 'Lose'],
y=[verdict_data["Small"], verdict_data["Big"], verdict_data["Lose"]]
)]
py.iplot(data, filename='basic-bar')
For sake of ease the simulation, we shall stick to one bet (either big or small throughout the simulation). Though we can always set a condition to switch to the other shall one appear x number of times consecutively.
P( 5 <= X <= 8) = 0.0467
If win, we keep on placing the minimum bet of 200
For example if lose after the first time, bet 400, if lose again, bet 800, etc. This will enable us to recover back our loss and make a profit when he finally hit a win.
The only drawback about this strategy is that we must have sufficient funds to sheild us through the consecitive losses. There is a close to 5% chance that we can lose 5 to 8 in a row. Hence we must have at least 12,600 to 51,000 to cover potential losses.
#calculating probability of more than 5 but less than 8 consecutive occurences
num1 = 0
for i in range(5,8):
num = 0.486**i
num1 = num1 + num
print num1
0.0466943057289
all_data["Cumulative"] = 0
all_data.head()
Sum | Verdict | Cumulative | |
---|---|---|---|
Trials | |||
1 | 9 | Small | 0 |
2 | 13 | Big | 0 |
3 | 5 | Small | 0 |
4 | 15 | Big | 0 |
5 | 10 | Small | 0 |
initial = 100000
bet = "Big"
minbet = 200
for i in range(1, simnum + 1):
if all_data.Verdict[i] == bet:
initial = initial + minbet
minbet = 200
else:
initial = initial - minbet
minbet = minbet*2
all_data.ix[[i], ["Cumulative"]] = initial
all_data.head()
Sum | Verdict | Cumulative | |
---|---|---|---|
Trials | |||
1 | 9 | Small | 99800 |
2 | 13 | Big | 100200 |
3 | 5 | Small | 100000 |
4 | 15 | Big | 100400 |
5 | 10 | Small | 100200 |
# Create a trace
trace = go.Scatter(
x = all_data.index,
y = all_data.Cumulative
)
data = [trace]
layout = go.Layout(
title='Simulated Winnings/Losses',
xaxis=dict(
title='Trials',
titlefont=dict(
family='Courier New, monospace',
size=18,
color='#7f7f7f'
)
),
yaxis=dict(
title='Capital (HKD)',
titlefont=dict(
family='Courier New, monospace',
size=18,
color='#7f7f7f'
)
)
)
fig = go.Figure(data=data, layout=layout)
# Plot and embed in ipython notebook!
py.iplot(fig, filename='basic-line')
# or plot with: plot_url = py.plot(data, filename='basic-line')