LIVE
connecting to the live quote stream…
--:--:--UTC
hardQuantPro○
#19

Heston Monte Carlo pricer

hardQuantacceptance —~45 min

Implement heston_call(S, K, T, r, v0, kappa, theta, xi, rho, steps, n, seed) — a European call under Heston stochastic volatility by Euler simulation with full truncation. Call random.seed(seed); for each path and step draw z1 = random.gauss(0, 1) then w = random.gauss(0, 1), set z2 = rho·z1 + sqrt(1 - rho²)·w, update v = max(v + kappa·(theta - v)·dt + xi·sqrt(max(v, 0))·sqrt(dt)·z2, 0) and S = S·exp((r - v/2)·dt + sqrt(v)·sqrt(dt)·z1) using the variance from the START of the step. Discount the mean payoff.

Five parameters and a correlation buy you a volatility smile that Black-Scholes cannot draw; the workbench's Heston surrogate is trained on this exact simulation. Return the price rounded to 4 decimal places.

example 1
input
S=100.0, K=100.0, T=1.0, r=0.02, v0=0.04, kappa=1.5, theta=0.04, xi=0.3, rho=0.0, steps=20, n=400, seed=7
output
9.2308
example 2
input
S=100.0, K=100.0, T=1.0, r=0.02, v0=0.04, kappa=1.5, theta=0.04, xi=0.3, rho=-0.7, steps=20, n=400, seed=7
output
9.1822
note

Same parameters with rho = −0.7: the skew appears.

constraints
  • -1 < rho < 1
  • kappa, theta, xi > 0
  • steps ≤ 40, n ≤ 1_000 (it has to run in your head, not on a cluster)
teacher · 2 hints · the first is free
↗ read the theory
the chapter this problem is cut from
▶ open in the workbench
run the same math on a real tape
●solution.py· utf-8 · spaces:4
ln 1, col 1tab indent · esc leave editor
python 3.13 · pyodide
+ 6 hidden on submit
input · keyword arguments to heston_call()
S=100.0, K=100.0, T=1.0, r=0.02, v0=0.04, kappa=1.5, theta=0.04, xi=0.3, rho=0.0, steps=20, n=400, seed=7
expected
9.2308

the judge calls heston_call() with exactly these inputs · outputs are compared to 6 decimal places

● standing bypython 3.13 in your browser · pyodide 0.28.3 · judged on the server to 6 dp⌘↵ run · ⌘⇧↵ submit
paper only · educational · not advice