bukosabino/ta

volume_price_trend is completly wrong

Groni3000 opened this issue · 2 comments

Wiki link you provided: https://en.wikipedia.org/wiki/Volume%E2%80%93price_trend
It tells: VPT is based on a running cumulative volume that adds or subtracts ...

Another link: https://www.barchart.com/education/technical-indicators/price_volume_trend
It tells: Add to yesterday's cumulative total:
Percentage Change * Volume [today] + PVT [yesterday]

I used TradingView indicator: Price Volume Trend by [everget] (https://ru.tradingview.com/u/everget/)
Окт 29, 2018
And it tells me the same...

So the formula should be
vpt = (closes.pct_change().dropna() * volume.iloc[1:]).cumsum() if you use pandas
or
np_closes, np_volume = closes.to_numpy(), volume.to_numpy()
np_vpt = np.cumsum((np_closes[1:]/np_closes[:-1] - 1) * np_volume[1:]) if you use numpy

But Tradingview version uses rolling SMA smoothing factor with 21 window by default like this:
tradingview_vpt = (closes.pct_change().dropna() * volume.iloc[1:]).cumsum().rolling(21).mean()
or IF YOU WANT - exponentially weighted with span like this:
tradingview_vpt = (closes.pct_change().dropna() * volume.iloc[1:]).cumsum().ewm(span=21, adjust=False).mean()

Check it please. Am I wrong or misunderstood?

Hi @Groni3000,

Sorry for the delay.

I am studying your suggested PR: #311

Hi @Groni3000,

Congratulations on your work!

The volume price trend indicator is now fixed and it is included in the latest version v0.11.0.