Algotopian is starting. Let it be the future of backtrader. Check it out! https://www.algotopian.com
For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

Interpreting optimization results when using multiple strategies



  • Hello gentlemen,

    I would like to integrate Bokeh plotting for optimization results but I have a problem interpreting optimization results when using multiple strategies.

    Let's say I have this test code:

    cerebro.optstrategy(TestStrategy, buydate=range(14, 16, 1))
    cerebro.optstrategy(TestStrategy2, buydate=range(11, 13, 1))
    cerebro.addanalyzer(bt.analyzers.TradeAnalyzer)
    data = ...
    cerebro.adddata(data)
    res = cerebro.run()
    

    Now I have a list of 4 entries in the variable res (all possible strategy combinations), which is fine for me. Each of these entities contain a list 2 OptReturn objects. One for each strategy involved.
    But how can I know which of these OptReturn objects belongs to which of the two strategies? I mean: I have 2 OptReturn objects and I have 2 strategies. They only contain the set of optimization parameters and a list of analyzers.

    0_1517560361811_4a3aea20-4080-412a-a12f-41a10170cc63-image.png

    Thank you!


  • administrators

    They are returned in the same order in which they were inserted. You can also deactivate the return of the OptReturn objects and get the strategies by setting optreturn=False

    Docs - Cerebro



  • @backtrader
    Thanks for quick answer.

    So I would need to have access to strategy list which means I need a reference to the cerebro object to be able to process the OptReturn objects programmatically, right?

    As far as I can see the plotting interface (which is called when trying to plot the OptReturn) does not provide a reference to the the cerebro object in the call:
    https://github.com/backtrader/backtrader/blob/development/backtrader/plot/plot.py#L116

    So my idea would be to pass a reference to the cerebro object (or maybe just to the strategy list) in the constructor call to my Bokeh plotting object (only needed when planning to plot optimization results with optreturn=True). Then when plotting OptReturns the cerebro can be used to find the corresponding Strategy object and add, for example, the name of the strategy.

    Does this sound reasonable or are there maybe better approaches to get the corresponding strategies?

    EDIT:
    Hm, another problem:
    The plot function is called for every OptReturn object seperately, so I don't know the current index in the list which I need to access the Strategy list... hm...


  • administrators

    @vbs said in Interpreting optimization results when using multiple strategies:

    So I would need to have access to strategy list

    No. Your best bet is to use optreturn=False and get Strategy instances returned instead of OptReturn objects.

    @vbs said in Interpreting optimization results when using multiple strategies:

    The plot function is called for every OptReturn object seperately, so I don't know the current index in the list which I need to access the Strategy list... hm..

    This because if you are optimizing you can end up with hundreds or thousands of Strategy instances. Plotting was deemed to be meaningless. Hence the optimization in the returned values.



  • I agree that plotting is not useful when having a certain amount of outputs. I just thought it would make sense to implement it since cerebro actually is trying to plot optimization results. However the integrated plotter seems to yield an exception when trying to plot opt results.


  • administrators

    End users are (sometimes) also responsible for their actions, i.e.: trying to plot an optimization run.


Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.