ICAM Toulouse · NID · Python

Monte CarloA talk and live coding session on probabilistic simulation: from estimating π with random dots to simulating a stock portfolio the way banks do.

Format
20-slide talk, two live demos in VS Code, a quiz to finish
Stack
Python · NumPy · Matplotlib
Case study
Portfolio simulation, as used by investment banks and Finary
Takeaway
Past performance does not define future performance
Fan chart of thousands of simulated portfolio paths
Thousands of simulated paths · percentile bands · live in the terminal
01 · The ideaRandom sampling for deterministic answers

Throw enough random darts and π falls out.

Scatter points uniformly in a square, count how many land inside the quarter circle, multiply the ratio by four. The more points, the closer to π. Same trick, bigger question: replace the square with a market model and the ratio with a distribution of outcomes.

# live demo 1 · π from random points
import numpy as np
N = 1_000_000
x, y = np.random.rand(2, N)          # uniform in [0, 1)²
inside = (x**2 + y**2 <= 1).sum()
pi = 4 * inside / N                 # → 3.1416…, error ~ 1/√N
Random points inside and outside a circle
Live demo 1 · estimating π
02 · Three kinds of randomThe model is the assumption
Uniform
random()

Every value equally likely. Fine for darts, wrong for markets.

Normal
mean, deviation

Bell curve. Most daily moves are small; extremes are rare. The standard model, and its blind spot.

Fat tail
heavy extremes

Rare events happen far more than the bell predicts. Flash crashes live here.

Normal distribution
Normal distribution
Fat-tail distribution
Fat-tail distribution
03 · Case studySimulating a portfolio

Feed a portfolio’s historical mean and volatility into thousands of random walks and read the result as a range, not a number: median outcome, best and worst percentiles, probability of loss. This is what the risk desks of the big banks run every night.

# live demo 2 · portfolio paths
mu, sigma = returns.mean(), returns.std()   # daily, from history
days, paths = 252, 10_000
shocks = np.random.normal(mu, sigma, (days, paths))
# swap for a Student-t to get fat tails:
# shocks = mu + sigma * np.random.standard_t(3, size=(days, paths)) / np.sqrt(3)
value = start * np.cumprod(1 + shocks, axis=0)
p5, p50, p95 = np.percentile(value[-1], [5, 50, 95])
loss_prob = (value[-1] < start).mean()
  • Drift and volatility come from history; the randomness is the model’s honesty about what it doesn’t know.
  • 10,000 paths, 252 trading days: enough that the percentiles stop moving between runs.
  • The distribution is a switch. Normal to Student-t changes the 5th percentile far more than the median. That switch is the whole talk.
Portfolio simulation, bearish scenario
Live demo 2 · bearish drift
Portfolio simulation, bullish scenario
Live demo 2 · bullish drift
1960 – 80
First computers

Automation begins on the trading floor.

1986
End of open outcry

Paris closes the pit.

1999 → 2010
HFT, then the Flash Crash

High-frequency trading, big data, and a market that fell 9 % in minutes.

2020s
Generative AI

Quant tools reach everyone.

04 · Quiz timeGuess the direction · five stocks · five months
Stock5 months agoTodayMove
Google$203.54$174.68−14.2 %
Nvidia$120.06$154.31+28.5 %
Amazon$237.68$211.99−10.8 %
Tesla$404.60$327.55−19.0 %
Apple$235.43$201.56−14.4 %

Four of five household names fell. The room guessed mostly up. That was the point of the disclaimer slide.