calc_sharpe | R Documentation |
Calculate the Sharpe and Sortino ratios of a time series of returns.
calc_sharpe(retp, riskf = 0, nperiods = 252)
retp |
A time series of returns, with multiple columns. |
riskf |
The annual risk-free interest rate (the default is
|
nperiods |
The number of time periods in a year (the default is
|
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.
A matrix of the Sharpe and Sortino ratios.
# Calculate the Sharpe and Sortino ratios of VTI and IEF returns
rutils::calc_sharpe(rutils::etfenv$returns[, c("VTI", "IEF")])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.