Latest posts made by Tim Brug

Plotting Problems
OK  this thread explains that Pyplot turns on the checking and puts the matplotlib into headless mode. commenting out all the pyplot related code works so that I can now get the cerebro.plot code working without error.
I would very much still like an answer to the 2nd part of my question. i.e. Where does backtrader store the the time series of the portfolio results?

Plotting Problems
Re: Plotting inside JupyterLab
I am trying to teach myself backtrader, after doing the quickstart I jumped into the Momemtum Strategy blog by Teddy Kokker.
There are two things I would like help with:

Everything works until I try to plot and get the following :
*ImportError: Cannot load backend 'TkAgg' which requires the 'tk' interactive framework, as 'headless' is currently running*
I have tried numerous different iterations / suggestions of trying to import libraries in the right order and to add matplotlib.use('agg') or matplotlib.use('TkAgg'). All result in the same exact error.
Any help with this would be appreciated.
 Since i got stuck on that and it was stated in one of the blogs that backtrader is not intended as a plotting platform I thought fine. I would just plot the final portfolio series directly with matplotlib how hard could this be? I however am having trouble figuring out how to access the time series of the portfolio data. It obviously exists, i.e. the cerebero.plot function is accessing it. The momentum example puts results into results
results = cerebro.run()
using various print functions I can figure out how to get various other information. How do I get access to the portfolio time series information directly? It does not appear to be in results.
print(f"Sharpe: {results[0].analyzers.sharperatio.get_analysis()['sharperatio']:.3f}") print(f"Norm. Annual Return: {results[0].analyzers.returns.get_analysis()['rnorm100']:.2f}%") print(f"Max Drawdown: {results[0].analyzers.drawdown.get_analysis()['max']['drawdown']:.2f}%") print(f"Max Drawdown Days: {results[0].analyzers.drawdown.get_analysis()['max']['len']:.0f}") print(f"Final Portfolio Value: ${cerebro.broker.getvalue():.0f}") for x in results[0].analyzers: x.print()
