Skip to content

Add example: exact Heston MC Greeks via AADC (144x speedup) - #251

Open
mar20tinha-dot wants to merge 1 commit into
domokane:masterfrom
mar20tinha-dot:feat/aadc-heston-mc-greeks
Open

Add example: exact Heston MC Greeks via AADC (144x speedup)#251
mar20tinha-dot wants to merge 1 commit into
domokane:masterfrom
mar20tinha-dot:feat/aadc-heston-mc-greeks

Conversation

@mar20tinha-dot

Copy link
Copy Markdown

Summary

Adds an example showing how AADC (Automatic Adjoint Differentiation) can compute exact pathwise Greeks for FinancePy's Heston Monte Carlo simulation.

The example records the EulerLog MC scheme on an AADC tape and replays all paths in a single batch call, producing exact gradients w.r.t. all 6 model parameters (S0, v0, kappa, theta, sigma, rho) at negligible extra cost.

Results (200K paths, 50 steps)

Method Time What
FinancePy MC 0.76s 1 price
FinancePy + FD 9.7s price + 6 Greeks (13 runs)
AADC batch 0.07s price + 6 Greeks (1 pass)
Speedup 144×

All Greeks verified against finite differences on the same paths (ratio 0.998–1.02).

Key technique

  • Random normals marked with mark_as_input_no_diff() — no gradient, but values change per scenario
  • An array of values (one per path) is passed for each random input
  • One aadc.evaluate() call replays the tape for all scenarios via ThreadPool

Dependencies

  • aadc (pip install aadc, free evaluation, no licence key)
  • No changes to FinancePy source code

🤖 Generated with Claude Code

Records FinancePy's Heston EulerLog MC scheme on an AADC tape and
replays all paths in one batch call, producing exact pathwise Greeks
w.r.t. all 6 model parameters (S0, v0, kappa, theta, sigma, rho).

200K paths + 6 Greeks in 0.07s vs 9.7s for finite differences (144x).
All Greeks verified against FD on same paths (ratio 0.998-1.02).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@domokane

domokane commented Aug 8, 2026

Copy link
Copy Markdown
Owner

Looks good. Give me some time to look at this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants