by nonameiguess · 5y ago · 0 comments
import numpy as np
import pandas as pd
n_subjects = 100
n_trials = 1000
start = 10.0
win = 1.5
loss = 0.6
prob = 0.5
results = np.ones((n_trials, n_subjects)) * start
for trial in range(1, n_trials):
wins = np.random.binomial(1, prob, n_subjects) == 1
results[trial, wins] = results[trial - 1, wins] * win
results[trial, ~wins] = results[trial - 1, ~wins] * loss
ax = pd.DataFrame(results).plot(legend=False, figsize=(18,10), logy=True, linewidth=0.5)
ax.plot(results.mean(axis=1), color='red', lw=2, linestyle='--')
The mean always trends to 0 and every single player eventually loses. There are never any winners at all past around 500 trials or so. Not sure how you're getting a different result as I have never used Julia and can't tell what your code is doing (except apparently something different).Looking at the Julia code, I think what he is doing wrong is making all wins worth $.50 and all losses worth $.40, but the bet computes a win or loss based on your current wealth, not your starting wealth. His formula would work if you were always betting $1 no matter what your bankroll was, but that isn't what the actual post stipulates.
Sounds like a good strategy whether in Vegas or Wall Street.
If you don't trust the Julia code, try running with the same parameters in Python.
My code is right up there and you can run it. You can even just run the OP's notebook that he provided but increase the number of trials. Change the "num_flips_per_sim" parameter he provides in cell 6 to anything over 500 and you will always get sum(count_lose_capital) == everyone.
n_subjects = 1000
n_trials = 100