sortino

Defined in fynance.metrics

sortino(X, rf=0, period=252, log=False, axis=0, dtype=None, ddof=0)[source]

Compute the Sortino ratio for each X’ series.

Annualized excess return per unit of downside volatility. Unlike the Sharpe ratio (sharpe), only negative returns contribute to the denominator, so strategies that generate frequent large gains are not penalized for their upside variance.

Parameters:
Xnp.ndarray[dtype, ndim=1 or 2]

Time-series of prices, performances or index.

rffloat, optional

Annualized risk-free rate. Default is 0.

periodint, optional

Number of periods per year. Default is 252 (trading days).

logbool, optional

If True, compute returns as log-returns. Default is False.

axis{0, 1}, optional

Axis along which the computation is done. Default is 0.

dtypenp.dtype, optional

Output array dtype. Inferred from X if not given.

ddofint, optional

Delta Degrees of Freedom. Default is 0.

Returns:
dtype or np.ndarray[dtype, ndim=1]

Sortino ratio for each series. Returns inf when downside volatility is zero (all returns are non-negative).

See also

sharpe, calmar, mdd

Notes

The Sortino ratio is computed as the annualized expected return minus the risk-free rate divided by the annualized downside deviation:

\[sortinoRatio = \frac{E(R) - rf}{\sqrt{period \times Var(R^{-})}}\]

where \(R^{-}_t = \min(R_t, 0)\) and \(R\) is defined as for sharpe.

Examples

Assume a series X of monthly prices:

>>> X = np.array([70, 100, 80, 120, 160, 80]).astype(np.float64)
>>> sortino(X, period=12)
0.4742428587192754
>>> sortino(X.reshape([6, 1]), period=12)
array([0.47424286])