pikers / piker

(e2e) foss trading for non-tinas
GNU Affero General Public License v3.0
102 stars 17 forks source link

VWAP needs tick, let's do eet #119

Open goodboy opened 3 years ago

goodboy commented 3 years ago

I could be losing it but, it sure seems almost all retail platforms aren't computing vwap correctly? This likely has to do with with most platforms not providing historical tick data and/or just not using it for the computation.

The standard we've seen a lot of traders use is from tradingview's built-in which was not previously anchored, but recently got updated for such. TV has an explanation and calculation which describes it as:

There are five steps in calculating VWAP:

Calculate the Typical Price for the period.

[(High + Low + Close)/3)]

Multiply the Typical Price by the period Volume.

(Typical Price x Volume)

Create a Cumulative Total of Typical Price.

Cumulative(Typical Price x Volume)

Create a Cumulative Total of Volume.

Cumulative(Volume)

Divide the Cumulative Totals.

VWAP = Cumulative(Typical Price x Volume) / Cumulative(Volume)

Here's pine script implementing this with multi-anchoring.

This is somewhat amusing since OHL3 loses information and smooths the volume weighted part. To be fair I'm sure there's some error margin here that isn't so bad but this definitely is not analytically correct by the original definition.

Here's some resources for that definition:

Ideally we can run (psuedo-)tick quote samplers on as many feeds as possible and generate an accurate VWAP calc as a built-in. We're undecided at this point if the OHL3 approach should be used for aggregated history; is there a better typical price per bar measure?

goodboy commented 3 years ago

This is getting more amusing by the day.

Apparently TWS devs think they've implemented vwap on charts based on this "completed" feature request: https://www.interactivebrokers.com/en/index.php?f=2493&sid=10784

It's pretty clear to anyone who can compute the proposed func themselves (or who can compare with other platforms) that this line when plotted in tws doesn't match at all...in fact it's not even close.

Further amusement comes from the vwap value delivered by the RTVolume data feed which appears to be (at least a) session-anchored vwap calc when compared manually with the ohc3 typical price method computed from ohlc data. The value appears to also have large steps in value arbitrarily throughout the session which points at it probably not being computed on high(er) frequency ohlc data.

The final lolz they also include a so called WAP value in historical data: https://interactivebrokers.github.io/tws-api/historical_bars.html#hd_receive

But, it's only shown in the receive callback example and this value appears to map to nothing shown in TWS studies whatsoever (including not matching the VWAP of the bar as you'd expect).

:exploding_head:

goodboy commented 3 years ago

It's amazing to me that this is still the definition no matter where we look: https://www.marketvolume.com/technicalanalysis/vwap.asp