Wave 52: Gambler's Ruin, Stochastic Processes & K-Fold Symmetry

Three additions spanning probability theory and generative art: an exact analytical Gambler's Ruin solver with Monte Carlo path visualisation and Kelly criterion, a four-mode stochastic differential equations explorer covering Brownian motion, GBM, Ornstein-Uhlenbeck and correlated processes, and an interactive K-fold rotational symmetry drawing tool with kaleidoscope and dihedral modes.

Wave 52 at a glance

3
new simulations
6
HTML files
532
total simulations
1
blog post
๐ŸŽฒ

Gambler's Ruin

Exact ruin probability formula, Monte Carlo path browser, Kelly criterion and expected duration.

Open simulation โ†’
๐Ÿ“ˆ

Stochastic Processes

BM, Geometric BM (Black-Scholes), Ornstein-Uhlenbeck, and correlated Brownian motion with confidence bands.

Open simulation โ†’
๐Ÿ”ฏ

K-Fold Symmetry

Draw a single stroke and watch it reflected into 2โ€“16 symmetric sectors. Dihedral mirror mode, palette presets, Save PNG.

Open simulation โ†’

๐ŸŽฒ Gambler's Ruin

The Gambler's Ruin problem asks: a player starts with wealth W and bets one unit at a time, winning with probability p and losing with probability q = 1 โˆ’ p. Play stops when wealth reaches the target T (win) or zero (ruin). What is the probability of eventual ruin?

Analytical solution

The exact formula depends on whether the game is fair:

For a slightly unfavourable game (e.g. casino roulette with p โ‰ˆ 0.4737), starting at W = 50 with target T = 100 already gives a ruin probability exceeding 98%. The asymmetry is enormous even for small deviations from fair.

Kelly criterion

The Kelly criterion gives the bet fraction that maximises long-run wealth growth. For simple even-money bets:

f* = 2p โˆ’ 1 โ€” optimal fraction of current bankroll to bet each round. For p = 0.55 this is f* = 0.10 (10%). Over- or under-betting both reduce long-run growth.

Monte Carlo

The simulation generates up to 200 independent random walk paths simultaneously. Paths are coloured red when they hit ruin (wealth = 0), green when they reach the target, and violet for paths still in progress. The Monte Carlo estimate of P(ruin) converges rapidly to the analytical formula.

๐Ÿ“ˆ Stochastic Processes & Wiener Process

A Wiener process (standard Brownian motion) is a continuous-time random process W(t) satisfying: W(0) = 0; increments W(t) โˆ’ W(s) are Gaussian with mean 0 and variance t โˆ’ s; increments over non-overlapping intervals are independent. It is the scaling limit of a simple random walk and the building block of stochastic calculus.

Four process modes

1. Standard Brownian Motion (Wiener process)

SDE: dX = ฮผ dt + ฯƒ dW โ€” additive drift plus Gaussian noise. Variance grows linearly: Var[X(t)] = ฯƒยฒt. The shaded confidence band shows the ยฑ1ฯƒ envelope around the theoretical mean path.

2. Geometric Brownian Motion (GBM โ€” Black-Scholes stock model)

SDE: dS = ฮผS dt + ฯƒS dW. The solution is S(t) = Sโ‚€ exp((ฮผ โˆ’ ฯƒยฒ/2)t + ฯƒW(t)). Log-returns are normally distributed; prices are log-normal and always positive. This is the model underlying the Black-Scholes option pricing formula.

3. Ornstein-Uhlenbeck process (mean reversion)

SDE: dX = ฮบ(ฮธ โˆ’ X) dt + ฯƒ dW. The parameter ฮบ controls how quickly the process reverts to the long-run mean ฮธ. Used for modelling interest rates (Vasicek model), commodity prices, and inter-spike intervals in neuroscience. Variance converges to ฯƒยฒ/(2ฮบ) as t โ†’ โˆž.

4. Correlated Brownian Motion pair

Two arithmetic BM processes sharing correlated noise: dWโ‚‚ = ฯ dWโ‚ + โˆš(1โˆ’ฯยฒ) dZ, where Z โŠฅ Wโ‚. Blue paths are Xโ‚ and pink paths are Xโ‚‚. The correlation ฯ โˆˆ (โˆ’1, 1) controls how tightly coupled they move โ€” relevant for modelling correlated assets in portfolio theory.

The white path is the sample mean across all simulated paths. For all modes the mean converges to the theoretical expectation as the path count increases.

๐Ÿ”ฏ K-Fold Rotational Symmetry

Rotational symmetry of order K means an object looks identical after a rotation of 360ยฐ/K. The symmetry group is the cyclic group Cโ‚–. When reflections are also included (mirror mode) the group becomes the dihedral group Dโ‚–, doubling the number of copies.

Drawing algorithm

Every stroke segment from (xโ‚, yโ‚) to (xโ‚‚, yโ‚‚) is first translated to the canvas centre, then drawn K times, each copy rotated by k ร— 2ฯ€/K from the previous. In dihedral mode a mirror copy (y โ†’ โˆ’y before rotation) is added for each sector, producing 2K copies total.

Because strokes are accumulated on a persistent offscreen canvas, details build up progressively to create mandala and kaleidoscope patterns. The guide lines (faint sector dividers) update in real time as K is changed.

Wallpaper groups

The preset buttons correspond to the four wallpaper groups achievable with pure rotational symmetry on a lattice:

The finished artwork can be saved as a lossless PNG using the Save PNG button, which triggers a direct canvas โ†’ data-URL download.

What's next

Wave 53 candidates from the queue include fluid simulations (laminar-turbulent transition, boundary layer), fish-school 3D flocking, and Islamic geometric pattern generation. Biology and physics queues are also well stocked. Suggestions welcome via the contact page.

โ† Devlog #71 โ€” Wave 51 All posts