'DataFrame VWAP Does not match TradingView
Not sure why I cannot get my DataFrame VWAP calculations to TradingView version at this link: https://www.tradingview.com/support/solutions/43000502018-volume-weighted-average-price-vwap/
They provide a simple calculation method which I can duplicate in a DataFrame but my calculations do not match. I believe it has something to do with the TradingView “Anchor Session” setting. Not sure how to adjust or add to my DataFrame calculations to match TradingView. I have also tried the Python Technical Analysis Library which does not match TradingView.
Simple Calculation
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)
Anchor Period
Indicator calculation period. This setting specifies the Anchor, i.e. how frequently the VWAP calculation will be reset. For VWAP to work properly, each VWAP period should include several bars inside of it, so e.g. setting Anchor to 'Session' and timeframe to '1D' is not useful because the indicator will be reset on every bar. Possible values: Session, Week, Month, Quarter, Year, Decade, Century, Earnings (reset on earnings), Dividends (reset on dividends), Splits (reset on splits).
# My VWAP - DataFrame Code:
df['Typ_Price'] = (df['high'] + df['low'] + df['close'] ) /3
df['Typ_PriceVol'] = df['Typ_Price'] * df['volume']
df['Cum_Vol_Price'] = df['Typ_PriceVol'].cumsum()
df['Cum_Vol'] = df['volume'].cumsum()
df['VWAP'] = df['Cum_Vol_Price'] / df['Cum_Vol']
print(df)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|