calculate_rolling_sharpe#

API documentation for tradeexecutor.visual.equity_curve.calculate_rolling_sharpe Python function.

calculate_rolling_sharpe(returns, freq='D', periods=90)[source]#

Calculate rolling Sharpe ration.

Explanation how to interpret rolling sharpe from QuantStrat:

It can be seen that the strategy had a significant upward period in 2013 which gives rise to a high trailing annualised Sharpe of 2.5, exceeding 3.5 by the start of 2014. However the strategy performance remained flat through 2014, which caused a gradual reduction in the annualised rolling Sharpe since the volatility of returns was largely similar. By the start of 2015 the Sharpe was between 0.5 and 1.0, meaning more risk was being taken per unit of return at this stage. By the end of 2015 the Sharpe had risen slightly to around 1.5, largely due to some consistent upward gains in the latter half of 2015.

Example:

import plotly.express as px

from tradeexecutor.visual.equity_curve import calculate_rolling_sharpe

rolling_sharpe = calculate_rolling_sharpe(
    returns,
    freq="D",
    periods=180,
)

fig = px.line(rolling_sharpe, title='Strategy rolling Sharpe (6 months)')
fig.update_layout(showlegend=False)
fig.update_yaxes(title="Sharpe")
fig.update_xaxes(title="Time")
fig.show()
Parameters:
  • returns (Series) – Returns series with rolling sharpe

  • freq (pandas._libs.tslibs.offsets.DateOffset | str | None) – Returns binning frequency for Sharpe calculations

  • periods – How many periods of data we sample for rolling sharpe.

Return type:

Series