Speed

Fitting the Model to Quotes

Calibration searches the five Heston parameters so that the model's implied volatilities come close to quoted ones; in the example the model reprices all ten made-up quotes within 5 basis points, and the page looks at the misfit and not at the parameters.

The question

A model with five parameters can be adjusted to quotes. How is that done, and what is the result worth looking at?

Calibration searches the five Heston parameters so that the model's implied volatilities are as close as possible to a set of quoted ones. The number to look at is how far the model is from each quote, the misfit, and not the parameters that came out. The quotes here are ten made-up volatilities: five strikes at one year and the same five at two years, with spot 100 and a rate of 5%. It is a description of an arithmetic model and not investment advice.

Work it by hand

The misfit of one quote is the model's implied volatility minus the quoted one. With a misfit of 0.0003 the model is 3 basis points above the quote; 100 basis points are 1 percentage point. A calibration is judged by all its misfits together: one common summary is the root mean square, the square root of the average of the squared misfits.

For a quote of 23.26% and a model volatility of 23.29% the misfit is 3 basis points. The page does not fit by hand: the search over five parameters is the engine's work, and the exercise is the summary of the misfits.

Run it

The program takes the strikes, two lists of quoted volatilities, one for one year and one for two years, and the spot and the rate. Line 1 starts a fit; the two loops of lines 2 to 7 add one quote per strike and maturity (the statement f.quote(...) adds a quote); line 8 runs the search; line 9 reads the misfit of every quote, in the order the quotes were added.

The loop from line 11 turns each misfit into the volatility the model gives, in whole basis points, and counts the quotes the model reprices within 5 basis points (line 19). Line 22 returns that count. The table shows the strike, the years, the quoted and the model volatility in basis points.

A table of ten rows with strike, years, quoted and model volatility in basis points: strikes 80 to 120 at 1 year from 2326 to 1678 and at 2 years from 2239 to 1787, the model equal to the quote in every row.
Watch the steps (recorded video)
let f = calibration.heston(spot, rate, 0.0);
for (i in range(0, strikes.len())) {
  f.quote(strikes.at(i), 1.0, vols1.at(i));
}
for (i in range(0, strikes.len())) {
  f.quote(strikes.at(i), 2.0, vols2.at(i));
}
f.fit();
let e = f.errors();
let rows = str_list(); let near = 0;
for (i in range(0, e.len())) {
  let k = i % strikes.len(); let yrs = 1 + i / strikes.len();
  let quoted = vols1.at(k);
  if (yrs == 2) { quoted = vols2.at(k); }
  let q = int(math_round(quoted * 10000.0));
  let refit = int(math_round(lmf.round(quoted + e.at(i), 4) * 10000.0));
  let sk = str(strikes.at(k));
  rows.add(sk + "|" + str(yrs) + "|" + str(q) + "|" + str(refit));
  if (abs(e.at(i)) * 10000.0 < 5.0) { near = near + 1; }
}
lmcode_return_put("rows", rows);
let answer = near;
{
  "answer": 10,
  "rows": [
    "80|1|2326|2326",
    "90|1|2147|2147",
    "100|1|1976|1976",
    "110|1|1817|1817",
    "120|1|1678|1678",
    "80|2|2239|2239",
    "90|2|2111|2111",
    "100|2|1993|1993",
    "110|2|1885|1885",
    "120|2|1787|1787"
  ]
}

The quotes are the example smile of this book at 1 and 2 years, rounded to four decimals, so a good fit is expected: the recorded table shows the model equal to every quote in whole basis points. The fitted parameters are not shown: several parameter sets fit the same quotes almost equally well, and the search can end at slightly different numbers on different computers.

You can change the lists, which must have the same length as strikes: a shorter vols1 stops at line 3 and a shorter vols2 at line 6, with "FloatList.at: index out of range: 4" (four entries against five strikes). A strike or a volatility of 0 stops at line 3 (line 6 for vols2) with "HestonFit.quote: strike, years and volatility must be positive". The table shows the first 16 of the quotes (eight strikes at two maturities); with more, the count in the answer still covers all of them.

The fit needs at least five quotes in all: two strikes at two maturities are four, and stop at line 8 with "Heston fitting needs at least 5 quotes (it has 5 parameters)". Wild quotes do not stop the fit: with volatilities alternating between 5% and 90% the run finishes with a model far from every quote and a count of 0.

Your turn

A desk compares a model with its quotes: the lists quoted and priced hold the quoted and the model implied volatilities, one per quote in the same order. It wants the root mean square of their differences, in millionths: the volatility difference times 1,000,000, so 0.0001 is 100. The program below is meant to return it. Decide whether it does, and find the candidates that do. Check runs each candidate on the lists shown and on five others.

Five quoted volatilities, the five volatilities of the model, and the millionths that the shown program returns.
let total = 0.0;
for (i in range(0, quoted.len())) {
  let d = priced.at(i) - quoted.at(i);
  total = total + d;
}
let mean = total / float(quoted.len());
let answer = int(math_round(lmf.round(mean, 8) * 1000000.0));
{
  "answer": 140
}

The lists quoted and priced hold implied volatilities per quote, in the same order. Return the root mean square of the differences priced minus quoted, in millionths: the square root of the average of the squared differences, times 1,000,000, rounded to a whole number.

Read the result carefully

A small misfit says that the model can reproduce these ten numbers, and nothing more. The quotes were made from a Heston model with the fixed example's parameters, so a good fit is possible by construction (the search found one here); real quotes carry no such guarantee. The fitted parameters depend on the starting guess, on the quotes chosen and on the computer, which is why the page shows none.

A model with five free parameters can fit many shapes of five or ten quotes, and a close fit does not show that the model is right. The page shows no price, no forecast and no advice. It is a description of an arithmetic model and not investment advice.

Recap

  • Calibration searches the model's parameters so that its implied volatilities come close to the quotes.
  • The result to look at is the misfit of each quote, not the fitted parameters.
  • A root mean square of the misfits summarises the fit.
  • The quotes of the page were made from a Heston model, so a good fit says little.