Finding the Root by Halving
The root search by hand: keep a bracket, price at the middle, and keep the half that still contains the quote; each step halves the uncertainty, and the same loop finds a strike when the price falls instead of rises.
The question
The last lesson let the engine find the implied volatility. How can a search like that work without a formula for the answer? Keep two volatilities, one whose price is below the quote and one whose price is above it. The answer lies between them. Price at the middle, keep the half that still has the quote inside, and repeat.
How many steps does that take, and what does each step tell you?
Work it by hand
Use the quote 9.00 for the call of the book (spot 100, strike 105, rate 0.05, one year) and start with the bracket 0.05 to 0.85. The middle is 0.45, where the call is 17.85. That is above 9.00, so the answer is below 0.45 and the bracket becomes 0.05 to 0.45.
The middle of that is 0.25, where the call is 10.00. Above 9.00 again, so the bracket becomes 0.05 to 0.25. Its middle is 0.15 and the call there is 6.04, below 9.00: now the lower end moves, and the bracket is 0.15 to 0.25. Each step halves the width: 0.8, 0.4, 0.2, 0.1. The three prices are the call at those volatilities: change the loop of the last lesson's program, or price the call with with_vol, to read them.
Run it
The program repeats the halving up to steps times, at most 16. Line 3 asks the engine for the root, to draw it as a flat line. Line 7 starts the loop over 16 possible steps, and line 8 lets only the first steps of them run. Line 10 prices the call at the middle volatility, and line 11 moves the lower end when the price is below the quote and the upper end otherwise. Line 18 returns the lower end after the last step, in millionths.

let m = model.black_scholes(spot, rate, 0.0, 0.2);
let option = instrument.european_call(strike, 1.0);
let root = calibration.implied_vol(option, m, pricing.analytic(), quote);
let lo = 0.05; let hi = 0.85;
let nums = float_list(); let lows = float_list();
let highs = float_list(); let roots = float_list();
for (k in range(0, 16)) {
if (k < steps) {
let mid = (lo + hi) / 2.0;
let p = pricing.price(option, m.with_vol(mid), pricing.analytic()).price();
if (p < quote) { lo = mid; } else { hi = mid; }
nums.add(float(k + 1)); lows.add(lmf.round(lo, 6));
highs.add(lmf.round(hi, 6)); roots.add(lmf.round(root, 6));
}
}
lmcode_return_put("steps", nums); lmcode_return_put("low", lows);
lmcode_return_put("high", highs); lmcode_return_put("root", roots);
let answer = int(math_round(lmf.round(lo, 6) * 1000000.0));
{
"answer": 221875,
"steps": [
1,
2,
3,
4,
5,
6,
7,
8
],
"low": [
0.05,
0.05,
0.15,
0.2,
0.2,
0.2125,
0.21875,
0.221875
],
"high": [
0.45,
0.25,
0.25,
0.25,
0.225,
0.225,
0.225,
0.225
],
"root": [
0.224685,
0.224685,
0.224685,
0.224685,
0.224685,
0.224685,
0.224685,
0.224685
]
}The picture draws the two ends of the bracket after each step, with the engine's root as a flat third line. Choose steps from 1 to 16: more than 16 runs 16 steps, and 0 runs none, so the answer is the starting end 50000 and the picture has no points.
A quote that the engine cannot reach stops line 3 with "price 0.001 is outside the range reachable with volatility in [0.0001, 5]". A quote that it can reach but that lies outside the prices of the bracket does not stop the loop: it walks to one end of the bracket.
Your turn
The same search works on another unknown. The program below is meant to find the strike at which the call is worth target, by halving the bracket 41 to 169 steps times, and to return the lower end of the bracket, in whole cents. Decide whether it does, and find the candidates that do. Check runs each candidate on the data shown and on four others.

let m = model.black_scholes(spot, rate, 0.0, vol);
let lo = 41.0;
let hi = 169.0;
for (k in range(0, steps)) {
let mid = (lo + hi) / 2.0;
let option = instrument.european_call(mid, float(years));
let p = pricing.price(option, m, pricing.analytic()).price();
if (p < target) { lo = mid; } else { hi = mid; }
}
let answer = int(math_round(lmf.round(lo, 2) * 100.0));
{
"answer": 4100
}The call (no dividend, volatility vol, strike unknown) is worth target at some strike between 41 and 169. Start with the bracket lo = 41, hi = 169 and repeat steps times: price the call at the middle strike and keep the half of the bracket that still contains the strike at which the call is worth target. Return the lower end of the bracket after the last step, in whole cents. steps is at most 9.
Read the result carefully
Halving works because the price is monotone in the unknown and the bracket contains the root. It says nothing about whether the quote is right. After n steps the unknown is known to within the width of the bracket, here 0.8 divided by 2 to the power n, not exactly: the engine's root is the exact answer that the lower end approaches.
The quote, the target and the other inputs are made up. The page describes a method of arithmetic on a model and is not investment advice.
Recap
- Keep a bracket that contains the root and halve it by pricing at the middle.
- Each step halves the width, so n steps leave a bracket of the width divided by 2 to the power n.
- Halving needs the price to be monotone in the unknown.
- The lower end after n steps approaches the engine's root; it does not equal it.