Possible to pass and return a dataframe to a strategy?
Is it possible to pass and return a dataframe to a strategy?
Got started with this post.
Here is a code snippet of the strategy parameters.
class TestStrategy(bt.Strategy): params = ( ('results', None), # This is the dataframe ('fastmaperiod', 10), ('midmaperiod', 20), ('slowmaperiod', 50), ('atrperiod', 15), # ATR Period (standard) ('atrdist', 3.0), # ATR distance for the strike price
cerebro.addstrategy(TestStrategy, results = results_df)
I want to return the results dataframe after the strategy has completed.
Cerebroreturns the strategy instances that have run.
The definition of what's returned is in the
Cerebroreference: https://www.backtrader.com/docu/cerebro/, section Returning the Results
You may pass a dataframe and later get it from the executed strategy.
Can you give me a hint how to get the dataframe from the executed strategy? May be obvious to a python expert but is not obvious to me. A simple example is usually good enough.
Executed strategy instances are returned. See
And each strategy has its parameters available as
Tejas Krishna Reddy last edited by
Just to provide an example,
strategy1 = cerebro.run() st = strategy1 # To return something back from the strategy - df = st.params.results # Will return your df back. st.params.midmaperiod # will return back 20 and so on.