Skip to content

plot_drawdown


function backtide.analysis.drawdown.plot_drawdown(data, price_col="close", title=None, legend="lower left", figsize=(900, 600), filename=None, display=True)[source]

Create a drawdown chart.

Plots the percentage drawdown from the running peak over time for one or more symbols. Drawdown measures the decline from a historical peak in price and is a key risk metric.

Parameters

data : pd.DataFrame | pl.DataFrame

Input data containing columns symbol, the column specified by price_col, and dt with the datetime.

price_col : str, default="close"
Column name used to compute the drawdown.

title : str | dict | None, default=None
Title for the plot.

legend : str | dict | None, default="lower left"
Legend for the plot. See the user guide for an extended description of the choices.

  • If None: No legend is shown.
  • If str: Position to display the legend.
  • If dict: Legend configuration.

figsize : tuple[int, int], default=(900, 600)
Figure's size in pixels, format as (x, y).

filename : str | Path | None, default=None
Save the plot using this name. The type of the file depends on the provided name (.html, .png, .pdf, etc...). If filename has no file type, the plot is saved as .html. If None, the plot isn't saved.

display : bool | None, default=True
Whether to render the plot. If None, it returns the figure.

Returns

Figure | None

The Plotly figure object. Only returned if display=None.


See Also

plot_correlation

Create a correlation heatmap.

plot_price

Create a price line chart.

plot_returns

Create a returns distribution histogram.


Example

>>> from backtide.storage import query_bars
>>> from backtide.analysis import plot_drawdown

>>> df = query_bars(["AAPL", "MSFT"], "1d")
>>> plot_drawdown(df, legend="lower right")