Testing Popular Ideas · Lesson 5
Volatility bands (Bollinger Bands®)
An average, a width and two opposite readings: the 72 versions inside one idea.
Know the basics? Read the lesson notesAn average and a typical distance
The bands are built from two numbers. One is the average of the last few closes (a close is a day's last price): lesson E2's moving average. The other is their standard deviation, their typical distance from that average: square each distance, average the squares, take the square root (lesson A8).
Here are five made-up closes, few enough to work by hand. Press Next step.
Five closes (made up)
Dotted: their average. Lines: each close's distance from it.
The average is 22 and the standard deviation 4.
We divided the 80 by 5, the number of closes, as this lesson does throughout. Some tools divide by one less (lesson A8 has both): √(80 ÷ 4) ≈ 4.47. Sources differ, so check which a tool uses.
Two bands around the average
Now draw one line 2 standard deviations above the average and one 2 below: 22 ± 2 × 4 = 30 and 14. The average is the middle band, and the two lines are the upper band and the lower band. The 2, the number of standard deviations, is the width. Try another width.
Five closes and their bands (made up)
Dotted: the middle band. Orange: the upper and lower band.
A larger width moves both bands out; the middle band stays.
The customary values are 20 closes and a width of 2, written 20/2: a custom, not the result of a calculation.
The bands on a market
Now the last 20 closes at a time, on one year of a simulated market: prices made up by a computer, not a real market. It rises slowly on average; beyond that, past prices say nothing about which way the next move goes (we built it so).
Each day the middle band is the average of the last 20 closes, today's included, and the bands sit 2 standard deviations of those closes above and below it. Volatility is how much prices move: the bands spread after big moves and narrow after small ones. John Bollinger devised them (sources below the lesson).
A close above the upper band or below the lower band is a close outside. Lesson A5's bell-curve rule says about 95 values in 100 land within 2 standard deviations of the average, leaving about 5 outside. Guess how many of this year's 260 closes were outside, then count them.
Closes and their bands, 2017 (simulated)
Dark: the close. Dotted: the middle band. Orange: the bands; orange dots: closes outside.
33 of the 260: about 13 in 100, not 5. The dots come in runs: 27 of the 33 sit in runs of two or more days. When prices move fast in one direction, the average trails behind them, so several closes in a row sit beyond a band. Lesson A5's rule is for values drawn independently around a fixed, known average; here neither holds. Now try another number of closes and another width.
Other settings give other counts: how often a close is outside depends on the data and the settings. It is a count, not a law.
On 1,000 more simulated markets built the same way, the share at 20/2 averaged 12.6 in 100.
For the precise
Across the 1,000 simulated markets the share ran between 10.1 and 14.9 in 100. Each is ten years long; the first nine months only start the averages, as in lessons E2 to E4, and every count uses the rest. In this simulated 2017 the 33 closes outside formed 14 runs, the longest 6 days. Over the five days ending on a close outside the price had moved 4.0% on average, sign dropped, against 1.4% on the other days. Across the 1,000 simulated markets, 50.8 in 100 closes outside came directly after another one. In 2017 the counts at 10/2, 50/2, 20/1.5 and 20/2.5 were 18, 53, 85 and 10; across all nine settings they ran from 2 (at 10/2.5) to 92 (at 50/1.5). With only 5 closes, dividing by 5, no close can ever be more than 2 standard deviations from its own average, so 5-close bands of width 2 never have a close outside. In general the limit is √(n − 1) standard deviations for n closes: 3 for 10 closes, 4.36 for 20. On the bell curve's exact figure, 4.6 values in 100 land more than 2 standard deviations out.One name, opposite rules
"Trade the bands" is not a rule yet. Two common readings are opposite:
- Mean reversion (mean is the textbook word for average) reads a price at the lower band as fallen too far. It buys there and sells when the price closes back above the middle band.
- Breakout reads a price at the upper band as strong. It buys there and sells when the price closes back below the middle band.
"At the band" is a choice too. A touch: the day's lowest price reached the lower band (for breakout, the highest reached the upper band). Or a close outside. On touches, one of John Bollinger's published rules says: "Tags of the bands are just that, tags not signals."
A rule decides at a day's close, since the bands need that close, and trades at the next day's first price (lesson E2). Between a buy and its sale it is in the market; the rest of the time it holds nothing. Show all four on the same year, at 20/2.
Two readings, two entries, 2017, at 20/2 (simulated)
Shaded: days the chosen rule is in the market. Dots: the days that made it buy.
With a touch, mean reversion bought 5 times and breakout 7; with a close outside, 2 and 6. One name, four different sets of trades.
One rule against just holding
Start with one exact rule: mean reversion, entered on a touch and sold above the middle band, at 20/2. Call it the baseline version. It is this lesson's starting point, not a rule the bands' originator gives (his quoted rule says a touch is not a signal); only the 20 and the 2 are customary.
It runs on six years of the simulated market (late 2015 to the end of 2021) against just holding: buying on the first day and never selling (lesson E1). Each buy and each sale costs 0.1% of the price (lesson A16, Costs); holding pays that once. Results are in % a year: the steady yearly growth that gives the same total.
Holding made 6.3% a year. After costs, where did the baseline version end?
The baseline version and holding, 2015–2021, after costs (simulated)
Accounts starting at 100. Orange: the baseline version. Dotted: holding.
After costs it made 3.7% a year in this simulated market: a gain, and behind holding's 6.3%.
One market is one draw
Now run the baseline version on each of the 1,000 other simulated markets.
A result's lead is its % a year minus holding's, in points (a point is 1% a year). On the market above the lead was 3.7 − 6.3 = −2.6 points a year.
The baseline version's lead over holding on 1,000 simulated markets, after costs
Bars: markets by size of lead. Orange: ahead of holding.
After costs it beat holding in 130 of the 1,000 simulated markets and trailed it in 870. The average lead was −7.4 points a year.
These markets rise on average, and across them the baseline version was in the market on only 29 days in 100, on average.
These markets were built with nothing to find in past prices, so the counts show what these rules produce when there is nothing to find. They cannot show whether the bands work in any real market.
Is the opposite reading the answer?
In this simulation, buying at the lower band trailed holding. So try the baseline version's opposite: breakout, entered on a touch and sold below the middle band, at 20/2, on the same market, years and costs. Where do you think it ended?
On the 1,000 simulated markets, after costs, both of these rules ended with a gain in 387. Both beat holding in 39.
So "it made money" can be true of a rule and its opposite at once. In markets that rise on average, a rule that is in the market part of the time often ends with a gain, whichever band it buys at.
How many versions?
The tempting next move is to try other settings: three lengths (the last 10, 20 or 50 closes), three widths (1.5, 2 or 2.5), either reading, a touch or a close outside. And two sales: at the middle band, as before, or the opposite-band sale, which waits for a close beyond the other band (above the upper band for mean reversion, below the lower one for breakout).
Each different set of choices is a version: the same idea with different settings (lesson E1, How we test an idea). How many versions is that?
All 72, on one market and on 1,000
Here are all 72 versions on the same simulated market and years, 2015 to 2021. Call those the choosing years: a version will be chosen on them. Show them, then turn the costs on.
72 versions: each one's lead over holding, 2015–2021 (simulated)
One bar per version; in each reading, largest before-costs lead first, so with costs on the bars need not descend. Above the line: beat holding. Black: the baseline version. Solid orange: the best. Ticks: before-costs leads.
Before costs 12 of the 72 beat holding; after costs, 8. The best was a breakout version (touch, middle-band sale, 10/1.5): it led holding by 6.3 points a year before costs and by 3.0 after. The baseline version came 30th of the 72: its place, counting from the largest lead after costs.
A find, or the luck of the best of many (lesson B7, The best of many)? Run all 72 on the 1,000 simulated markets.
Across the 1,000 simulated markets the best version after costs was a mean-reversion one in 478 and a breakout one in the rest: close to a coin flip between two opposite readings.
For the precise
All after costs, on the choosing years of the 1,000 simulated markets. A breakout version was the best in 522. "Best" is the largest lead, even one below zero: in 224 markets no version beat holding, and on average 11.9 of the 72 did. The baseline version's place averaged 43.2 of 72; a version drawn at random averages 36.5. On the one market shown, the best version made about 30 buys and sells a year, and its costs took 3.3 points a year.Does the best stay best?
Before any version was run, 2022 to 2024 were set aside: years held out, to be used once (lesson B10, The held-out test).
On each of the 1,000 simulated markets we took the best of the 72 on the choosing years, the pick, and ran it once on the held-out years, after costs. A blind draw, one version taken at random, would be best there in about 14 of 1,000 (1,000 ÷ 72). Guess how often the pick stayed best, then run them.
The pick's held-out place on 1,000 simulated markets, after costs
One bar per place, 1st on the left. Dashed: a blind draw.
The pick stayed best in 43 of the 1,000 simulated markets, against a blind draw's 14. In the other 957 it was not the best on the held-out years.
Why 43 and not 14? The pick usually had the opposite-band sale, so it was in the market on more days, which helps in markets that rise on average. That is what the averages suggest, not a controlled test.
For the precise
All after costs, across the 1,000 simulated markets. The pick had the opposite-band sale in 915 markets. On the choosing years the picks were in the market on 61% of days and made 5.3 buys and sells a year, on average; all 72 versions averaged 42% and 9.3. On the held-out years the pick beat holding in 310 markets; the baseline version, with no picking, in 226. The pick's held-out place averaged 29.2 of 72; all versions of its rule averaged 31.9, and a blind draw averages 36.5. In 24 markets two or more versions shared first place on the held-out years; counting those ties, a blind draw is best in 14.3 markets, where 1,000 ÷ 72 gives 13.9. On the one market shown earlier, the best version of the choosing years made 5.5% a year on the held-out years against holding's 10.0%: a lead of −4.5 points, 19th of the 72.The three bands
Volatility bands are three lines built from the last n closes: a simple moving average, and a line k standard deviations above and below it. The standard deviation is a moving standard deviation: worked out again each day, like the average. Until n closes exist there are no bands. A touch compares a day's highest or lowest price with bands built from closes, that day's included.
- Ct
- the close on day t; each sum runs over the last n closes, today's included
- n
- the length: how many closes (20 by custom)
- Mt
- the middle band: the simple moving average of those n closes
- st
- their standard deviation, dividing by n in this course (some tools divide by n − 1)
- k
- the width, in standard deviations (2 by custom)
n = 5, k = 2. M = (24 + 20 + 16 + 22 + 28) ÷ 5 = 22. Squared distances: 4 + 4 + 36 + 0 + 36 = 80, so s = √(80 ÷ 5) = 4. Upper = 22 + 2 × 4 = 30, lower = 22 − 2 × 4 = 14.
- the closes are in order, one per day, none missing or wrong (lesson B4, Data quality);
- the length, the width and the divisor are stated.
The bands are read with the bell curve's "95 in 100 inside": in this lesson's simulated markets about 13 closes in 100 were outside at 20/2.
Four new closes: 8, 12, 12 and 8, with n = 4 and k = 1.5, dividing by n. What is the upper band?
What this means for your test
- Write the exact rule before you run it.
"The bands" names three lines, not a rule. Say the length, the width and the divisor; the reading; touch or close outside; where it sells; the price each trade gets and the costs.
- Subtract the costs, then compare with just holding, not with zero.
In this simulation the baseline version and its opposite both ended with a gain, after costs, in 387 of 1,000 simulated markets. Both beat holding in 39.
- Count the versions, the opposite reading too, then hold out years.
72 here. After costs, the best of 72 stayed best on held-out years in 43 of 1,000 simulated markets; a blind draw would in about 14. The extra is not skill: the pick usually had the opposite-band sale, so it spent more days in a market that rises on average (what the averages suggest, not a controlled test).
A friend's spreadsheet
What lower band do you get?
Hint: the average; the squared distances, added up; ÷ 5; square root. Lower band = average − 2 × that.
Two videos, one chart
What follows?
Lesson done
The bands are an average of the last closes with a line a set number of standard deviations above and below it. A close lands outside them about 13 times in 100 at 20/2 in these simulated markets, not the bell curve's 5: a count that moves with the data and the settings. Reading, entry, sale, length and width made 72 versions. These markets were built with nothing to find in past prices, so the counts show what these rules produce when there is nothing to find: after costs the baseline version trailed just holding in 870 of 1,000 simulated markets, it and its opposite both ended with a gain in 387, and the best of 72 stayed best on held-out years in 43 (a blind draw: about 14; the extra is not skill: the pick usually had the opposite-band sale, so more days in a market that rises on average, as the averages suggest). They cannot show whether the bands work in any real market.
Key ideas
- Middle band
- the average of the last n closes (20 by custom): a simple moving average
- Upper band, lower band
- the middle band plus and minus k standard deviations of the same closes (the width k is 2 by custom; dividing by n in this course, by n − 1 in some tools)
- Close outside, touch
- a close beyond a band; a day whose highest or lowest price reached one. How often depends on the data and the settings
- Mean reversion, breakout
- opposite readings of the bands: buy at the lower band, or at the upper one. Each is a rule to test, not a finding
- Version
- the same idea with different settings; count every one
Formulas
Mt = (Ct−n+1 + … + Ct) ÷ n · st = √( [(Ct−n+1 − Mt)² + … + (Ct − Mt)²] ÷ n )
upper = M + k × s · lower = M − k × s