calc_sharpe: Calculate the Sharpe and Sortino ratios of a time series of...

View source: R/rutils.R

calc_sharpeR Documentation

Calculate the Sharpe and Sortino ratios of a time series of returns.

Description

Calculate the Sharpe and Sortino ratios of a time series of returns.

Usage

calc_sharpe(retp, riskf = 0, nperiods = 252)

Arguments

retp

A time series of returns, with multiple columns.

riskf

The annual risk-free interest rate (the default is 0).

nperiods

The number of time periods in a year (the default is 252 days).

Details

The function calc_sharpe() calculates the Sharpe and Sortino ratios of a time series of returns.

The function calc_sharpe() performs an sapply() loop over the columns of the retp argument. It calculates the Sharpe and Sortino ratios for each column. It subtracts from retp the annual risk-free interest rate riskf divided by nperiods. It multiplies the Sharpe and Sortino ratios by the square root of nperiods, in order to obtain the annual ratios.

The Sharpe ratio S_r is defined as:

S_r = \sqrt{n} \frac{\bar{r}}{\sigma_r}

Where r are the daily excess returns (the returns minus the risk-free rate), \bar{r} are the average excess returns, and \sigma_r is their daily standard deviation.

The Sortino ratio {So}_r is defined as:

{So}_r = \sqrt{n} \frac{\bar{r}}{\sigma_d}

Where r are the daily excess returns (the returns minus the risk-free rate), \bar{r} are the average excess returns, and \sigma_d is their daily downside deviation. The downside deviation \sigma_d is equal to the standard deviation of the downside returns r_d, the returns that are less than the risk-free rate.

Value

A matrix of the Sharpe and Sortino ratios.

Examples

# Calculate the Sharpe and Sortino ratios of VTI and IEF returns
rutils::calc_sharpe(rutils::etfenv$returns[, c("VTI", "IEF")])

algoquant/rutils documentation built on June 10, 2025, 3:55 p.m.