Stochastic Processes Python Monte Carlo

The Martingale Illusion

An analysis of Tail Risk: Why "foolproof" doubling strategies fail in constrained systems.

Extreme Volatility

Figure 1: 10 sample episodes showing extreme volatility.

Ideal vs. Constrained

Scenario A: Infinite

100% Convergence
Figure 2: Infinite Bankroll Mean

Theoretical Success: With infinite capital, EV converges to +$80. However, the risk (std dev) diverges, requiring infinite variance to secure the win.

Scenario B: Limited

-$35.50 Exp. Value
Figure 4: Limited Bankroll Mean (Failure)

Systemic Failure: A "hard stop" of $256 (8 consecutive losses) activates Gambler's Ruin. The cost of recovery quickly exceeds the system's error budget.

// Analytical Insight

The "Median Trap" & Fat Tail Risks

The Misleading Metric (P50) If we look at the Median Winnings (Figure 5), the line stabilizes at +$80. This suggests a "typical" user wins. In product analytics, relying on P50 would mask the critical failure mode.
The Bimodal Reality The distribution is not normal; it is bimodal.
• Mode 1 (65.6%): Small Win (+$80)
• Mode 2 (34.4%): Catastrophic Loss (-$256)
Product Implication For AI systems or financial models, this demonstrates why optimizing for "Precision" (Win Rate) without considering "Safety" (Max Drawdown) is fatal. A strategy with a negative Expected Value (-$35.50) is unsustainable, regardless of how often it "typically" succeeds.
Median Winnings Graph

Figure 5: The deceptive Median (P50)

Technical Implementation

To model 1,000 independent episodes effectively, I utilized NumPy to construct a state_matrix (1000, 1001). Instead of running nested loops (O(N²)), the simulation calculates wager outcomes across the entire episode axis simultaneously.