Hello vladisld,
I can't post my whole code, but I try to give you an overview about my logic:
class trade_list(bt.Analyzer):
# --> pasted code of the link in the problem description
class ZigZagStrategy(bt.Strategy):
# --> my Strategy
if __name__ == '__main__':
for i in range(len(alleSymbole)):
print("(", alleSymbole[i][0],")", ".... process complete .... ",round(i/len(alleSymbole)*100,2),"%")
cerebro = bt.Cerebro()
datapath = DATA_LOCATION+alleSymbole[i][0]+".csv"
data_df = pd.read_csv(datapath,
index_col=0,
usecols=["date", "open","high", "low", "close"])
data_df.index = pd.to_datetime(data_df.index)
feed = bt.feeds.PandasData(dataname=data_df,name=alleSymbole[i][0])
cerebro.adddata(feed)
cerebro.broker.setcash(STARTING_CAP)
cerebro.broker.setcommission(commission=COMMISSION, leverage=2)
cerebro.addanalyzer(TotalTrades, _name='total_trades')
strats = cerebro.run(tradehistory=True)
# get analyzers data
trade_list = strats[0].analyzers.trade_list.get_analysis()
trade_list_tabuliert = tabulate(trade_list, headers="keys")
trade_list_pandas = pd.DataFrame(trade_list)
# 1. calculating profit factor
winners = 0
winner_counter = 0
loosers = 0
looser_counter = 0
for q in range(len(trade_list_pandas["pnl"])):
if trade_list_pandas["pnl"][q] >= 0:
winners += trade_list_pandas["pnl"][q]
winner_counter += 1
else:
loosers += trade_list_pandas["pnl"][q]
looser_counter += 1
winners = winners / winner_counter
loosers = (loosers / looser_counter) * (-1)
profit_factor[i] = round(winners/loosers,2)
for l in range(len(trade_list_pandas["cumpnl"])):
Stock_Equity[l][i] = round(trade_list_pandas["cumpnl"][l],2)
symbole = np.empty(len(alleSymbole),dtype=str)
for i in range(len(alleSymbole)):
symbole[i] = alleSymbole[i][0]
pandas = pd.DataFrame(Stock_Equity.tolist(),columns=symbole)
PATHi = "/Users/MYPATH.xlsx"
pandas.to_excel(PATHi, index=True)
My Error message is here:
File "/Users/PATH", line 484, in <module>
strats = cerebro.run(tradehistory=True)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/backtrader/cerebro.py", line 1127, in run
runstrat = self.runstrategies(iterstrat)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/backtrader/cerebro.py", line 1257, in runstrategies
strat._addanalyzer(ancls, *anargs, **ankwargs)
Fi**le "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/backtrader/strategy.py", line 247, in _addanalyzer
analyzer = ancls(*anargs, **ankwargs)
TypeError: 'list' object is not callable