All Projects
06

Stochastic Processes & SDE Lab

Interactive simulation and numerical analysis of stochastic differential equations used in quantitative finance. Explore Brownian motion, geometric Brownian motion, mean-reverting processes, short-rate models, and stochastic volatility while comparing simulated distributions, theoretical moments, and numerical discretization error.

Stochastic CalculusSDEsMonte CarloEuler–MaruyamaBrownian MotionMean ReversionQuantitative FinancePythonLive Python / NumPy
Source Code

Running production Monte Carlo simulation…

Airo React → Railway FastAPI → NumPy vectorized simulation

CALCULATING

Model Equation

Ornstein–Uhlenbeck

dX_t = κ(θ − X_t) dt + σ dW_t

X₀ = initial value · κ = mean-reversion speed · θ = long-run mean · σ = volatility

Gaussian mean-reverting process useful for spreads, signals, factors, and simplified market dynamics.

Empirical Mean

Theoretical Mean

Model Diagnostic

Backend Runtime

Simulated Sample Paths

Production Python/NumPy Monte Carlo paths

Waiting for production simulation…

Terminal Distribution

Backend terminal sample with analytical density overlay where implemented

Waiting for terminal distribution…

Mean & Variance Through Time

Empirical backend moments vs analytical trajectories where available

Waiting for moment diagnostics…

Numerical Convergence

Independent client-side GBM validation using shared Brownian paths: Euler–Maruyama vs Milstein vs exact solution

finer Δt ←log₁₀(Δt)
Euler measured order ≈ 0.49Milstein measured order ≈ 0.98

Theoretical vs Empirical Moments

StatisticTheoreticalSimulationAbsolute Error
E[X_T]
Var[X_T]
Std Dev

Process Diagnostics

Model

Ornstein–Uhlenbeck

Monte Carlo Paths

10,000

Δt

Backend Runtime

Model Validation Summary

Connecting to the production stochastic engine…

METHODOLOGY & IMPLEMENTATION

Model Workflow

01

Stochastic Differential Equations

Each process is defined by a drift term and diffusion term driven by Brownian motion. The page exposes the economically important parameters and lets the user observe how they change path behavior and terminal distributions.

02

Production Monte Carlo Simulation

Scenario parameters are sent to a FastAPI endpoint on Railway. NumPy vectorizes thousands of simulated paths and returns sample paths, terminal observations, empirical mean and variance through time, model diagnostics, and request-side runtime.

03

Analytical Moment Validation

For Brownian motion, GBM, Ornstein–Uhlenbeck, Vasicek, and CIR, known analytical moments are compared with Monte Carlo estimates. The UI reports absolute moment errors rather than relying only on visual path inspection.

04

Mean Reversion & Rate Models

OU, Vasicek, and CIR expose mean-reversion speed and long-run level. The mean-reversion half-life ln(2)/κ is reported directly, while CIR also evaluates the Feller condition 2κθ ≥ σ².

05

Heston Stochastic Volatility

The Heston simulation evolves spot and variance jointly with correlated Gaussian shocks. Full-truncation style safeguards keep simulated variance non-negative in the numerical scheme.

06

Numerical Convergence

A separate reproducible GBM experiment compares Euler–Maruyama and Milstein terminal strong error against the exact GBM solution using shared Brownian paths. The measured log-log slopes provide a numerical convergence diagnostic.

Numerical Methods

Monte Carlo simulationNumPy vectorizationEuler–Maruyama discretizationMilstein discretizationExact GBM transition benchmarkAnalytical moment validationFull-truncation CIR / Heston safeguardsStrong convergence regression

Technologies

PythonNumPyFastAPIRailwayReactTypeScript

Plain-English Interpretation

The objective is not merely to draw stochastic paths. The lab connects continuous-time model equations to numerical simulation, checks Monte Carlo output against known theory where available, exposes discretization and model diagnostics, and measures the accuracy-versus-computation trade-off that appears in pricing and risk systems.