Exporting the generated backtest result in csv format.
-
Exporting data in csv.
Hey guys can u please help me on how to export the data of trades and all the details printed in the terminal to csv files.
I want to export all my trades in csv files
@run-out @ab_trader @backtrader -
Take a look at the tradelist analyzer: https://community.backtrader.com/topic/1274/closed-trade-list-including-mfe-mae-analyzer
-
IIRC everything printed to terminal by python script can be saved to text file when you run script:
python your script.py > results.txt
-
You may want to try Writer also
https://www.backtrader.com/docu/writer/ -
Thanks a lot guys. You guys are genius with Backtrader.
I would like to know that can remove some extra details from csv file when using Writer.Like pnl ,tickers etc
-
@Abhishek-Agrawal said in Exporting the generated backtest result in csv format.:
I would like to know that can remove some extra details from csv file when using Writer.
Like pnl ,tickers etcIf you are comfortable using pandas, you can use the following with the TradeList analyzer:
import pandas as pd ... cerebro.addanalyzer(TradeList, _name="trade_list") strat = cerebro.run(tradehistory=True) ... # Save trade list. trade_list = strat[0].analyzers.getbyname("trade_list").get_analysis() df = pd.DataFrame(trade_list) df = df.drop(['pnl', 'pnl/bar', 'ticker'], axis=1) df.to_csv("trade_list.csv")