2019-10-02: The community is currently in read-only mode
Plotting JUST the account's value
Curtis Miller last edited by
Hello all. I'm new to backtrader and I'm excited to learn it.
I've managed to set up a Simple Moving Average Crossover strategy to get started, that processes multiple stock symbols. The backtest does in fact work, which made me happy, but in a Jupyter notebook the resulting plot is cramped to the point that it's hard to read it. Most of the time I am interested only in the performance of the account. How can I get a plot of JUST what's happening in the account (it's overall value, cash available, like what's normally the top-most plot)? Is there a way to restrict, after the fact (so not by setting each symbol's
plotparameter, and not redoing the backtest every time I want a new plot), which symbols actually get plotted? Is there a way to resize the plot? I've been looking through the documentation (excellent, by the way), and I'm struggling to see how these are controlled.
The plotting functionality was designed with data as the centre of the plot.
The easiest way is to set
data.plotinfo.plot = Falsefor data feeds right after creation or passing
data = MyDataFeed(dataname=xxx, plot=False)during creation.
For large numbers of symbols the 2nd approach seems easier if you pack that argument into
kwargsand end up doing
data = MyDataFeed(dataname=xxx, **kwargs). Thosekwargs
may contain other arguments likefromdate
Curtis Miller last edited by Curtis Miller
@backtrader This reply was helpful, and thank you for that! I've also been looking at your multiple series example as a reference. I figured out how to get all the series to plot together like in your example and I have a few questions.
- In the legend the plot produces only the last series is shown in the legend (in your example you only see d2; in mine, out of AAPL, GOOG, and MSFT, only MSFT appears in the legend). Is there some way to either show all series or suppress this aspect of the legend all together?
- The default statistics (
Cerebroinstance is created) gets cluttered, so I turned it off (that is, set
stdstats=False), then create my own
Brokerobserver, then add in the
BuySellobserver. What's strange is that, while you get an indication for every series when a buy or sell was made (that is, there is a plot for every series), I don't get this when I turn off
stdstatsand add in
BuySellmyself; it will work for the first data series, but not the rest. Why is this happening, and how can I fix it?
Also, check the formatting of your reply. :)
EDIT: I managed to fix the second problem I mentioned by putting
self._addobserver(True, bt.observers.BuySell)in the
__init__()method of my strategy (your source code suggested that could be done).
The actual documented way to do it:
The source code uses internal methods to do things which may break at any time.
See Docs - Cerebro and look for
addoservermulti(the reference is close to the end) It will add the observer as many times as data feeds are present in the system (with each observer in charge of the things happening on one data feed)