gs_quant.timeseries.econometrics.sharpe_ratio¶
- sharpe_ratio(series, currency=RiskFreeRateCurrency.USD, w=None, curve_type=CurveType.PRICES, method=Interpolate.NAN)[source]¶
Calculate Sharpe ratio
- Parameters:
series (
Series
) – series of prices or excess returns for an assetcurrency (
RiskFreeRateCurrency
) – currency for risk-free rate, defaults to USDw (
Union
[Window
,int
,str
,None
]) – Window or int: size of window and ramp up to use. e.g. Window(22, 10) where 22 is the window size and 10 the ramp up value. If w is a string, it should be a relative date like ‘1m’, ‘1d’, etc. Window size defaults to length of series.curve_type (
CurveType
) – whether input series is of prices or excess returns, defaults to pricesmethod (
Interpolate
) – interpolation method (default: nan). Used to calculate returns on dates without data (i.e. weekends) when window is a relative date. Defaults to no interpolation.
- Return type:
Series
- Returns:
Sharpe ratio
Usage
Given a price series P, risk-free rate R, and window of size w returns the rolling Sharpe ratio S:
\(S_t = \frac{(E_t / E_{t-w+1})^{365.25 / (D_t - D_{t-w})}-1}{volatility(E, w)_t}\)
Excess returns E are defined as:
\(E_t = E_{t-1} + P_t - P_{t-1} * (1 + R * (D_t - D_{t-1}) / 360)\)
where D is the date for a data point. The Actual/360 day count convention is used.
Examples
Get rolling sharpe ratio of a price series (with window of 22).
>>> sr = sharpe_ratio(generate_series(365, END_TODAY), USD, 22, PRICES)
See also