Disable ability to use lookahead-biased vwap

closes #5782
This commit is contained in:
Matthias 2021-10-17 11:23:58 +02:00
parent abd5c4f278
commit e23eb99abf
1 changed files with 6 additions and 4 deletions

View File

@ -339,11 +339,13 @@ def vwap(bars):
(input can be pandas series or numpy array) (input can be pandas series or numpy array)
bars are usually mid [ (h+l)/2 ] or typical [ (h+l+c)/3 ] bars are usually mid [ (h+l)/2 ] or typical [ (h+l+c)/3 ]
""" """
typical = ((bars['high'] + bars['low'] + bars['close']) / 3).values raise ValueError("using `qtpylib.vwap` facilitates lookahead bias. Please use "
volume = bars['volume'].values "`qtpylib.rolling_vwap` instead, which calculates vwap in a rolling manner.")
# typical = ((bars['high'] + bars['low'] + bars['close']) / 3).values
# volume = bars['volume'].values
return pd.Series(index=bars.index, # return pd.Series(index=bars.index,
data=np.cumsum(volume * typical) / np.cumsum(volume)) # data=np.cumsum(volume * typical) / np.cumsum(volume))
# --------------------------------------------- # ---------------------------------------------