For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

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.

    Thanks,
    Dave


  • administrators

    Cerebro returns the strategy instances that have run.

    The definition of what's returned is in the Cerebro reference: 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.


Log in to reply
 

});