我正在尝试根据一些历史数据对我的策略进行回测。但是,自2008年以来,我每天都在遍历50个符号。 For循环迭代将永远存在。
symbols = ['AAPL','GOOG',.......]
#df is a dataframe with all the 1 minute data of all the stocks from 2008 to #2019
returnsdf = []
for i in symbols['Symbol']:
df2 = df[df['Symbol']==i]
for i in list(set(df2.index.date)):
try:
returnsdf.append(strategy(df2[str(i)]))
except:
continue
def strategy(df):
do some operations on df
returns [timeOfTRade,entryPrice,exitPrice]