Hello everones i attend to Quantitave Trading Strategies and medels and studiying Bolingers bands Strategy cod on spider and when i typing
'df.loc[(df['upper'].shift(2) > df['Close'].shift(2))&(df['upper'].shift(2)<df['Close'].shift(2))&(df['R_Std'].shift(1)>df['Ret'].shift(1)),'Signal']=1' it throws
''>' not supported between instances of 'method' and 'float' "
how can ı handle of it. thanks
This line of code looks perfectly fine. Can you send the whole code so that we can investigate further?
ok whole code is:
import talib as t
from talib import MA_Type
import numpy as np
import pandas as pd
import matplotlib as plt
df=pd.read_csv("/Users/ayti/Desktop/Python for Trading kodlar/quantitative Trading Strategies and Models/Downloadables-PFT/Backtesting/APPLE.csv",index_col=0,parse_dates=True)
del df['Adj_Volume']
del df['Adj_Low']
del df['Adj_Open']
del df['Adj_High']
del df['Dividend']
del df['Split']
del df['Volume']
del df['Adj_Close']
#%%
VALUE OF 'n' FOR STANDART DEV?ATON
n=60
#RETURNS AND STANDARD DEVATION
df['Ret']=df['Close'].pct_change()
df['R_Std']=df['Ret'].rolling(window=n).std
#BOL?NGER BANDS
df['upper'],df['middle'],df['lower'] = t.BBANDS(np.array(df['Close']), matype=MA_Type.T3)
#%%
#S?GNAL COLUMNS
#We check when the market cross the upper Bollinger Bands and compare that day's return with the standard
#deviation of returns. Similarly, we will apply the opposite criterion as discussed in the video for
#the lower Bollinger Bands and break out
df['Signal']=0
df['Signal']=0
df.loc[(df['upper'].shift(2)>df['Close'].shift(2))&(df['upper'].shift(1)<df['Close'].shift(1)) \
& (df['R_Std'].shift(1)>df['Ret'].shift(1)),'Signal']=1
df.loc[(df['lower'].shift(2)<df['Close'].shift(2))&(df['lower'].shift(1)>df['Close'].shift(1)) \
& (-df['R_Std'].shift(1)<df['Ret'].shift(1)),'Signal']=-1
#Strategy returns
df['Str_ret']=df['Signal']*df['Ret']
Try replacing this line of code df['R_Std']=df['Ret'].rolling(window=n).std with
df['R_Std']=df['Ret'].rolling(window=n).std()
yes you right how did i miss it thanks for your attantion and respond