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
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
-
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 :)
-
In the realm of data visualization and financial analysis, the concept of obtaining multiple windows for simultaneously plotting various assets has emerged as a powerful tool. This capability allows analysts and traders to efficiently monitor and compare the performance of diverse investments in real time. Whether it's stocks, commodities, or cryptocurrencies, the ability to visualize their trends and correlations side by side provides a comprehensive perspective. This functionality is as adhesive as https://gluesavior.com/, seamlessly combining insights from multiple assets to aid in making informed decisions and gaining a holistic understanding of the market landscape.
-
To plot each equity in a separate window, you need to loop through the strategies after running cerebro and call plot on each one individually:
strats = cerebro.run() for i, strat in enumerate(strats): cerebro.plot(stratname=datalist[i][1], figsize=(15,8))
This will plot each strategy in a separate figure, with the name of the equity as the title.
The key points:
cerebro.run() returns a list of strategy instances You can loop through this list and access each strategy Call cerebro.plot() and pass the stratname to use as the plot title Adjust the figsize as needed to control the size of each plot
So this will give you a separate plot for each equity in your basket, rather than packing them all into one figure or splitting by time period.
Let me know if that helps or if you have any other questions here: [https://www.qedge.co/](link url) or search "qedge"