Testing Popular Ideas · Lesson 6
VWAP
An average that counts shares, two opposite readings, 24 versions, and what costs do to a rule that trades all day.
Know the basics? Read the lesson notesAn average that counts shares
A five-minute bar is a candle for a five-minute window: its first price, highest, lowest and last price (the close). Its volume is how many shares traded in it.
VWAP, the volume-weighted average price, averages the prices so far with each bar counted by its shares. Each bar needs one price. Here it is the typical price, (high + low + close) ÷ 3. Multiply it by the bar's volume, add these up from the first bar, and divide by the shares added up. Press Next bar.
Four bars (made up)
Dots: each bar's typical price. Grey bars: its volume. Orange: VWAP so far.
After four bars VWAP is 990 ÷ 10 = 99.
The plain average of the four prices is 99.5; the heaviest bar, at 96, pulls VWAP below that. Sources differ on the price: with the closes instead, VWAP is 98.5. Now add a fifth bar at 104 and drag its volume up.
With 90 thousand shares, nine times the first four together, VWAP is (990 + 104 × 90) ÷ 100 = 103.5. One heavy bar can set the line almost alone.
VWAP through one simulated day
Now a simulated market: prices and volumes made up by a computer, not a real market. It rises slowly on average, its moves come in calm and wild spells, and past prices, the day's earlier bars included, say nothing about which way the next move goes (we built it so: the generator's own setting for five-minute bars leaves a small pull-back within each day, so this lesson uses its corrected setting, which removes it). Its day runs from 09:30 to 16:00: 78 five-minute bars. Its volumes are made up too: more shares near the open and the close, more on wild days, and not tied to which way a bar moved.
Slide through the day. At each bar, VWAP uses only the bars so far.
One day, 5 June 2017 (simulated)
Dark: the close of each bar. Orange: VWAP. Grey bars: volume.
At the 16:00 close of 98.25, VWAP was 97.71. Early on it follows each new price; by the afternoon it has most of the day's shares behind it and barely moves.
Where the sums start
The VWAP above starts its sums at the day's first bar and goes back to zero the next morning: a session VWAP. The moment it starts again is the reset time. Markets that also trade before the open, or around the clock, need a choice of hour, and each choice draws another line.
An anchored VWAP starts at one bar you choose and never resets. One choice is each Monday's first bar. Try three starting points on one simulated week.
One week, 5–9 June 2017 (simulated)
Dark: the closes. Orange: VWAP from the chosen start.
Friday closed at 99.26. VWAP read 99.96 from that morning, 98.83 from Monday and 99.18 from Wednesday.
Same prices, same volumes: the line depends on where its sums start.
Bands around VWAP
Bands put a distance around VWAP. Their unit is a volume-weighted standard deviation: lesson A8's typical distance from the average, with each bar counted by its shares. For each bar so far, square its price's distance from VWAP and multiply by its volume; add these up, divide by the shares, take the square root.
Your four bars: distances from 99 of −1, +5, +1 and −3; squared and times volume, 1 + 50 + 3 + 36 = 90; 90 ÷ 10 = 9; √9 = 3.
The bands sit k of these above and below VWAP; k is the width. With width 2: 99 ± 2 × 3 = 105 and 93. Try both widths on the simulated day.
VWAP and its bands, 5 June 2017 (simulated)
Dark: the closes. Orange: VWAP and its bands. Dots: closes outside the bands, from 09:45.
Of the day's 75 closes from 09:45 on, 37 were outside the width-1 bands and 8 outside the width-2 bands.
One name, opposite rules
"Trade VWAP" is not a rule yet. Two common readings are opposite:
- Trend: price above VWAP means strength. Buy when a bar closes above the upper band; sell when a close falls back below VWAP.
- Mean reversion (mean is the textbook word for average): price below VWAP is cheap and should come back. Buy when a close is below the lower band; sell when a close is back above VWAP.
Width 0 means VWAP itself. A rule decides at a bar's close and trades at the next bar's first price. It starts at 09:45, after three bars, and sells whatever it holds at 16:00: nothing is kept overnight. Each buy and each sale counts as one trade. Try both readings at every width.
Two readings, three widths, 5 June 2017 (simulated)
Shaded: bars the rule is in the market. Dots: the closes that made it buy.
At width 0 trend made 8 trades that day and mean reversion 6; at width 2, 2 each.
At width 0 the two readings split the day: after the first signal, exactly one of them is in the market at every bar (37 bars and 38).
A cost on every trade
Start with one exact rule: trend at width 0, typical price, session VWAP. Call it the baseline version: this lesson's starting point, not a rule from any source.
It runs on seven years of the simulated market, 2015 to 2021, against just holding: buying at the first 09:45 close and never selling, nights included (lesson E1). Each buy and each sale costs 0.1% of the price, the round figure lessons E2 to E5 use (lesson A16, Costs); holding pays it once. Results are in % a year: the steady yearly growth that gives the same total.
Holding made 4.4% a year. The baseline version traded 7.6 times a day on average. After costs, where did it end?
The baseline version and holding, 2015–2021 (simulated)
Accounts starting at 100, on a scale where each line marks ten times less. Dotted: holding. Grey: the baseline version before costs. Orange: after costs.
One market is one draw
Now the baseline version and its opposite, mean reversion at width 0, on each of 1,000 other simulated markets built the same way, first before costs. A result's lead is its % a year minus holding's, in points (a point is 1% a year).
The baseline version's lead over holding on 1,000 simulated markets, before costs
Bars: markets by size of lead. Orange: ahead of holding.
Before costs the baseline version beat holding in 157 of the 1,000 simulated markets and its opposite in 192: the two readings came out close.
Both trailed holding in most markets: each was in the market about half of each day and never overnight, while holding always was, in markets that rise on average.
For the precise
Before costs, across the 1,000 simulated markets: average leads −5.60 (the baseline version) and −5.19 (its opposite) points a year; a gain in 747 and 770; both a gain in 575; both ahead of holding in 68. The gap between the two averages, 0.41 points a year, is about two standard errors and small next to either lead. After costs the baseline version averaged −85.9% a year; even in its best market it made −82.8% a year.These markets were built with nothing to find in which way prices move next, so the counts show what these rules produce when there is nothing to find. They cannot show whether VWAP rules work in any real market.
How many versions?
The tempting next move is to try other settings: either reading; width 0, 1 or 2; the typical price or the close; and sums that reset each day or each Monday.
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 24, on one market and on 1,000
Here are all 24 versions on the same simulated market, 2015 to 2021. Call those the choosing years: a version will be chosen on them. Show them, then turn the costs on.
24 versions: each one's lead over holding, 2015–2021 (simulated)
One bar per version, fewest trades a day on the left; ordered by trades, not by lead, so a bar can be taller than the one before it. Above the line: beat holding. Black: the baseline version.
Before costs 2 of the 24 beat holding; after costs, none. The best after costs was mean reversion at width 2, with the close and sums from Monday, 20.0 points a year behind holding. It traded least, 0.83 times a day. A version's place counts from the largest lead; its place was 1st (a blind draw is first 1 time in 24).
After costs, in none of the 1,000 simulated markets did any version beat holding, or even end with a gain.
For the precise
Across the 1,000 simulated markets the versions traded from 0.81 to 7.69 times a day on average. After costs the four at width 2 with sums from Monday averaged places 1.5 to 3.5; the four at width 0 with daily sums, 21.7 to 23.3. Before costs 3.7 of the 24 beat holding, on average, and at least one did in 394 markets. At a fifth of the cost, 0.02% a trade, no version beat holding in 933 of the 1,000.Does the best stay best?
2022 to 2024 were set aside as years held out, to be used once for the choice below (lesson The held-out test).
On each of the 1,000 simulated markets we took the best of the 24 on the choosing years after costs, 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 42 of 1,000 (1,000 ÷ 24). Guess how often the pick stayed best.
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 517 of the 1,000 simulated markets, against a blind draw's 42. It still trailed holding there in 998.
The extra is not skill. The version with the fewest trades on the choosing years, chosen without looking at any result, was best on the held-out years in 587: the low trade count paid off again, not a find.
For the precise
All after costs, across the 1,000 simulated markets. The pick was the fewest-trades version in 647; it was always at width 2 with the close and sums from Monday (mean reversion in 649, trend in 351). Its held-out place averaged 1.8 of 24, and it beat holding there in 2 markets. Picked and judged before costs, it stayed best in 62. At 0.02% a trade it stayed best in 233. No two versions shared first place on the held-out years in any market, so a blind draw is best in exactly 1,000 ÷ 24 = 41.7.VWAP and its bands
VWAP (volume-weighted average price) is the average price since an anchor, the first bar its sums use, with each bar counted by its volume. Its bands sit k volume-weighted standard deviations of the same prices above and below it. All three are worked out again at every bar, that bar included.
- Pi
- bar i's price: in this lesson the typical price, (high + low + close) ÷ 3; some tools use the close
- Vi
- bar i's volume: the shares traded in it
- a
- the anchor: the first bar the sums use (each day's first bar for a session VWAP)
- st
- the volume-weighted standard deviation: the typical distance of the prices from VWAP, each bar counted by its volume
- t
- the bar now; each sum runs over every bar from a to t
- k
- the width, in volume-weighted standard deviations
Prices 98, 104, 100, 96; volumes 1, 2, 3, 4 thousand. VWAP = (98 + 208 + 300 + 384) ÷ 10 = 990 ÷ 10 = 99. Squared distances times volume: 1 × 1 + 2 × 25 + 3 × 1 + 4 × 9 = 90, so s = √(90 ÷ 10) = 3. At k = 2: 105 and 93.
- each volume is the shares actually traded in that bar, all of them (one trading venue's volume gives another line; lesson B4, Data quality);
- the price, the anchor and the reset time are stated.
One bar's volume dwarfs the rest: the line then sits near that bar's price for the rest of the day (a fifth bar of 90 thousand shares at 104 moved it from 99 to 103.5).
Three new bars: typical prices 20, 23 and 22 with volumes 5, 2 and 3 thousand shares. What is VWAP after the third bar?
What this means for your test
- Write the exact rule before you run it.
"VWAP" names a line, not a rule. Say the price, the anchor and reset time, the band and its width, the reading, the entry and the sale, the price each trade gets and the costs.
- Subtract the costs for every trade, then compare with just holding.
A rule that trades all day pays all day: in this simulation the baseline version's 7.6 trades a day at 0.1% each cost about 0.76% a day.
- Count the versions, the opposite reading too, then hold out years.
24 here. After costs the best of 24 stayed best on held-out years in 517 of 1,000 simulated markets, against about 42 for a blind draw. The extra came from trading least, not from a find.
A friend's spreadsheet
What VWAP do you get?
Hint: each bar's typical price is (high + low + close) ÷ 3. Multiply each by its volume, add up, divide by the shares.
A backtest "before fees"
About how much, in % of the account, would it pay in costs each day?
Hint: trades a day × cost of one trade.
Lesson done
VWAP is the running sum of price × volume divided by the running sum of volume, from an anchor: each day's first bar for a session VWAP, any chosen bar for an anchored one. Its bands sit a set number of volume-weighted standard deviations away. Reading, width, price and reset made 24 versions. These markets were built with nothing to find in which way prices move next, so the counts show what these rules produce when there is nothing to find: before costs the baseline version and its opposite each trailed holding on average; at 0.1% a trade, no version beat holding or even ended with a gain in any of 1,000 simulated markets, and the best of 24 stayed best on held-out years in 517 (a blind draw: about 42) because it traded least, not because it found anything. They cannot show whether VWAP rules work in any real market.
Key ideas
- VWAP
- volume-weighted average price: the prices since the anchor, each bar counted by its volume
- Typical price
- (high + low + close) ÷ 3 for a bar; some tools use the close instead
- Anchor, reset time
- the bar where VWAP's sums start; a session VWAP starts again at each day's first bar, an anchored VWAP never resets
- Volume-weighted standard deviation
- the typical distance of the prices from VWAP, each bar counted by its volume; bands sit k of these above and below VWAP
- Trend, mean reversion
- opposite readings of VWAP: buy above it, or buy below it. Each is a rule to test, not a finding
- Version
- the same idea with different settings; count every one
Formulas
VWAPt = (PaVa + … + PtVt) ÷ (Va + … + Vt) · P = (high + low + close) ÷ 3
st = √( [Va(Pa − VWAPt)² + … + Vt(Pt − VWAPt)²] ÷ (Va + … + Vt) ) · bands = VWAP ± k × s