On 21 August 2026 the market surface of SPY, made here from a smile on top of real volatilities (the course has no option quotes), runs from 12.8% at three months to 14.2% at a year, with a skew: low strikes have a higher volatility. Black-Scholes-Merton with one volatility cannot reproduce that. The Heston model, in which the variance itself is random, can: five parameters, calibrated by a search that needs no derivatives, match the 15 quotes to 0.41 volatility points, with a correlation of −0.63 between the share and its variance. A put struck 10% below the spot costs 14.13 in the model and 13.48 in the market. This topic prices with Heston, builds its surface, and calibrates it.
When the volatility moves too
Where we are. In topic 10 the market quoted a different volatility for each strike and each expiry, and in topic 11 a model fitted caplets. For equity options we need a model that gives a smile and a skew by itself. In the Heston model the share has a variance v that is also random: dS = (r − q) S dt + √v S dW₁, dv = κ (θ − v) dt + ξ √v dW₂, with the two Brownian motions correlated by ρ. The variance is pulled back to its long-run level θ at speed κ, ξ is the volatility of the variance, and v₀ is the variance today. Five parameters: v₀, κ, θ, ξ, ρ.
Each parameter shapes the surface. A negative ρ means that the variance rises when the share falls: low strikes become dearer, a skew. A larger ξ makes the wings of the smile higher, the curvature. A large κ makes the variance forget its start quickly, so the smile fades as the expiry grows, as real smiles do. If 2κθ > ξ² (the Feller condition) the variance never reaches zero; markets often violate it, and the model still works.
The price of a call has no closed form in terms of v, but the model has a closed form for its characteristic function, the function φ(u) = E[exp(i u ln S_T)] of the log of the final price. Every probability distribution has one, and it determines the distribution. For Heston it has an explicit form, with complex numbers: a square root d and a ratio g, the 'little trap' form that stays well-behaved for long expiries. Four checks hold for any model: φ(0) = 1; φ(−i) = E[S_T], the forward price; |φ(u)| ≤ 1 for real u; and φ(−u) is the conjugate of φ(u).
Worked example 1. *Problem:* with v₀ = 0.04, κ = 2, θ = 0.04, ξ = 0.3 and ρ = −0.7, spot 100, rate 5%, dividend yield 2% and one year, evaluate the characteristic function at 0, at −i, at 2 and at 5. Then find its size at 0.5, 2 and 10. *Plan:* use heston_cf. *Steps:* below.
args = (0.04, 2.0, 0.04, 0.3, -0.7, 100.0, 0.05, 0.02, 1.0)values = heston_cf(np.array([0.0, -1j, 2.0, 5.0]), *args)1print([complex(round(v.real, 5), round(v.imag, 5)) for v in values], round(100.0 * math.exp(0.03), 5))2print([round(float(abs(v)), 5) for v in heston_cf(np.array([0.5, 2.0, 10.0]), *args)])3
[(1+0j), (103.04545+0j), (-0.90472+0.1684j), (-0.21203-0.58821j)] 103.04545 [0.99471, 0.92026, 0.22917]
- 1Four values of the argument: 0, −i, 2 and 5.
- 2At −i the function is the forward price.
- 3The size falls as u grows.
*Check:* the values are 1, 103.04545, −0.90472+0.1684j and −0.21203−0.58821j. At 0 the function is 1, and at −i it is 103.04545, which is 100 × e^(0.03), the forward price. The sizes at 0.5, 2 and 10 are 0.99471, 0.92026 and 0.22917: below 1 and falling. *What to notice:* these checks need no reference price. If your function fails the first two, its pricing will be wrong.
From the function to a price
The price is recovered from the characteristic function by inversion. A call is worth the share, when it is above the strike, minus the strike when it is: call = S e^(−qT) P₁ − K e^(−rT) P₂, where P₂ is the probability, under the pricing measure, that the call ends in the money, and P₁ is the same probability under a measure where the share is the unit of account. Both come from the characteristic function as integrals over u from 0 to infinity, which are cut at a high limit and computed by Gauss–Legendre quadrature: the sum of the integrand at a few hundred well-chosen points times weights. The integrand shrinks fast, so a limit of 100 is enough.
Worked example 2. *Problem:* price calls with strikes 80, 100 and 120, for the same parameters, and compare each with the Black-Scholes-Merton price at a volatility of 20%. Find the implied volatility of each Heston price. Then check put-call parity for strike 90: price the call and the put, and compare their difference with S e^(−qT) − K e^(−rT). *Plan:* use heston_call, heston_put and implied_vol. *Steps:* below.
P = (0.04, 2.0, 0.04, 0.3, -0.7)for strike in (80.0, 100.0, 120.0): price = heston_call(100.0, strike, 0.05, 0.02, 1.0, *P)1 print(strike, round(price, 4), round(bsm_price(100.0, strike, 0.05, 0.02, 0.2, 1.0), 4), round(implied_vol(price, 100.0, strike, 0.05, 0.02, 1.0), 4))2call, put = heston_call(100.0, 90.0, 0.05, 0.02, 1.0, *P), heston_put(100.0, 90.0, 0.05, 0.02, 1.0, *P)print(round(call, 4), round(put, 4), round(call - put, 4), round(100.0 * math.exp(-0.02) - 90.0 * math.exp(-0.05), 4))3
80.0 23.2207 22.7641 0.227 100.0 9.0595 9.227 0.1956 120.0 1.8016 2.7118 0.1695 15.4386 3.0293 12.4092 12.4092
- 1The Heston price.
- 2The Black-Scholes-Merton price at 20%, and the implied volatility of the Heston price.
- 3Put-call parity.
*Check:* the Heston prices are 23.2207, 9.0595 and 1.8016, against 22.7641, 9.227 and 2.7118 from the formula at 20%. Their implied volatilities are 0.227, 0.1956 and 0.1695: a skew, higher for the low strike, caused by the negative correlation. The call at 90 is 15.4386 and the put 3.0293; their difference, 12.4092, equals S e^(−qT) − K e^(−rT), as parity demands. (A simulation of 200,000 paths gives about 9.07 for the at-the-money call, with an error of 0.03.) *What to notice:* the price needs no simulation; one evaluation takes less than a millisecond.
The surface of a model
A model's surface is its prices turned into implied volatilities, strike by strike and expiry by expiry, with the function of topic 5. Look at how the parameters act. With ρ = −0.7 the smile slopes down: a skew. With ρ = 0 it is a symmetric smile, low in the middle and higher at both ends. And in both cases the smile is steeper for short expiries and flatter for long ones, because the variance forgets its starting point: the shape that real option markets show, and that a local volatility surface needs a lot of work to reproduce.
Worked example 3. *Problem:* compute the implied volatility grid of the Heston model for strikes 80 to 120 and expiries of 3 months, 1 year and 2 years, once with ρ = −0.7 and once with ρ = 0. *Plan:* use heston_vol_grid. *Steps:* below.
strikes = [80.0, 90.0, 100.0, 110.0, 120.0]for rho in (-0.7, 0.0): grid = heston_vol_grid(100.0, strikes, [0.25, 1.0, 2.0], 0.05, 0.02, (0.04, 2.0, 0.04, 0.3, rho))1 for row in grid: print(rho, [round(v, 4) for v in row])2
-0.7 [0.2431, 0.2203, 0.1974, 0.1756, 0.1596] -0.7 [0.227, 0.2108, 0.1956, 0.1817, 0.1695] -0.7 [0.2174, 0.2065, 0.1965, 0.1876, 0.1795] 0.0 [0.2112, 0.2009, 0.1968, 0.1994, 0.2059] 0.0 [0.2028, 0.1974, 0.1951, 0.1955, 0.198] 0.0 [0.1999, 0.1973, 0.196, 0.1959, 0.1966]
- 1One grid for each correlation.
- 2One row for each expiry.
*Check:* with ρ = −0.7 the 3-month row is [0.2431, 0.2203, 0.1974, 0.1756, 0.1596], a steep skew, and the 2-year row [0.2174, 0.2065, 0.1965, 0.1876, 0.1795], much flatter. With ρ = 0 the 3-month row is [0.2112, 0.2009, 0.1968, 0.1994, 0.2059]: low in the middle and higher at both ends, a smile. *What to notice:* the sign of the correlation sets the direction of the skew, and the expiry sets how strong it is.
Calibrating the five parameters
Calibration finds the parameters whose surface is closest to the market's. The error is the sum of the squared differences of the implied volatilities. The parameters have natural limits: the variance, its speed, its long-run level and its volatility must be positive, and the correlation must be between −1 and 1. An optimiser that searches freely over the numbers could leave this region. The usual trick is to search over an unconstrained vector x and to map it: exp for the four positive parameters and tanh for the correlation. The search is the Nelder–Mead method, which moves a simplex of six points over the five-dimensional space and needs no derivatives; it is given.
Worked example 4. *Problem:* make a market surface from known parameters (v₀ = 0.05, κ = 1.5, θ = 0.06, ξ = 0.5, ρ = −0.6; spot 100, rate 3%, dividend yield 1%; strikes 90, 100, 110; expiries 6 months and 1 year). Start the search from (0.03, 1.0, 0.04, 0.3, −0.3). Find the error at the start and at the end, and the parameters found. *Plan:* use heston_vol_grid, calibration_error and calibrate_heston. *Steps:* below.
true = (0.05, 1.5, 0.06, 0.5, -0.6)strikes, expiries = [90.0, 100.0, 110.0], [0.5, 1.0]market = heston_vol_grid(100.0, strikes, expiries, 0.03, 0.01, true)x0 = pack(0.03, 1.0, 0.04, 0.3, -0.3)print(round(calibration_error(x0, 100.0, strikes, expiries, 0.03, 0.01, market), 6))1params, error = calibrate_heston(100.0, strikes, expiries, 0.03, 0.01, market, x0)print([round(v, 4) for v in params], round(error, 8))2
0.011404 [0.0492, 1.7925, 0.0527, 0.2976, -0.9948] 1.155e-05
- 1The error at the start.
- 2The parameters found, and the error at the end.
*Check:* the error at the start is 0.011404; at the end it is 1.155e-05, a thousand times smaller. The parameters found are [0.0492, 1.7925, 0.0527, 0.2976, −0.9948]. *What to notice:* the surface is matched, to about 0.14 volatility points, but the parameters are not the ones that made it (ρ is at the edge, −0.995, not −0.6). Six quotes cannot pin down five parameters: several combinations produce almost the same surface. The calibration reproduces the quotes; it does not discover the truth.
Heston on SPY
Worked example 5. *Problem:* on the last day of the data, build the market surface: the level of the expiries 3 months, 6 months and 1 year is the historical volatility of the last 21, 63 and 126 days, the strikes are 80% to 120% of the spot, and the smile is the topic's smile that fades with the expiry. Calibrate Heston from the start (atm₀², 2, atm₂², 0.5, −0.5). Find the root-mean-square error of the fit, whether the Feller condition holds, and the price of a one-year put struck at 90% of the spot in the model and in the market. *Plan:* study combines the functions. *Steps:* below.
out = study(load_data())print([round(v, 4) for v in out["atm_vols"]])1print(round(out["v0"], 4), round(out["kappa"], 3), round(out["theta"], 4), round(out["xi"], 3), round(out["rho"], 3), round(out["rmse"], 5), out["feller"])2print(round(out["put_heston"], 3), round(out["put_market"], 3))3
[0.1282, 0.1367, 0.142] 0.0105 6.86 0.026 0.634 -0.628 0.00412 False 14.133 13.485
- 1The level of each expiry.
- 2The five parameters, the fit, and the Feller condition.
- 3The put in the model and in the market.
*Check:* the levels are 0.1282, 0.1367 and 0.142. The calibration gives v₀ = 0.0105 (a volatility of 10.2% today), κ = 6.86, θ = 0.026 (a long-run volatility of 16.1%), ξ = 0.634 and ρ = −0.628, with an RMSE of 0.00412, a little over four tenths of a volatility point. The Feller condition fails (2κθ = 0.36 against ξ² = 0.40), which is common for equities. The put costs 14.133 in the model and 13.485 in the market, a difference of about 5%. *What to notice:* the model has to rise to a long-run level above today's, which explains the upward term structure of the levels; and the fit is best near the money, where the quotes are most informative.
Several sets of Heston parameters can fit a surface almost equally well, as example 4 showed, so calibrated parameters move from day to day more than the market does. Hedge ratios and exotic prices depend on the parameters, not only on the vanilla quotes they were fitted to, so calibrate to enough strikes and expiries, check the parameters for sense (a correlation at −1 is a warning), and compare with a second calibration from another start. In QuantLib, HestonModel is the model, AnalyticHestonEngine prices with the characteristic function, HestonModelHelper is a calibration target and LevenbergMarquardt an optimiser.
- NameQuestion it answers
- heston_cf(u, v0, kappa, theta, xi, rho, spot, rate, div, t)What is the distribution of the final price?QuantLib: HestonProcess and the characteristic function
- heston_call(spot, strike, rate, div, t, v0, kappa, theta, xi, rho)What is a call worth in the model?uses heston_cfQuantLib: AnalyticHestonEngine
- heston_put(...)What is a put worth in the model?uses heston_callput-call parity
- heston_vol_grid(spot, strikes, expiries, rate, div, params)Which surface does the model produce?uses heston_calluses implied_vol
- unpack(x)Which parameters does this vector mean?keeps them in the allowed region
- calibration_error(x, spot, strikes, expiries, rate, div, market)How far is the model from the market?uses heston_vol_gridQuantLib: the cost function of the calibration
- calibrate_heston(spot, strikes, expiries, rate, div, market, x0)Which parameters fit the market?uses calibration_errorQuantLib: HestonModel.calibrate
What you will build
The lab follows the lecture. Task 1 is the characteristic function of the log of the final price in the Heston model. Task 2 prices a call from it with two integrals, and task 3 a put by parity. Task 4 turns the prices into a grid of implied volatilities, task 5 maps an unconstrained vector to the five parameters, and task 6 measures the distance between the model's surface and the market's. Task 7 runs the optimiser. Task 8 calibrates the model to a surface for SPY on the last real day and compares a put in the model and in the market.
Next topic: Validation: cross-checking against QuantLib. A pricing library is only as good as its tests. The next topic puts everything you built to the test: identities that must hold, such as put-call parity and convergence, agreement between engines that use different methods, and a comparison of the prices with reference values, with a report of the largest differences.
Lab · what's graded
8 tasks · 100 pts- The characteristic function20 pts
- A call price22 pts
- A put price4 pts
- The surface of the model8 pts
- The allowed region6 pts
- The distance to the market10 pts
- The calibration10 pts
- Heston on SPY20 pts