Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Neural Differential Equations

Personal project exploring continuous-depth models for time series, from the maths up to working PyTorch code, with a physics-flavoured dataset and a route to deep hedging. I'm a third-year CS and Data Analytics undergrad at IIT Patna with a background in differential equations and stochastic processes (Langevin, Fokker-Planck, Brownian motion), so I'm trying to connect that physical intuition to the neural DE literature.

What I'm building

Neural ODEs, Neural CDEs, and Neural SDEs — understanding each one properly before moving to the next — and then applying the same differentiable stochastic-simulation machinery to deep hedging. The final deliverable is a report with the maths, experiments, comparison tables, and an honest take on when continuous-depth models actually help.

Phases

  1. Theory — Neural ODEs, adjoint method, Latent ODEs, Neural CDEs, Neural SDEs, Ito calculus, uncertainty quantification.
  2. Pendulum sanity check — verify a Neural ODE recovers the true vector field on known dynamics before trusting it on real data.
  3. Real data — irregularly sampled physics-flavoured data via Neural CDEs.
  4. Neural SDE — principled uncertainty; check whether predicted distributions are calibrated.
  5. Honest benchmarks — compare against GRU, LSTM, GRU-D, Transformer on the same data and compute budget.
  6. Report.

The financial angle is deep hedging: it reuses the stochastic simulation engine, which is more interesting than trying to predict prices directly.

Repo layout

quant/
  gbm_onramp.py        # GBM as an SDE; Euler-Maruyama vs exact; convergence
  option_hedging.py    # European call; Black-Scholes price; delta hedge; cost tradeoff
  deep_hedge.py        # Neural hedger; shared rollout; benchmark vs BS delta at tc=1%
  deep_hedge_sweep.py  # Sweep tc in [0%, 0.2%, 0.5%, 1%, 2%, 5%]; deadzone scatter

figures/               # Output figures (PNG)
models/                # Trained HedgeNet weights per tc level
notes/
  lab_log.md           # Running notes on what each experiment showed

requirements.txt

Setup

python -m venv .venv && source .venv/bin/activate
pip install torch          # match your CUDA/MPS version first
pip install -r requirements.txt

Running

python quant/gbm_onramp.py        # sanity checks + figures, ~5s
python quant/option_hedging.py    # price + hedge checks + figures, ~30s
python quant/deep_hedge.py        # frictionless gate + tc=1% benchmark, ~10 min CPU
python quant/deep_hedge_sweep.py  # full tc sweep + deadzone plot, ~10 min MPS

Results so far (quant rail)

Frictionless gate

At tc=0, the neural hedger's P&L std matches BS-delta P&L std within Monte Carlo noise (ratio 1.007–1.011 across runs). This is the validation check I run before trusting anything with costs turned on.

Single-point benchmark (tc=1%, 52 weekly steps, 20k held-out paths)

Policy Mean P&L Std P&L Exp Cost Avg Turnover Cost+Risk
BS delta -3.52 1.43 3.46 3.37 4.94
Neural hedge -2.34 1.41 2.32 2.23 3.75

24% improvement in cost+risk. The network learned to trade less (turnover 2.23 vs 3.37), accepting a tiny variance increase in exchange for much lower costs.

tc-rate sweep

tc BS turnover Neural turnover BS C+R Neural C+R
0.0% 3.37 3.38 0.96 0.96
0.2% 3.37 2.90 1.70 1.62
0.5% 3.37 2.54 2.88 2.48
1.0% 3.37 2.22 4.94 3.75
2.0% 3.37 1.88 9.25 5.94
5.0% 3.37 0.97 22.49 12.05*

* Training failure at tc=5%: loss stagnated and the network over-reduced trades until variance blew up. Probably needs a lower lambda or a CVaR objective at that extreme cost level.

Neural turnover falls monotonically as tc rises; BS turnover is flat regardless of cost. A no-trade dead zone is visible in the gap-vs-trade scatter at tc=1%.

Stack

Python 3.13, PyTorch, torchdiffeq / torchsde / torchcde, numpy, scipy, matplotlib. ODE solver: dopri5. GPU: MPS (Apple M-series).

Status

Quant rail (pieces 1–3b) done. Physics rail next: ODEFunc network and short-window training on the damped pendulum.

About

Neural ODEs, CDEs, SDEs and deep hedging — building continuous-depth models from the maths up

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages