Type: | Package |
Title: | Tools for Analyzing Time Series Data of Just Finance and Econometrics |
Version: | 2.5.11 |
Date: | 2025-06-29 |
Author: | Ho Tsung-wu [aut, cre] |
Maintainer: | Ho Tsung-wu <tsungwu@ntnu.edu.tw> |
Description: | Offer procedures to download financial-economic time series data and enhanced procedures for computing the investment performance indices of Bacon (2004) <doi:10.1002/9781119206309>. |
License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
LazyData: | TRUE |
LazyLoad: | yes |
Depends: | R (≥ 3.5.0), xts |
Suggests: | car, dynlm, openxlsx, timeDate, timeSeries, zoo |
NeedsCompilation: | no |
Packaged: | 2025-06-29 03:48:32 UTC; badal |
Repository: | CRAN |
Date/Publication: | 2025-06-29 08:40:02 UTC |
Active Premium or Active Return
Description
The return on an investment's annualized return minus the benchmark's annualized return.
Usage
ActivePremium(Ra, Rb, scale = NA)
Arguments
Ra |
return vector of the portfolio |
Rb |
return vector of the benchmark asset |
scale |
number of periods in a year (daily scale = 252, monthly scale = 12, quarterly scale = 4) |
Details
Active Premium = Investment's annualized return - Benchmark's annualized return. With a view to speeding computation. I re-write the code of some ratios of the package PerformanceAnalytics, and use the same name for comparing the performance enhancing. Interested readers may compare speed improvement with the use of system.time().
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
References
Sharpe, W.F. The Sharpe Ratio,Journal of Portfolio Management, Fall 1994, 49-58.
See aslo package PerformanceAnalytics
.
See Also
Return.annualized
,
InformationRatio
,
TrackingError
,
Examples
data(assetReturns)
assetReturns=assetReturns["2015::2018"] #short sample for fast example
# Ra=assetReturns[, -29]
# Rb=assetReturns[,29] #DJI
# ActivePremium(Ra, Rb)
Adjusted Sharpe ratio of the return distribution
Description
Adjusted Sharpe ratio was introduced by Pezier and White (2006) to adjusts for skewness and kurtosis by incorporating a penalty factor for negative skewness and excess kurtosis.
Usage
AdjustedSharpeRatio(R, Rf = 0, FUN = "StdDev")
Arguments
R |
an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns |
Rf |
the risk free rate |
FUN |
one of "StdDev" or "VaR" or "ES" to use as the denominator for unadjusted Sharpe ratio, default="StdDev" |
Details
Adjusted Sharpe Ratio = SR * [1 + (\frac{S}{6}) * SR - (\frac{K - 3}{24}) * SR^2]
where SR
is the sharpe ratio with data annualized, S
is the skewness and K
is the kurtosis
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
References
Carl Bacon, Practical portfolio performance measurement
and attribution, second edition 2008 p.99.
Pezier, Jaques and White, Anthony. 2006. The Relative Merits of Investable
Hedge Fund Indices and of Funds of Hedge Funds in Optimal Passive Portfolios.
Check https://econpapers.repec.org/paper/rdgicmadp/icma-dp2006-10.htm
See also package PerformanceAnalytics
.
Examples
data(assetReturns)
AdjustedSharpeRatio(assetReturns)
Appraisal ratio of the return distribution
Description
Appraisal ratio is the Jensen's alpha adjusted for specific risk. The numerator is divided by specific risk instead of total risk.
Usage
AppraisalRatio(Ra, Rb, Rf = 0, method = c("appraisal", "modified",
"alternative"))
Arguments
Ra |
an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns |
Rb |
return vector of the benchmark asset |
Rf |
risk free rate, in same period as your returns |
method |
is one of "appraisal" to calculate appraisal ratio, "modified" to calculate modified Jensen's alpha or "alternative" to calculate alternative Jensen's alpha. |
Details
Modified Jensen's alpha is Jensen's alpha divided by beta.
Alternative Jensen's alpha is Jensen's alpha divided by systematic risk.
Appraisal ratio = \frac{\alpha}{\sigma_{\epsilon}}
Modified Jensen's alpha = \frac{\alpha}{\beta}
Alternative Jensen's alpha = \frac{\alpha}{\sigma_S}
where alpha
is the Jensen's alpha, \sigma_{epsilon}
is the specific risk,
\sigma_S
is the systematic risk.
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
References
Carl Bacon, Practical portfolio performance measurement
and attribution, second edition 2008 p.77.
See also package PerformanceAnalytics
.
Examples
data(assetReturns)
Ra=assetReturns[, -29]
Rb=assetReturns[,29] #DJI
AppraisalRatio(Ra, Rb, method="appraisal")
Bernardo and Ledoit ratio of the return distribution
Description
To calculate Bernardo and Ledoit ratio we take the sum of the subset of returns that are above 0 and we divide it by the opposite of the sum of the subset of returns that are below 0
Usage
BernardoLedoitRatio(R)
Arguments
R |
an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns |
Details
BernardoLedoitRatio(R) = \frac{\frac{1}{n}\sum^{n}_{t=1}{max(R_{t},0)}}{\frac{1}{n}\sum^{n}_{t=1}{max(-R_{t},0)}}
where n
is the number of observations of the entire series
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
References
Carl Bacon, Practical portfolio performance measurement
and attribution, second edition 2008 p.95.
See also package PerformanceAnalytics
.
Examples
data(assetReturns)
BernardoLedoitRatio(R=assetReturns)
Burke ratio of the return distribution
Description
To calculate Burke ratio we take the difference between the portfolio return and the risk free rate and we divide it by the square root of the sum of the square of the drawdowns. To calculate the modified Burke ratio we just multiply the Burke ratio by the square root of the number of datas.
Usage
BurkeRatio(R, Rf = 0, modified = FALSE)
Arguments
R |
an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns |
Rf |
the risk free rate |
modified |
a boolean to decide which ratio to calculate between Burke ratio and modified Burke ratio. |
Details
Burke Ratio = \frac{r_P - r_F}{\sqrt{\sum^{d}_{t=1}{D_t}^2}}
Modified Burke Ratio = \frac{r_P - r_F}{\sqrt{\sum^{d}_{t=1}\frac{{D_t}^2}{n}}}
where n
is the number of observations of the entire series, d
is number of drawdowns, r_P
is the portfolio return, r_F
is the risk free rate and D_t
the t^{th}
drawdown.
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
References
Carl Bacon, Practical portfolio performance measurement
and attribution, second edition 2008 p.90-91.
See aslo package PerformanceAnalytics
.
Examples
data(assetReturns)
assetReturns=assetReturns["2011::2018"] #short sample for fast example
BurkeRatio(assetReturns,Rf=0)
Jensen's alpha of the return distribution
Description
The Jensen's alpha is the intercept of the regression equation in the Capital Asset Pricing Model and is in effect the exess return adjusted for systematic risk.
Usage
CAPM.jensenAlpha(Ra, Rb, Rf = 0)
Arguments
Ra |
an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns |
Rb |
return vector of the benchmark asset |
Rf |
risk free rate, in same period as your returns |
Details
\alpha = r_p - r_f - \beta_p * (b - r_f)
where r_f
is the risk free rate, \beta_r
is the regression beta,
r_p
is the portfolio return and b is the benchmark return
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
References
Carl Bacon, Practical portfolio performance measurement
and attribution, second edition 2008 p.72
See also package PerformanceAnalytics
.
Examples
data(assetReturns)
assetReturns=assetReturns["2011::2018"] #short sample for fast example
Ra=assetReturns[, -29]
Rb=assetReturns[,29] #DJI
CAPM.jensenAlpha(Ra, Rb)
calculate a Calmar or Sterling reward/risk ratio
Calmar and Sterling Ratios are yet another method of creating a
risk-adjusted measure for ranking investments similar to the
SharpeRatio
.
Description
Both the Calmar and the Sterling ratio are the ratio of annualized return over the absolute value of the maximum drawdown of an investment. The Sterling ratio adds an excess risk measure to the maximum drawdown, traditionally and defaulting to 10%.
Usage
CalmarRatio(R, scale = NA)
SterlingRatio(R, scale = NA, excess = 0.1)
Arguments
R |
an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns |
scale |
number of periods in a year (daily scale = 252, monthly scale = 12, quarterly scale = 4) |
excess |
for Sterling Ratio, excess amount to add to the max drawdown, traditionally and default .1 (10%) |
Details
It is also traditional to use a three year return series for these calculations, although the functions included here make no effort to determine the length of your series. If you want to use a subset of your series, you'll need to truncate or subset the input data to the desired length.
Many other measures have been proposed to do similar reward to risk ranking.
It is the opinion of this author that newer measures such as Sortino's
SharpeRatio
are both “better” measures, and
should be preferred to the Calmar or Sterling Ratio.
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
References
Bacon, Carl. Practical Portfolio Performance Measurement
and Attribution. Wiley. 2004.
See also package PerformanceAnalytics
.
See Also
Return.annualized
,
maxDrawdown
,
Examples
data(assetReturns)
R=assetReturns[, -29]
# SterlingRatio(R)
d ratio of the return distribution
Description
The d ratio is similar to the Bernado Ledoit ratio but inverted and taking into account the frequency of positive and negative returns.
Usage
DRatio(R)
Arguments
R |
an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns |
Details
It has values between zero and infinity. It can be used to rank the performance of portfolios. The lower the d ratio the better the performance, a value of zero indicating there are no returns less than zero and a value of infinity indicating there are no returns greater than zero.
DRatio(R) = \frac{n_{d}*\sum^{n}_{t=1}{max(-R_{t},0)}}{n_{u}*\sum^{n}_{t=1}
{max(R_{t},0)}}
where n
is the number of observations of the entire series,
n_{d}
is the number of observations less than zero,
n_{u}
is the number of observations greater than zero
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
References
Carl Bacon, Practical portfolio performance measurement
and attribution, second edition 2008 p.95
See also package PerformanceAnalytics
.
Examples
data(assetReturns)
R=assetReturns[, -29]
DRatio(R)
downside risk (deviation, variance) of the return distribution
Description
Downside deviation, semideviation, and semivariance are measures of downside risk.
Usage
DownsideDeviation(R, MAR = 0, method = c("full", "subset"),potential = FALSE)
Arguments
R |
an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns |
MAR |
Minimum Acceptable Return, in the same periodicity as your returns |
method |
one of "full" or "subset", indicating whether to use the length of the full series or the length of the subset of the series below the MAR as the denominator, defaults to "full" |
potential |
if TRUE, calculate downside potential instead, default FALSE |
Details
Downside deviation, similar to semi deviation, eliminates positive returns when calculating risk. Instead of using the mean return or zero, it uses the Minimum Acceptable Return as proposed by Sharpe (which may be the mean historical return or zero). It measures the variability of underperformance below a minimum targer rate. The downside variance is the square of the downside potential.
To calculate it, we take the subset of returns that are less than the target (or Minimum Acceptable Returns (MAR)) returns and take the differences of those to the target. We sum the squares and divide by the total number of returns to get a below-target semi-variance.
DownsideDeviation(R , MAR) = \delta_{MAR} = \sqrt{\sum^{n}_{t=1}\frac{min[(R_{t} - MAR), 0]^2}{n}}
DownsideVariance(R, MAR) = \sum^{n}_{t=1}\frac{min[(R_{t} - MAR), 0]^2}{n}
DownsidePotential(R, MAR) = \sum^{n}_{t=1}\frac{min[(R_{t} - MAR), 0]} {n}
where n
is either the number of observations of the entire series or
the number of observations in the subset of the series falling below the
MAR.
SemiDeviation or SemiVariance is a popular alternative downside risk measure that may be used in place of standard deviation or variance. SemiDeviation and SemiVariance are implemented as a wrapper of DownsideDeviation with MAR=mean(R).
In many functions like Markowitz optimization, semideviation may be substituted directly, and the covariance matrix may be constructed from semideviation or the vector of returns below the mean rather than from variance or the full vector of returns.
In semideviation, by convention, the value of n
is set to the full
number of observations. In semivariance the the value of n
is set to
the subset of returns below the mean. It should be noted that while this is
the correct mathematical definition of semivariance, this result doesn't
make any sense if you are also going to be using the time series of returns
below the mean or below a MAR to construct a semi-covariance matrix for
portfolio optimization.
Sortino recommends calculating downside deviation utilizing a continuous fitted distribution rather than the discrete distribution of observations. This would have significant utility, especially in cases of a small number of observations. He recommends using a lognormal distribution, or a fitted distribution based on a relevant style index, to construct the returns below the MAR to increase the confidence in the final result. Hopefully, in the future, we'll add a fitted option to this function, and would be happy to accept a contribution of this nature.
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
References
Sortino, F. and Price, L. Performance Measurement in a Downside
Risk Framework. Journal of Investing. Fall 1994, 59-65.
Carl Bacon, Practical portfolio performance measurement and attribution,
second edition 2008
Plantinga, A., van der Meer, R. and Sortino, F. The Impact of Downside Risk
on Risk-Adjusted Performance of Mutual Funds in the Euronext Markets. July
19, 2001. Available at SSRN:https://papers.ssrn.com/sol3/papers.cfm?abstract_id=277352
see especially end note 10 https://en.wikipedia.org/wiki/Semivariance.
See also package PerformanceAnalytics
.
Examples
data(assetReturns)
assetReturns=assetReturns["2011::2018"] #short sample for fast example
R=assetReturns[, -29]
DownsideDeviation(R, MAR = 0)
Drawdawn peak of the return distribution
Description
Drawdawn peak is for each return its drawdown since the previous peak
Usage
DrawdownPeak(R)
Arguments
R |
an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns |
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
Examples
data(assetReturns)
R=assetReturns[, -29]
# Not run
# DrawdownPeak(R)
InformationRatio = ActivePremium/TrackingError
Description
The Active Premium divided by the Tracking Error.
Usage
InformationRatio(Ra, Rb, scale = NA)
Arguments
Ra |
an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns |
Rb |
return vector of the benchmark asset |
scale |
number of periods in a year (daily scale = 252, monthly scale = 12, quarterly scale = 4) |
Details
InformationRatio = ActivePremium/TrackingError
This relates the degree to which an investment has beaten the benchmark to the consistency with which the investment has beaten the benchmark.
Note
William Sharpe now recommends InformationRatio
preferentially
to the original SharpeRatio
.
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
References
Sharpe, W.F. The Sharpe Ratio,Journal of Portfolio
Management,Fall 1994, 49-58.
See also package PerformanceAnalytics
.
See Also
TrackingError
ActivePremium
SharpeRatio
Examples
data(assetReturns)
Ra=assetReturns[, -29]
Rb=assetReturns[,29] #DJI
InformationRatio(Ra, Rb)
calculate Kelly criterion ratio (leverage or bet size) for a strategy
Description
Kelly criterion ratio (leverage or bet size) for a strategy.
Usage
KellyRatio(R, Rf = 0)
Arguments
R |
a vector of returns to perform a mean over |
Rf |
risk free rate, in same period as your returns |
Details
The Kelly Criterion was identified by Bell Labs scientist John Kelly, and applied to blackjack and stock strategy sizing by Ed Thorpe.
The Kelly ratio can be simply stated as: “bet size is the ratio of edge over odds.” Mathematically, you are maximizing log-utility. As such, the Kelly criterion is equal to the expected excess return of the strategy divided by the expected variance of the excess return, or
leverage=\frac{(\overline{R}_{s}-R_{f})}{StdDev(R)^{2}}
As a performance metric, the Kelly Ratio is calculated retrospectively on a particular investment as a measure of the edge that investment has over the risk free rate. It may be use as a stack ranking method to compare investments in a manner similar to the various ratios related to the Sharpe ratio.
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
References
Thorp, Edward O. (1997; revised 1998). The Kelly Criterion in
Blackjack, Sports Betting, and the Stock Market.
See also package PerformanceAnalytics
.
Examples
data(assetReturns)
R=assetReturns[, -29]
KellyRatio(R, Rf=0)
M squared for Sortino of the return distribution
Description
M squared for Sortino is a M^2 calculated for Downside risk instead of Total Risk
Usage
M2Sortino(Ra, Rb, MAR = 0)
Arguments
Ra |
an xts, vector, matrix, data frame, timeSeries or zoo object of asset return |
Rb |
return vector of the benchmark asset |
MAR |
the minimum acceptable return |
Details
M^2_S = r_P + Sortino ratio * (\sigma_{DM} - \sigma_D)
where M^2_S
is MSquared for Sortino, r_P
is the annualised portfolio return,
\sigma_{DM}
is the benchmark annualised downside risk and D
is the portfolio
annualised downside risk
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
References
Carl Bacon, Practical portfolio performance measurement
and attribution, second edition 2008 p.102-103
See aslo package PerformanceAnalytics
.
Examples
data(assetReturns)
Ra=assetReturns[, -29]
Rb=assetReturns[,29] #DJI
M2Sortino(Ra, Rb, MAR=0)
Martin ratio of the return distribution
Description
To calculate Martin ratio we divide the difference of the portfolio return and the risk free rate by the Ulcer index
Usage
MartinRatio(R, Rf = 0)
Arguments
R |
an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns |
Rf |
risk free rate, in same period as your returns |
Details
Martin ratio = \frac{r_P - r_F}{\sqrt{\sum^{n}_{i=1} \frac{{D'_i}^2}{n}}}
where r_P
is the annualized portfolio return, r_F
is the risk free
rate, n
is the number of observations of the entire series, D'_i
is
the drawdown since previous peak in period i
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
References
Carl Bacon, Practical portfolio performance measurement
and attribution, second edition 2008 p.91
See also package PerformanceAnalytics
.
Examples
data(assetReturns)
R=assetReturns[, -29]
# Not run
# MartinRatio(R)
Mean absolute deviation of the return distribution
Description
To calculate Mean absolute deviation we take the sum of the absolute value of the difference between the returns and the mean of the returns and we divide it by the number of returns.
Usage
MeanAbsoluteDeviation(R)
Arguments
R |
an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns |
Details
MeanAbsoluteDeviation = \frac{\sum^{n}_{i=1}\mid r_i - \overline{r}\mid}{n}
where n
is the number of observations of the entire series, r_i
is the
return in month i and \overline{r}
is the mean return
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
References
Carl Bacon, Practical portfolio performance measurement
and attribution, second edition 2008 p.62.
See also package PerformanceAnalytics
.
Examples
data(assetReturns)
assetReturns=assetReturns["2011::2018"] #short sample for fast example
R=assetReturns[, -29]
MeanAbsoluteDeviation(R)
Omega-Sharpe ratio of the return distribution
Description
The Omega-Sharpe ratio is a conversion of the omega ratio to a ranking statistic in familiar form to the Sharpe ratio.
Usage
OmegaSharpeRatio(R, MAR = 0)
Arguments
R |
an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns |
MAR |
Minimum Acceptable Return, in the same periodicity as your returns |
Details
To calculate the Omega-Sharpe ration we subtract the target (or Minimum Acceptable Returns (MAR)) return from the portfolio return and we divide it by the opposite of the Downside Deviation.
OmegaSharpeRatio(R,MAR) = \frac{r_p - r_t}{\sum^n_{t=1}\frac{max(r_t - r_i, 0)}{n}}
where n
is the number of observations of the entire series
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
References
Carl Bacon, Practical portfolio performance measurement
and attribution, second edition 2008, p.95
See also package PerformanceAnalytics
.
Examples
data(assetReturns)
R=assetReturns[, -29]
OmegaSharpeRatio(R)
Pain index of the return distribution
Description
The pain index is the mean value of the drawdowns over the entire analysis period. The measure is similar to the Ulcer index except that the drawdowns are not squared. Also, it's different than the average drawdown, in that the numerator is the total number of observations rather than the number of drawdowns.
Usage
PainIndex(R)
Arguments
R |
an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns |
Details
Visually, the pain index is the area of the region that is enclosed by the horizontal line at zero percent and the drawdown line in the Drawdown chart.
Pain index = \sum^{n}_{i=1} \frac{\mid D'_i \mid}{n}
where n
is the number of observations of the entire series, D'_i
is
the drawdown since previous peak in period i
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
References
Carl Bacon, Practical portfolio performance measurement
and attribution, second edition 2008 p.89, Becker, Thomas (2006) Zephyr Associates
See also package PerformanceAnalytics
.
Examples
data(assetReturns)
R=assetReturns[, -29]
# Not run
# PainIndex(R)
Pain ratio of the return distribution
Description
To calculate Pain ratio we divide the difference of the portfolio return and the risk free rate by the Pain index
Usage
PainRatio(R, Rf = 0)
Arguments
R |
an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns |
Rf |
risk free rate, in same period as your returns |
Details
Pain ratio = \frac{r_P - r_F}{\sum^{n}_{i=1} \frac{\mid D'_i \mid}{n}}
where r_P
is the annualized portfolio return, r_F
is the risk free
rate, n
is the number of observations of the entire series, D'_i
is
the drawdown since previous peak in period i
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
References
Carl Bacon, Practical portfolio performance measurement
and attribution, second edition 2008 p.91
See also package PerformanceAnalytics
.
Examples
data(assetReturns)
assetReturns=assetReturns["2011::2018"] #short sample for fast example
R=assetReturns[, -29]
PainRatio(R)
Prospect ratio of the return distribution
Description
Prospect ratio is a ratio used to penalise loss since most people feel loss greater than gain
Usage
ProspectRatio(R, MAR)
Arguments
R |
an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns |
MAR |
the minimum acceptable return |
Details
ProspectRatio(R) = \frac{\frac{1}{n}*\sum^{n}_{i=1}(Max(r_i,0)+2.25*Min(r_i,0) - MAR)}{\sigma_D}
where n
is the number of observations of the entire series, MAR is the minimum acceptable return and \sigma_D
is the downside risk
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
References
Carl Bacon, Practical portfolio performance measurement
and attribution, second edition 2008 p.100
See also package PerformanceAnalytics
.
Examples
data(assetReturns)
R=assetReturns[, -29]
ProspectRatio(R, MAR=0)
calculate an annualized return for comparing instruments with different length history
Description
An average annualized return is convenient for comparing returns.
Usage
Return.annualized(R, scale = NA, geometric = TRUE)
Arguments
R |
an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns |
scale |
number of periods in a year (daily scale = 252, monthly scale = 12, quarterly scale = 4) |
geometric |
utilize geometric chaining (TRUE) or simple/arithmetic chaining (FALSE) to aggregate returns, default TRUE |
Details
Annualized returns are useful for comparing two assets. To do so, you must scale your observations to an annual scale by raising the compound return to the number of periods in a year, and taking the root to the number of total observations:
prod(1+R_{a})^{\frac{scale}{n}}-1=\sqrt[n]{prod(1+R_{a})^{scale}}-1
where scale is the number of periods in a year, and n is the total number of periods for which you have observations.
For simple returns (geometric=FALSE), the formula is:
\overline{R_{a}} \cdot scale
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
References
Bacon, Carl. Practical Portfolio Performance Measurement
and Attribution. Wiley. 2004. p. 6
See also package PerformanceAnalytics
.
Examples
data(assetReturns)
R=assetReturns[, -29]
Return.annualized(R)
calculate a traditional or modified Sharpe Ratio of Return over StdDev or VaR or ES
Description
The Sharpe ratio is simply the return per unit of risk (represented by variability). In the classic case, the unit of risk is the standard deviation of the returns.
Usage
SharpeRatio(R, Rf = 0, alpha = 0.05, FUN="StdDev",annualize=FALSE)
Arguments
R |
an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns |
Rf |
risk free rate, in same period as your returns |
alpha |
Tail probability for VaR or ES, default alpha=.05 |
FUN |
one of "StdDev" or "VaR" or "ES" to use as the denominator |
annualize |
if TRUE, annualize the measure, default FALSE |
Details
\frac{\overline{(R_{a}-R_{f})}}{\sqrt{\sigma_{(R_{a}-R_{f})}}}
William Sharpe now recommends InformationRatio
preferentially
to the original Sharpe Ratio.
The higher the Sharpe ratio, the better the combined performance of "risk" and return.
As noted, the traditional Sharpe Ratio is a risk-adjusted measure of return that uses standard deviation to represent risk.
A number of papers now recommend using a "modified Sharpe" ratio using a Modified Cornish-Fisher VaR or CVaR/Expected Shortfall as the measure of Risk.
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
References
Sharpe, W.F. The Sharpe Ratio,Journal of Portfolio
Management,Fall 1994, 49-58.
Laurent Favre and Jose-Antonio Galeano. Mean-Modified Value-at-Risk
Optimization with Hedge Funds. Journal of Alternative Investment, Fall 2002,
v 5.
See also package PerformanceAnalytics.
See Also
SharpeRatio.annualized
InformationRatio
TrackingError
ActivePremium
SortinoRatio
Examples
data(assetReturns)
R=assetReturns[, -29]
SharpeRatio(R)
calculate annualized Sharpe Ratio
Description
The Sharpe Ratio is a risk-adjusted measure of return that uses standard deviation to represent risk.
Usage
SharpeRatio.annualized(R, Rf = 0, alpha=0.05,scale = NA, geometric = TRUE, FUN = "StdDev")
Arguments
R |
an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns |
Rf |
risk free rate, in same period as your returns |
alpha |
Tail probability for VaR or ES, default alpha=.05 |
scale |
number of periods in a year (daily scale = 252, monthly scale = 12, quarterly scale = 4) |
geometric |
utilize geometric chaining (TRUE) or simple/arithmetic chaining (FALSE) to aggregate returns,default TRUE |
FUN |
one of "StdDev" or "VaR" or "ES" to use as the denominator, default="StdDev" |
Details
The Sharpe ratio is simply the return per unit of risk (represented by variance). The higher the Sharpe ratio, the better the combined performance of "risk" and return.
This function annualizes the number based on the scale parameter.
\frac{\sqrt[n]{prod(1+R_{a})^{scale}}-1}{\sqrt{scale}\cdot\sqrt{\sigma}}
Using an annualized Sharpe Ratio is useful for comparison of multiple return streams. The annualized Sharpe ratio is computed by dividing the annualized mean monthly excess return by the annualized monthly standard deviation of excess return.
William Sharpe now recommends Information Ratio preferentially to the original Sharpe Ratio.
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
References
Sharpe, W.F. The Sharpe Ratio,Journal of Portfolio
Management,Fall 1994, 49-58.
See also package PerformanceAnalytics
.
See Also
SharpeRatio
InformationRatio
TrackingError
ActivePremium
SortinoRatio
Examples
data(assetReturns)
R=assetReturns[, -29]
SharpeRatio.annualized(R)
Skewness-Kurtosis ratio of the return distribution
Description
Skewness-Kurtosis ratio is the division of Skewness by Kurtosis.
Usage
SkewnessKurtosisRatio(R)
Arguments
R |
an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns |
Details
It is used in conjunction with the Sharpe ratio to rank portfolios. The higher the rate the better.
SkewnessKurtosisRatio(R , MAR) = \frac{S}{K}
where S
is the skewness and K
is the Kurtosis
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
References
Carl Bacon, Practical portfolio performance measurement
and attribution, second edition 2008 p.100
See also package PerformanceAnalytics
.
Examples
data(assetReturns)
R=assetReturns[, -29]
SkewnessKurtosisRatio(R)
calculate Sortino Ratio of performance over downside risk
Description
Sortino proposed an improvement on the Sharpe Ratio to better account for skill and excess performance by using only downside semivariance as the measure of risk.
Usage
SortinoRatio(R, MAR = 0)
Arguments
R |
an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns |
MAR |
Minimum Acceptable Return, in the same periodicity as your returns |
Details
Sortino contends that risk should be measured in terms of not meeting the investment goal. This gives rise to the notion of “Minimum Acceptable Return” or MAR. All of Sortino's proposed measures include the MAR, and are more sensitive to downside or extreme risks than measures that use volatility(standard deviation of returns) as the measure of risk.
Choosing the MAR carefully is very important, especially when comparing disparate investment choices. If the MAR is too low, it will not adequately capture the risks that concern the investor, and if the MAR is too high, it will unfavorably portray what may otherwise be a sound investment. When comparing multiple investments, some papers recommend using the risk free rate as the MAR. Practitioners may wish to choose one MAR for consistency, several standardized MAR values for reporting a range of scenarios, or a MAR customized to the objective of the investor.
SortinoRatio=\frac{(\overline{R_{a} - MAR})}{\delta_{MAR}}
where
\delta_{MAR}
is the DownsideDeviation
.
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
References
Sortino, F. and Price, L. Performance Measurement in a Downside
Risk Framework. Journal of Investing. Fall 1994, 59-65.
See also package PerformanceAnalytics
.
See Also
SharpeRatio
DownsideDeviation
InformationRatio
Examples
data(assetReturns)
R=assetReturns[, -29]
SortinoRatio(R)
Calculate Tracking Error of returns against a benchmark
Description
A measure of the unexplained portion of performance relative to a benchmark.
Usage
TrackingError(Ra, Rb, scale = NA)
Arguments
Ra |
an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns |
Rb |
return vector of the benchmark asset |
scale |
number of periods in a year (daily scale = 252, monthly scale = 12, quarterly scale = 4) |
Details
Tracking error is calculated by taking the square root of the average of the squared deviations between the investment's returns and the benchmark's returns, then multiplying the result by the square root of the scale of the returns.
TrackingError =
\sqrt{\sum\frac{(R_{a}-R_{b})^{2}}{len(R_{a})\sqrt{scale}}}
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
References
Sharpe, W.F. The Sharpe Ratio,Journal of Portfolio
Management,Fall 1994, 49-58.
See also package PerformanceAnalytics
.
See Also
InformationRatio
TrackingError
Examples
data(assetReturns)
assetReturns=assetReturns["2011::2018"] #short sample for fast example
Ra=assetReturns[, -29]
Rb=assetReturns[,29] #DJI
TrackingError(Ra, Rb)
calculate Treynor Ratio or modified Treynor Ratio of excess return over CAPM beta
Description
The Treynor ratio is similar to the Sharpe Ratio, except it uses beta as the volatility measure (to divide the investment's excess return over the beta).
Usage
TreynorRatio(Ra, Rb, Rf = 0, scale = NA, modified = FALSE)
Arguments
Ra |
an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns |
Rb |
return vector of the benchmark asset |
Rf |
risk free rate, in same period as your returns |
scale |
number of periods in a year (daily scale = 252, monthly scale = 12, quarterly scale = 4) |
modified |
a boolean to decide whether to return the Treynor ratio or Modified Treynor ratio |
Details
To calculate modified Treynor ratio, we divide the numerator by the systematic risk instead of the beta.
Equation:
TreynorRatio = \frac{\overline{(R_{a}-R_{f})}}{\beta_{a,b}}
ModifiedTreynorRatio = \frac{r_p - r_f}{\sigma_s}
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
References
https://en.wikipedia.org/wiki/Treynor_ratio,
Carl Bacon, Practical portfolio performance measurement
and attribution, second edition 2008 p.77
See also package PerformanceAnalytics
.
See Also
Examples
data(assetReturns)
assetReturns=assetReturns["2011::2018"] #short sample for fast example
Ra=assetReturns[, -29]
Rb=assetReturns[,29] #DJI
TreynorRatio(Ra, Rb)
calculate the Ulcer Index
Description
Developed by Peter G. Martin in 1987 (Martin and McCann, 1987) and named for the worry caused to the portfolio manager or investor. This is similar to drawdown deviation except that the impact of the duration of drawdowns is incorporated by selecting the negative return for each period below the previous peak or high water mark. The impact of long, deep drawdowns will have significant impact because the underperformance since the last peak is squared.
Usage
UlcerIndex(R)
Arguments
R |
a vector, matrix, data frame, timeSeries or zoo object of asset returns |
Details
UI = sqrt(sum[i=1,2,...,n](D'_i^2/n)) where D'_i = drawdown since previous peak in period i
DETAILS: This approach is sensitive to the frequency of the time periods involved and penalizes managers that take time to recover to previous highs.
REFERENCES: Martin, P. and McCann, B. (1989) The investor's Guide to Fidelity Funds: Winning Strategies for Mutual Fund Investors. John Wiley & Sons, Inc.
See also package PerformanceAnalytics
.
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
Examples
data(assetReturns)
R=assetReturns[, -29]
maxDrawdown(R)
Volatility and variability of the return distribution
Description
Volatility skewness is a similar measure to omega but using the second partial moment. It's the ratio of the upside variance compared to the downside variance. Variability skewness is the ratio of the upside risk compared to the downside risk.
Usage
VolatilitySkewness(R, MAR = 0, stat = c("volatility", "variability"))
Arguments
R |
an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns |
MAR |
Minimum Acceptable Return, in the same periodicity as your returns |
stat |
one of "volatility", "variability" indicating whether to return the volatility skewness or the variability skweness |
Details
VolatilitySkewness(R , MAR) = \frac{\sigma_U^2}{\sigma_D^2}
VariabilitySkewness(R , MAR) = \frac{\sigma_U}{\sigma_D}
where \sigma_U
is the Upside risk and \sigma_D
is the Downside Risk
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
References
Carl Bacon, Practical portfolio performance measurement
and attribution, second edition 2008 p.97-98.
See also package PerformanceAnalytics.
Examples
data(assetReturns)
R=assetReturns[, -29]
VolatilitySkewness(R, MAR=0, stat="volatility")
Data Sets
Description
assetReturns contains DJ component stocks returns data. macrodata contains US unemployment(unrate) and year-to-year changes in three regional business cycle indices (OECD, NAFTA, and G7).
Usage
data(assetReturns)
data(macrodata)
Value
assetReturns is a time series object of package xts
.
macrodata is macroeconomic time series data.
calculate Sortino Ratio of performance over downside risk
Description
durbinH test the serial correlation of a dynamic regression, namely, a time series regression with AR(1) terms. It modifies Durbin-Watson statictic.
Usage
durbinH(model,Ly.label="ar1")
Arguments
model |
Estimation result object by, for example, dynlm or arima |
Ly.label |
Label of AR(1) dependent variable |
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
Examples
data(macrodata)
y=ts(macrodata[,"OECD"],start=c(1961,1),freq=12) #OECD business cycle index
out1=dynlm::dynlm(y~L(y,1)+season(y)+trend(y))
durbinH(out1,Ly.label="L(y, 1)")
Download effective exchange rates data frame from Bank of International Settlement
Description
It downloads effective exchange rates data frame from BIS.
Usage
getEER(Areas=c("US","JP"),Freq="Monthly", Type="Real",Basket="Broad")
Arguments
Areas |
The currency country of effective exchange rates (EER) of BIS, it allows many countries. The defaults are "US" and "JP". |
Freq |
The type of EER, it has two types: "Daily" and "Monthly". The default is "Monthly". "Daily" works only for "Nominal" of NEER. |
Type |
The type of EER, it has two types: "Nominal" and "Real". The default is "Real". |
Basket |
The basket of EER, it has two types: "Broad" and "Narrow". The default is "Broad". |
Details
This function connects with <"https://www.bis.org/statistics/eer/"> and downloads the specified data. The rownames of downloaded data embeds the timestamp already, which can be directly transformed into timeSeries
via, as.timeSeries.
Value
Retrieved BIS effective exchange rates time series, without any time series format.
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
Examples
#To save time, the example below is commented.
output=getEER(Areas=c("US","JP"),Freq="Monthly", Type="Real",Basket="Broad")
head(output)
Download financial and economic time series data from the Fed
Description
It downloads financial and economic time series data from the Fed.
Usage
getFed(var.name="UNRATE", freq="Monthly")
Arguments
var.name |
The name of variable as used by <"https://fred.stlouisfed.org">. For example, "UNRATE" denotes unemployment rate, "CPIAUCSL" is monthly consumer price index, "GDP" is Gross domestic product, and "ICSA" is the initial claim seasonally adjusted. User please check with the web for symbol. |
freq |
The time series frequency, match Fed label, for example,"Monthly","Quarterly". |
Details
This function connects with <"https://fred.stlouisfed.org"> and downloads the specified market data. The rownames of downloaded data is embedded by the timestamp already.
Value
Retrieved Fed time series data, but without any time series format.
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
Examples
#To save time, the example below is commented.
output=getFed(var.name="UNRATE", freq="Monthly")
head(output)
Download seven asset pricing factors data from the data library of Dr. French
Description
It downloads seven factors data used for asset pricing analysis from the data library of Dr. Kenneth R. French at Dartmouth College.
Usage
getFrench.Factors(filename="F-F_Research_Data_Factors")
Arguments
filename |
The name of data file as listed in <"http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/data_library.html">, which is an important database for asset pricing literature, this function supports seven factor files: |
Details
This function connects with <"http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/data_library.html"> and downloads the specified factors data. Sometimes, the datafile contains multiple data tables, hence the code returns a list. The website may occur somthing unexpected, for example, "F-F_Research_Data_Factors_weekly" is ill-formated hence the .csv data table cannot be retrieved. However, it was OK before. For this problem, we will not fix the code.
Value
ff.factor |
The data retrieved and arranged. |
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
Examples
getFrench.Factors()
Download 24 asset pricing factors data from the data library of Dr. French
Description
It downloads 24 factors data used for asset pricing analysis from the data library of Dr. Kenneth R. French at Dartmouth College.
Usage
getFrench.Portfolios(filename="Portfolios_Formed_on_ME")
Arguments
filename |
The name of portfolio data file as listed in (http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/data_library.html), the default is "Portfolios_Formed_on_ME". So far, this function supports retrieving 24 portfolio data files: |
Details
This function connects with <"http://mba.tuck.dartmouth.edu/pages/faculty/ken.french/data_library.html"> and downloads the specified portfolio data constructed by factors. Currently, we support on retriving and arranging 24 portfolio datasets. Sometimes, the datafile contains multiple data tables, hence the code returns a list. Since the csv spreedsheet on the web is not structured data table, it does not only contain irregular headings, but also 7, or more, data tablesr; and the trivial portfolio data tables labelled by "Portfolio Formed by ..." are omitted. Check the "table.names" of output object.
Value
data |
The data retrieved and arranged. |
table.names |
The names of data table. |
file.name |
The file name of portfolio data. |
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
Examples
#To save time, the example below is commented.
output=getFrench.Portfolios()
output$file.name
dim(output$data[[1]])
output$data
output$table.names
caclulate the maximum drawdown from peak equity
Description
To find the maximum drawdown in a return series, we need to first calculate the cumulative returns and the maximum cumulative return to that point. Any time the cumulative returns dips below the maximum cumulative returns, it's a drawdown. Drawdowns are measured as a percentage of that maximum cumulative return, in effect, measured from peak equity.
Usage
maxDrawdown(R, geometric = TRUE, invert = TRUE)
Arguments
R |
an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns |
geometric |
utilize geometric chaining (TRUE) or simple/arithmetic chaining (FALSE) to aggregate returns, default TRUE |
invert |
TRUE/FALSE whether to invert the drawdown measure. see Details. |
Details
The option to invert
the measure should appease both academics and
practitioners. The default option invert=TRUE
will provide the
drawdown as a positive number. This should be useful for optimization
(which usually seeks to minimize a value), and for tables (where having
negative signs in front of every number may be considered clutter).
Practitioners will argue that drawdowns denote losses, and should be
internally consistent with the quantile (a negative number), for which
invert=FALSE
will provide the value they expect. Individually,
different preferences may apply for clarity and compactness. As such, we
provide the option, but make no value judgment on which approach is
preferable.
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
References
Bacon, C. Practical Portfolio Performance Measurement and
Attribution. Wiley. 2004. p. 88
See also package PerformanceAnalytics
.
Examples
data(assetReturns)
R=assetReturns[, -29]
maxDrawdown(R)
Annualized Returns Summary: Statistics and Stylized Facts
Description
Table of Annualized Return, Annualized Std Dev, and Annualized Sharpe
Usage
table.AnnualizedReturns(R, scale = NA, Rf = 0, geometric = TRUE,
digits = 4)
Arguments
R |
an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns |
scale |
number of periods in a year (daily scale = 252, monthly scale = 12, quarterly scale = 4) |
Rf |
risk free rate, in same period as your returns |
geometric |
utilize geometric chaining (TRUE) or simple/arithmetic chaining (FALSE) to aggregate returns, default TRUE |
digits |
number of digits to round results to |
Author(s)
Ho Tsung-wu <tsungwu@ntnu.edu.tw>, College of Management, National Taiwan Normal University.
See Also
Return.annualized
SharpeRatio.annualized
Examples
data(assetReturns)
Ra=assetReturns[, -29]
table.AnnualizedReturns(R=Ra)