twopirllc / pandas-ta

Technical Analysis Indicators - Pandas TA is an easy to use Python 3 Pandas Extension with 150+ Indicators
https://twopirllc.github.io/pandas-ta/
MIT License
5.28k stars 1.04k forks source link

VWAP Bands request like IB #532

Open rotemkama opened 2 years ago

rotemkama commented 2 years ago

Which version are you running? The latest version is on Github. Pip is for major releases.

import pandas_ta as ta
print(ta.version)
0.3.64b0

Indicator addition to match another broker

Hi, So kind of new around here, and I've been looking for indicator to match certain behavior of VWAP standard deviation bands like the bands that appears in Interactive brokers management portal . I've been examining the indicator that has been recently added here https://github.com/twopirllc/pandas-ta/pull/488 and his behavior and results is pretty different from IB's one. (BTW, while searching for this topic all around it seems that most of the formulas and libs are getting the same results as your indicator).

In the example attached, I pulled the data of a stock in 5 mins candles, calculated the VWAP and bands using your indicator, and got the same VWAP value, but very different bands values. I've been looking for 8 and 11 bands in the IB terminology and definition (example of the setting attached) but the results I'm getting are very different and it seems that the "issue" is with the calculation over time of the bands (again, pretty new to all of this). I will appreciate help and will provide any data as I can! Thanks!

DataFrame data: wfc_five_minutes_candles.zip

My code and plot:

df = pd.read_json(json.dumps(data))
df.sort_values(by="datetime", inplace=True)
df.set_index(pd.DatetimeIndex(df["datetime"]), inplace=True)
vwap = df.ta.vwap(anchor="D", bands=[8, 11], offset=None, append=False)
last = 100
adp = mpf.make_addplot(vwap.tail(last), type='line')
mpf.plot(df, figratio=(10, 5), type='candle', addplot=adp, volume=True, style='yahoo')

plot: image

Interactive indicator setup screen and values: image

interactive plotting: image

twopirllc commented 2 years ago

Hello @rotemkama,

In the example attached, I pulled the data of a stock in 5 mins candles, calculated the VWAP and bands using your indicator, and got the same VWAP value, but very different bands values.

That's good. At least the core value, vwap is consistent. But it is clear that the IB bands are not the same as the bands in this library.

When I use the IB vwap settings you use, I do not get all 10 channel lines like your IB candle/vwap. I just get the vwap and the upper and lower bands for the given standard deviation. I assume you have four other settings for the other 4 bands? (Just making sure our IB settings are consistent also).

Uncertain when I will be able to look at this more in depth. Hopefully someone with a similar interest can take a look at it also and help out.

Kind Regards, KJ

rotemkama commented 2 years ago

Yes you are right about the four other setting. :) Thanks for the willing to help, really looking forward to it and i'm also trying my best to implement if (doing some tests.

I'm adding IB reference for their explanation about it, maybe it will help us solve the issue:

IB Intraday VWAP

Thanks again!