import numpy as np
import matplotlib.pyplot as plt
# Parameters for the simulation
np.random.seed(42) # for reproducible results
initial_wealth = 2000 # initial wealth
n_bets = 1000 # number of bets (e.g., 10 years of weekly bets)
b = 1 # odds (b to 1)
p = 0.7 # probability of winning each bet
fraction_kelly = 1 # Fraction of the Kelly Criterion to bet; 1 for full Kelly
# Calculate the Kelly fraction
kelly_fraction = (b * p - (1 - p)) / b
# Simulate the wealth over time using the Kelly Criterion
wealth = [initial_wealth]
for _ in range(n_bets):
bet_size = fraction_kelly * kelly_fraction * wealth[-1]
win = np.random.rand() < p # win or lose the bet
if win:
wealth.append(wealth[-1] + bet_size * b) # update wealth if win
else:
wealth.append(wealth[-1] - bet_size) # update wealth if lose
# Plotting the results
plt.figure(figsize=(12, 6))
plt.plot(wealth, label="Wealth Over Time with Kelly Criterion")
plt.title("Wealth Accumulation Over Time Using the Kelly Criterion")
plt.xlabel("Number of Bets")
plt.ylabel("Wealth")
plt.legend()
plt.grid(True)
plt.show()
Click Run or press shift + ENTER to run code