sigmaquant.performance.metrics.sharpe_ratio#

sigmaquant.performance.metrics.sharpe_ratio(
returns,
frequency,
annualize=True,
risk_free=0.0,
)#

Compute the Sharpe ratio for a series of periodic returns.

If annualize is True, the Sharpe ratio is annualized by multiplying the non-annualized estimate by the square root of the number of periods per year implied by frequency.

Parameters:
  • returns (iterable of float) – Sequence of periodic portfolio returns.

  • frequency

    Frequency of the returns:
    • "D": daily

    • "W": weekly

    • "M": monthly

    • "Y": yearly

  • annualize (bool) – If True, the Sharpe ratio is scaled to annual frequency.

  • risk_free (float) – Risk-free rate per period, expressed at the same frequency as returns.

Returns:

Estimated Sharpe ratio.

Return type:

float

Notes

  • Missing values (NaN) are excluded from the computation.

Let \(r_t\) denote the periodic portfolio returns and \(r_f\) the per-period risk-free rate.

Define the sample mean excess return as:

\[\bar{r}_e = \frac{1}{T} \sum_{t=1}^{T} (r_t - r_f)\]

and the sample standard deviation of excess returns as:

\[s_e = \sqrt{ \frac{1}{T - 1} \sum_{t=1}^{T} \left( (r_t - r_f) - \bar{r}_e \right)^2 }\]

The (non-annualized) Sharpe ratio estimator is:

\[\widehat{\text{Sharpe}} = \frac{\bar{r}_e}{s_e}\]

If annualize=True, the estimator is scaled as:

\[\widehat{\text{Sharpe}}_{ann} = \sqrt{N} \frac{\bar{r}_e}{s_e}\]

where \(N\) is the number of periods per year implied by frequency.