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

Plotting only chosen data?



  • Hi there,

    I work with a large universe (50+) and when backtesting, plotting the results is an unseeable mess.

    I was wondering if it is possible to filter the results and to only plot certain data that meet the filter - a simple example would be the top 3 and bottom 3 performing assets in the backtest.

    Any help would be much appreciated!



  • What to you mean by top 3 and bottom 3 performing? Could you be more specific?



  • Perhaps this can help you in the meantime. If you know which stocks you want to chart, you can add the following after you run cerebro and before you run cerebro.plot(). Below are some sample stocks in a list.

    wins_losses = ['CMD', 'EW', 'BKNG' ]
        for d in cerebro.datas:
            if d._name in wins_losses:
                d.plotinfo.plot = True
    

    You must tell backtrader not to plot the lines when you are adding in your data lines.

    You do this by setting 'plot=False' when creating your dataline.

    data = bt.feeds.PandasData(dataname=dataframe, name='AMZN', plot=False)
    
    # Add the Data Feed to Cerebro
    cerebro.adddata(data)
    

  • administrators

    @run-out said in Plotting only chosen data?:

    You do this by setting 'plot=False' when creating your dataline.

    This can be done at anytime, not only during creation.



  • @run-out
    Thanks for your input! Unfortunately, I don't know ahead of time which assets I would like to plot.

    I would like to access something rank-able, such as returns of each asset, and make plotting decisions based on that (top-performing, mean, bottom-performing - for example).

    Any ideas or tips on achieving that?


Log in to reply
 

});