Preventing subplots
-
Hello,
I am interested in having separate plots for equity line and drawdown lines. How does one go about doing this?
I have setcerebro = bt.Cerebro(stdstats=False)
and then added an observer for drawdown like this:
cerebro.addobserver(bt.observers.DrawDown,plot=True, subplot=False)
butcerebro.plot()
only plots datafeed and the indicators.(i.e. doesn't plot newly added drawdown observer). -
@emin-ozkan said in Preventing subplots:
I am interested in having separate plots for equity line and drawdown lines
Don't really know what you mean. The "equity line" (known as "value" in backtrader) is not plotted in the same subplot as the `DrawDown´ observer (for starters, the latter is not part of the standard observers included in a non-customized plot)
They do for sure plot separately.
@emin-ozkan said in Preventing subplots:
cerebro.addobserver(bt.observers.DrawDown,plot=True, subplot=False)
This seems like a strange move. Why would you plot the
DrawDown
observer along with the data feed? The values are completely unrelated and the values of the observer are possible the chart, but cannot be seen due to the huge difference with the data.Because you don't show a chart (strange since you talk about charting), the bet is that the label for the
DrawDown
is there in the subplot of the data. -
I am sorry that I wasn't clear. I have attached an image to see what I get currently:
What I want to get is
.
I think this is called Broker observer? But the relevant part is I want an observer such as Value or Broker in its own independent plot without including datafeed and indicators etc. (rather than a subplot). Is this possible? Thanks, -
A
subplot
is a different plot within a figure (a chart) and not an independent figure (chart).You are looking for a tear sheet, which implements independent figures (charts).
No, that's not implemented. The implemented charting facility is a meant as visual aid and not as a reporting tool.
You may try disabling the plotting of the data feed with
plotinfo=False
and see what happens (unknown if someone has tried that and succeeded) -
@backtrader Thanks actually I got what I need by adding
plot=False
to datafeed and the indicators. -
Here is another way to plot an independent equity curve based on bokeh. I apologize for shitty code. This way, I don't have to turn off cerebro's built in
pretty plotting such as buysell observers.cerebro.run() # This assumes that you have added a strategy # the value observer plot_observer(cerebro.runstrats[0][0]) from mpl_toolkits.mplot3d import axes3d import matplotlib.pyplot as plt from matplotlib import cm import numpy as np from matplotlib.ticker import LinearLocator, FormatStrFormatter from matplotlib.dates import num2date import seaborn as sns from bokeh.io import show from bokeh.layouts import column from bokeh.models import ColumnDataSource, RangeTool from bokeh.plotting import figure, output_file def plot_observer(strategy,alias='value'): for observer in strategy.getobservers(): linealias = observer.lines._getlinealias(0) if linealias ==alias: dates = np.array(strategy.datetime.plot()) ydata = np.array(observer.line.plot()) dates = num2date(dates) plot_bokeh(dates=dates,values=ydata) return def plot_bokeh(dates,values): output_file("equity.html", title="equity line") TOOLS = "pan,wheel_zoom,box_zoom,reset,save" source = ColumnDataSource(data=dict(date=dates, value=values)) p = figure(plot_height=300, plot_width=600, tools=TOOLS, x_axis_type="datetime", x_axis_location="above", background_fill_color="#efefef", x_range=(dates[0], dates[-1])) p.line('date', 'value', source=source) p.yaxis.axis_label = 'value' select = figure(title="Drag the middle and edges of the selection box to change the range above", plot_height=130, plot_width=600, y_range=p.y_range, x_axis_type="datetime", y_axis_type=None, tools="", toolbar_location=None, background_fill_color="#efefef") range_rool = RangeTool(x_range=p.x_range) range_rool.overlay.fill_color = "navy" range_rool.overlay.fill_alpha = 0.2 select.line('date', 'value', source=source) select.ygrid.grid_line_color = None select.add_tools(range_rool) select.toolbar.active_multi = range_rool show(column(p, select))