Speed

The Standard Error

The standard error of a Monte Carlo estimate is the sample standard deviation of the discounted payoffs divided by the square root of their number. The estimate plus or minus 1.96 standard errors is a 95% interval for the model price, about the sampling error only.

The question

The estimate of the last lesson came from one seed and is one draw of a random quantity. A different seed would give a different estimate. How far can an estimate be from the number it estimates, and can the simulation tell us, without knowing the answer?

It can. The payoffs of the samples scatter, and the average of n of them scatters less than the payoffs themselves, by a factor of the square root of n. The standard error is the estimate of that scatter, computed from the same samples. This lesson computes it, compares it with the engine's, and builds the 95% interval around the estimate.

Work it by hand

Take four discounted payoffs 0, 5, 20 and 0, an assumption for this hand example. The mean is 6.25. The deviations from it are -6.25, -1.25, 13.75 and -6.25, their squares add up to 268.75, and dividing by n - 1 = 3 gives the sample variance 89.58. The sample standard deviation is its square root, about 9.46.

The standard error of the mean is that divided by the square root of n, which is 2: about 4.73. It is the size of a typical miss of the mean, not of a single payoff.

The 95% interval is the estimate plus or minus 1.96 standard errors, because 1.96 is the point that leaves 2.5% of a normal distribution on each side. Here it would be 6.25 plus or minus 9.28, wide because four samples say little; with so few samples the 1.96 itself is not trustworthy, and it is meant for thousands of samples.

Run it

The loop of lines 7 to 11 adds up the discounted payoffs and their squares. Line 12 takes the mean and line 13 the standard error from the sums, with n - 1 in the denominator. Line 14 asks the engine for its Monte Carlo price with the same seed, and line 19 returns the engine's own standard error from Result.stderr(). Line 15 takes the 1.96 from lmf.norm_inv(0.975), and lines 20 and 21 return the two ends of the interval.

The picture lists the estimate, the two standard errors, the interval and the closed form.

Seven values: the estimate 10.347, both standard errors 0.145, the interval from 10.0628 to 10.6313, the multiplier 1.96 and the closed form 10.4506.
let m = model.black_scholes(spot, rate, 0.0, vol);
let call = instrument.european_call(strike, 1.0);
let st = model.terminal_samples(m, 1.0, n, seed);
let disc = lmf.exp(0.0 - rate);
let sum = 0.0;
let sq = 0.0;
for (i in range(0, st.len())) {
  let x = call.payoff(st.at(i)) * disc;
  sum = sum + x;
  sq = sq + x * x;
}
let mean = sum / float(n);
let se = sqrt((sq - float(n) * mean * mean) / float(n - 1) / float(n));
let run = pricing.price(call, m, pricing.monte_carlo_plain(n, seed));
let z = lmf.norm_inv(0.975);
let exact = pricing.price(call, m, pricing.analytic()).price();
lmcode_return_put("estimate", lmf.round(mean, 4));
lmcode_return_put("own", lmf.round(se, 4));
lmcode_return_put("engine", lmf.round(run.stderr(), 4));
lmcode_return_put("low", lmf.round(mean - z * se, 4));
lmcode_return_put("high", lmf.round(mean + z * se, 4));
lmcode_return_put("z", lmf.round(z, 2));
lmcode_return_put("exact", lmf.round(exact, 4));
let answer = int(math_round(lmf.round(exact, 2) * 100.0));
{
  "answer": 1045,
  "estimate": 10.347,
  "own": 0.145,
  "engine": 0.145,
  "low": 10.0628,
  "high": 10.6313,
  "z": 1.96,
  "exact": 10.4506
}

With seed 42 and 10,000 samples the estimate is 10.35, both standard errors are 0.145, the interval runs from 10.06 to 10.63 and the closed form 10.45 lies inside it. These come from the seed; another seed gives other numbers.

You can change the inputs. n must be from 2 to 10000: 1 stops line 14 with "monte carlo: the standard error needs at least 2 paths, got 1", and the limits of model.terminal_samples stop line 3 as in the previous lessons. A strike of 0 or less stops line 2. A strike so far out of the money that every sampled payoff is 0 gives a standard error of 0 and an interval of one point.

A spot or a volatility of 0 or less stops line 1 with "model.black_scholes: spot must be positive" or "model.black_scholes: volatility must be positive". Inputs far outside any sensible range stop the run as well: a rate of 800 stops line 8 with "Option.payoff argument 1 must be finite".

Your turn

The list payoffs holds discounted payoffs. The program below is meant to return the standard error of their mean in whole cents: the sample standard deviation, with n - 1 in the denominator, divided by the square root of n. Decide whether it does, and find the candidates that do. Check runs each candidate on the data shown and on four others.

A list of seven discounted payoffs from 0 to 33.1, and the standard error in whole cents that the shown program returns.
let n = float(payoffs.len());
let total = 0.0;
for (i in range(0, payoffs.len())) {
  total = total + payoffs.at(i);
}
let mean = total / n;
let ss = 0.0;
for (i in range(0, payoffs.len())) {
  ss = ss + (payoffs.at(i) - mean) * (payoffs.at(i) - mean);
}
let se = sqrt(ss / (n - 1.0)) / n;
let answer = int(math_round(lmf.round(se, 2) * 100.0));
{
  "answer": 179
}

The list payoffs holds the discounted payoffs of a Monte Carlo run, at least two numbers. Return the standard error of their mean in whole cents: the sample standard deviation, the square root of the sum of squared deviations from the mean divided by n - 1, divided by the square root of n. Check runs each candidate on the data shown and on four others.

Read the result carefully

No engine call computes the statistics of a list; the demo sets the engine's number beside the formula, and Result.stderr() is this number. It exists only for the Monte Carlo engines: asking an analytic price for it stops with "Result.stderr: this engine does not provide it; use the risk functions (bumped Greeks)".

The interval is about the sampling error only, and it holds for the model price. "95%" means that about 95 of 100 seeds give an interval that covers the model price; the interval of this seed may be one of the others. A list of one payoff has no standard error: the exercise program then divides by zero and the run stops with "LmfApi.round argument 1 must be finite".

Money answers are whole cents because the engine works in binary floating point, where numbers such as 1.1 or 105.05 have no exact form and a raw result can end in a stray digit; the page rounds with lmf.round before it shows or compares. It is a description of an arithmetic model and not investment advice.

Recap

  • The standard error of the mean is the sample standard deviation divided by the square root of n.
  • The sample variance divides the squared deviations by n - 1.
  • Estimate plus or minus 1.96 standard errors is a 95% interval for the model price.
  • The interval measures the sampling error, not the error of the model's assumptions.