Recording the Trades
-
I would like to record all the trades in a system run.
I would like to save each trade in a pandas dataframe.I use notify_order to call a "Log" function
which contains the follow
md = {'dtopen':trade.open_datetime(),'dtclose':trade.open_datetime(),'price':trade.price}
self.dfTrades = self.dfTrades.append(md,ignore_index=True)In the init of the StrategyClass I also add
super().init()
self.dfTrades = pd.DataFrame()I'm not really getting this right, is there anyway I can get all the trades
into a pandas dataframe at the end of the run?Thank you
-
Analyzers track all the information you could want and then export them at the end of the run. Try this link and then let us know if you have any questions.
-
@run-out
Thanks. There are some stats that I'm not sure how to get though
Like Profit Factor, Avg Win/Loss, Profits Per Year
Most of these I would be able to calculate if I could simply save the
EntryDate, EntryPrice, ExitDate, ExitPrice, Pos(L/S)Is there any other way to get these? or do is it best to capture the trades when closed and save to a dataframe
-
@bchip
Think I may have found it under the Transactions analyzer
https://www.backtrader.com/docu/analyzers-reference/#transactions -
@bchip said in Recording the Trades:
@bchip
Think I may have found it under the Transactions analyzer
https://www.backtrader.com/docu/analyzers-reference/#transactionsAlso, If you cannot find what you need, developing an analyzer is not too hard. Just look at how those analyzers have been created. As a good example, have a look at @ab_trader add on trade list
-
@run-out Thank you