Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Average Volume Tool

I posted an algorithm like this a while ago to get a feel for the average volume profile for a stock. It splits the day up into 15 minute bars and averages the summed volume over e.g. 50 days. As expected opening volume is often high, but midday volume is normally low.

It looks like the old code was horribly buggy, so this is the (hopefully) bug-free version.

Trading idea: detect higher-than-average volume and trade it?

Research idea: multiply with standard deviation or coefficient of variation for each period to get some sort of risk measure?

some example outputs:

SPY, for the day of 2014-10-03  
09:30 |___+_______| avg 4,286,110  
09:45 |__________+| avg 9,566,519  
10:00 |________+__| avg 8,100,421  
10:15 |___+_______| avg 4,314,017  
10:30 |____+______| avg 5,199,986  
10:45 |__+________| avg 3,438,832  
11:00 |_+_________| avg 2,847,350  
11:15 |_+_________| avg 2,589,539  
11:30 |+__________| avg 1,974,574  
11:45 |+__________| avg 2,000,659  
12:00 |+__________| avg 2,011,643  
12:15 |+__________| avg 1,810,844  
12:30 |__+________| avg 3,063,876  
12:45 |_+_________| avg 2,309,463  
13:00 |+__________| avg 2,139,918  
13:15 |_+_________| avg 2,359,781  
13:30 |_+_________| avg 2,317,450  
13:45 |+__________| avg 1,862,101  
14:00 |_+_________| avg 2,548,634  
14:15 |+__________| avg 2,020,376  
14:30 |+__________| avg 1,890,426  
14:45 |+__________| avg 1,982,557  
15:00 |__+________| avg 3,455,738  
15:15 |_+_________| avg 2,295,834  
15:30 |___+_______| avg 4,348,935  
15:45 |________+__| avg 7,816,491

SPY, 50 day average, 2014-10-06  
09:30 |_________+_| avg 5,860,102  
09:45 |______+____| avg 4,436,230  
10:00 |______+____| avg 4,628,897  
10:15 |____+______| avg 3,388,130  
10:30 |___+_______| avg 3,202,702  
10:45 |____+______| avg 3,346,618  
11:00 |___+_______| avg 3,224,333  
11:15 |__+________| avg 2,641,541  
11:30 |__+________| avg 2,608,753  
11:45 |__+________| avg 2,366,560  
12:00 |_+_________| avg 2,104,312  
12:15 |_+_________| avg 2,002,188  
12:30 |_+_________| avg 1,924,918  
12:45 |+__________| avg 1,631,829  
13:00 |+__________| avg 1,830,455  
13:15 |_+_________| avg 2,028,191  
13:30 |_+_________| avg 2,184,216  
13:45 |_+_________| avg 2,074,436  
14:00 |___+_______| avg 2,940,176  
14:15 |_+_________| avg 2,309,741  
14:30 |_+_________| avg 2,117,535  
14:45 |_+_________| avg 2,206,116  
15:00 |__+________| avg 2,640,111  
15:15 |__+________| avg 2,632,735  
15:30 |___+_______| avg 3,298,939  
15:45 |__________+| avg 6,430,079

BRK_B, 50 day average, 2014-10-06  
09:30 |_______+___| avg 0,223,803  
09:45 |___+_______| avg 0,118,415  
10:00 |__+________| avg 0,109,785  
10:15 |__+________| avg 0,098,785  
10:30 |__+________| avg 0,099,232  
10:45 |__+________| avg 0,099,157  
11:00 |__+________| avg 0,093,092  
11:15 |_+_________| avg 0,085,136  
11:30 |_+_________| avg 0,080,494  
11:45 |_+_________| avg 0,072,821  
12:00 |+__________| avg 0,065,338  
12:15 |+__________| avg 0,065,387  
12:30 |+__________| avg 0,062,134  
12:45 |+__________| avg 0,055,230  
13:00 |+__________| avg 0,060,764  
13:15 |_+_________| avg 0,072,617  
13:30 |_+_________| avg 0,072,254  
13:45 |_+_________| avg 0,071,514  
14:00 |_+_________| avg 0,087,346  
14:15 |_+_________| avg 0,078,515  
14:30 |_+_________| avg 0,077,745  
14:45 |_+_________| avg 0,084,571  
15:00 |__+________| avg 0,094,058  
15:15 |__+________| avg 0,098,075  
15:30 |___+_______| avg 0,128,495  
15:45 |__________+| avg 0,280,983

EWJ (iShares Japan), 200 day average, 2014-10-06  
09:30 |___+_______| avg 1,464,722  
09:45 |__+________| avg 1,198,196  
10:00 |___+_______| avg 1,320,280  
10:15 |_+_________| avg 0,996,203  
10:30 |_+_________| avg 1,000,449  
10:45 |__+________| avg 1,146,853  
11:00 |__+________| avg 1,191,850  
11:15 |_+_________| avg 1,000,609  
11:30 |__+________| avg 1,099,580  
11:45 |_+_________| avg 0,908,533  
12:00 |_+_________| avg 0,843,027  
12:15 |+__________| avg 0,766,307  
12:30 |+__________| avg 0,709,156  
12:45 |+__________| avg 0,659,483  
13:00 |+__________| avg 0,673,392  
13:15 |+__________| avg 0,679,136  
13:30 |_+_________| avg 0,804,837  
13:45 |_+_________| avg 0,862,784  
14:00 |_+_________| avg 0,938,631  
14:15 |_+_________| avg 0,811,152  
14:30 |+__________| avg 0,752,432  
14:45 |_+_________| avg 0,813,710  
15:00 |_+_________| avg 0,869,246  
15:15 |__+________| avg 1,134,589  
15:30 |___+_______| avg 1,456,308  
15:45 |__________+| avg 3,148,161  

Those using the Research Beta Environment can produce nicer graphs.

3 responses

Hey James, you may want to have a look at the paper here, which explores the relationship between trading volume and returns.

Hi Ryan, I really like that paper. On p16 they say "we considered the idea that volume is correlated with absolute prices. Another popular belief is that volume is instead correlated with prices rather than the absolute value of prices, meaning that volume is high when prices move upwards, and low when prices move downwards". What's the difference between absolute prices and prices?
.

Hey James, I think the idea can be more accurately stated as a relationship between price changes, rather than the prices themselves, since prices are non-negative. The question we are interested in is whether volume is correlated with price changes irrespective of direction (for example, if increased volume leads price changes both in the up and down directions) or if volume is correlated only with price changes in the up direction (for example, an increase in volume may lead price changes in the up direction, and a decrease in volume may lead price changes in the down direction). Take a look at page 2 (1.1.2 Trading Volume) for details on microstructure, information flow, etc.