Performance tip for calculating VWAP

If you’re drawing VWAP based on secondary data series, result is practically the same between VWAP based on 1 second vs tick (sporadic max 4 ticks discrepancy, for a second, at open), but CPU usage is much less. For the longest time I calculated based on tick data and just recently switched to seconds with huge difference in charts loading.

3 Likes

With all such approximations, the question is always how to distribute the volume across the low-to-high range of prices in the bar. With a one-second bar that issue is reduced, but not eliminated. I agree you’re on a good track in terms of reducing CPU while keeping most of the signal.

This is a useful optimization, and I think there is an important distinction here between VWAP and something like Volume Profile.

VWAP ultimately collapses the distribution into a single volume-weighted average. If price does not travel very far inside each one-second interval, a 1-second approximation can therefore end up extremely close to the tick-based result while saving a considerable amount of processing.

I would be much more cautious about carrying the same shortcut over to Volume Profile, though.

A profile needs to know how the volume was distributed across individual prices. Once several trades at different prices have been compressed into a one-second OHLCV bar, the total volume is still there, but the original volume-at-price distribution is no longer fully represented.

A test I like for this kind of optimization is to run both versions side by side over the same session and record:

  • maximum intraday deviation;

  • deviation around the cash open / other high-activity periods;

  • final session deviation;

  • CPU and chart-load difference.

For VWAP, a very small price error may be an excellent trade-off for the performance gain.

For Volume Profile, POC or VAH/VAL, I would benchmark separately because a small loss of source granularity can change which individual price level wins even when a single averaged value such as VWAP barely moves.

1 Like