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

To get multiple windows for plotting each multiple assets



  • Hi, I am currently running a simple Long & Short model for multiple equities.

    This is my final part of the codes :

    #Variable for our starting cash
    startcash = 1000000000
    
    #Create an instance of cerebro
    cerebro = bt.Cerebro(cheat_on_open=False)
    
    #Add our strategy
    cerebro.addstrategy(Long)
    
    datalist = []
    for i in bascket:
        datalist.append(('{}.csv'.format(i), i))
    
    for i in range(len(datalist)):
        data = EIKON_HLOC(dataname = datalist[i][0])
        cerebro.adddata(data, name=datalist[i][1])
        
    # Set our desired cash start
    cerebro.broker.setcash(startcash)
    cerebro.broker.set_coc(True)
    cerebro.broker.setcommission(commission=0.005)
    
    # add analyzers
    cerebro.addanalyzer(trade_list, _name='trade_list')
    cerebro.addanalyzer(open_list, _name='open_list')
    # run backtest
    strats = cerebro.run(tradehistory=True)
    # get analyzers data
    trade_list = strats[0].analyzers.trade_list.get_analysis()
    open_list = strats[0].analyzers.open_list.get_analysis()
    print (tabulate(open_list, headers="keys"))
    print (tabulate(trade_list, headers="keys"))
    #Finally plot the end results
    cerebro.plot(numfigs=1)
    

    and I get this packed window

    0_1540218014012_45811dd8-da40-4ab3-a0e4-18b0500a300f-image.png

    What I want here is to get separate windows for each equity.
    I tried :

    cerebro.plot(numfigs=5)
    

    But it rather gave me 5 different windows for all equities with different time-horizon (ex: 2010-2011, 2011-2012 ...)

    I have lots of things to learn about backtrader and python while doing my UG degree and I would really appreciate you guys help!

    Thank you :D


  • administrators

    There is no support for plotting each data on a different figure. The problem is that scrolling is not implemented by matplotlib, which would be the ideal solution.



  • @backtrader Thanks! I will try reformatting by using matplotlib then :)