Skip to content

plot_rolling_sharpe


function backtide.analysis.rolling_sharpe.plot_rolling_sharpe(runs, window=60, periods_per_year=252, title=None, legend="upper left", figsize=(900, 600), filename=None, display=True)[source]

Create a rolling Sharpe-ratio chart for one or more strategy runs.

Each line plots the Sharpe ratio over a trailing window of samples, annualized by periods_per_year. Useful to spot when a strategy's risk-adjusted edge erodes or strengthens over time.

Parameters

runs : RunResult | list[RunResult]

The per-strategy results to plot.

window : int, default=60
Number of samples used in the trailing window.

periods_per_year : int, default=252
Annualization factor (number of periods/bars per year). Use 252 for daily intervals (or 365 for crypto) and 52 for weekly.

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

legend : str | dict | None, default="upper 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_pnl

Create a PnL-over-time chart for one or more strategy runs.

plot_rolling_returns

Create a rolling-return chart for one or more strategy runs.

RunResult

Result of running a single strategy as part of an experiment.


Example

>>> from backtide.analysis import plot_rolling_sharpe
>>> from backtide.storage import query_experiments, query_strategy_runs

>>> exp = query_experiments().iloc[0]
>>> runs = query_strategy_runs(exp.id)
>>> plot_rolling_sharpe(runs, window=90)