[Returnanalytics-commits] r2250 - in pkg/PerformanceAnalytics: R inst/doc man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Aug 19 18:44:29 CEST 2012


Author: matthieu_lestel
Date: 2012-08-19 18:44:29 +0200 (Sun, 19 Aug 2012)
New Revision: 2250

Added:
   pkg/PerformanceAnalytics/inst/doc/PA-Bacon.Rnw
   pkg/PerformanceAnalytics/inst/doc/PA-Bacon.pdf
Modified:
   pkg/PerformanceAnalytics/R/AdjustedSharpeRatio.R
   pkg/PerformanceAnalytics/R/AppraisalRatio.R
   pkg/PerformanceAnalytics/R/DownsideDeviation.R
   pkg/PerformanceAnalytics/R/FamaBeta.R
   pkg/PerformanceAnalytics/R/MeanAbsoluteDeviation.R
   pkg/PerformanceAnalytics/R/NetSelectivity.R
   pkg/PerformanceAnalytics/R/OmegaSharpeRatio.R
   pkg/PerformanceAnalytics/R/PainIndex.R
   pkg/PerformanceAnalytics/R/ProspectRatio.R
   pkg/PerformanceAnalytics/R/Selectivity.R
   pkg/PerformanceAnalytics/R/SkewnessKurtosisRatio.R
   pkg/PerformanceAnalytics/R/TotalRisk.R
   pkg/PerformanceAnalytics/R/UpsideRisk.R
   pkg/PerformanceAnalytics/man/AdjustedSharpeRatio.Rd
   pkg/PerformanceAnalytics/man/AppraisalRatio.Rd
   pkg/PerformanceAnalytics/man/DownsideDeviation.Rd
   pkg/PerformanceAnalytics/man/FamaBeta.Rd
   pkg/PerformanceAnalytics/man/MeanAbsoluteDeviation.Rd
   pkg/PerformanceAnalytics/man/NetSelectivity.Rd
   pkg/PerformanceAnalytics/man/OmegaSharpeRatio.Rd
   pkg/PerformanceAnalytics/man/PainIndex.Rd
   pkg/PerformanceAnalytics/man/ProspectRatio.Rd
   pkg/PerformanceAnalytics/man/Selectivity.Rd
   pkg/PerformanceAnalytics/man/SkewnessKurtosisRatio.Rd
   pkg/PerformanceAnalytics/man/TotalRisk.Rd
   pkg/PerformanceAnalytics/man/UpsideRisk.Rd
Log:
little corrections in documentation + additon of vignette on Bacon

Modified: pkg/PerformanceAnalytics/R/AdjustedSharpeRatio.R
===================================================================
--- pkg/PerformanceAnalytics/R/AdjustedSharpeRatio.R	2012-08-19 15:52:39 UTC (rev 2249)
+++ pkg/PerformanceAnalytics/R/AdjustedSharpeRatio.R	2012-08-19 16:44:29 UTC (rev 2250)
@@ -20,7 +20,7 @@
 #' @keywords ts multivariate distribution models
 #' @examples
 #' data(portfolio_bacon)
-#' print(AdjustedSharpeRatio(portfolio_bacon[,1])) #expected 0.813
+#' print(AdjustedSharpeRatio(portfolio_bacon[,1])) #expected 0.81
 #'
 #' data(managers)
 #' print(AdjustedSharpeRatio(managers['1996']))

Modified: pkg/PerformanceAnalytics/R/AppraisalRatio.R
===================================================================
--- pkg/PerformanceAnalytics/R/AppraisalRatio.R	2012-08-19 15:52:39 UTC (rev 2249)
+++ pkg/PerformanceAnalytics/R/AppraisalRatio.R	2012-08-19 16:44:29 UTC (rev 2250)
@@ -33,7 +33,7 @@
 #' @examples
 #'
 #' data(portfolio_bacon)
-#' print(AppraisalRatio(portfolio_bacon[,1], portfolio_bacon[,2], method="appraisal")) #expected -0.375
+#' print(AppraisalRatio(portfolio_bacon[,1], portfolio_bacon[,2], method="appraisal")) #expected -0.430
 #' print(AppraisalRatio(portfolio_bacon[,1], portfolio_bacon[,2], method="modified")) 
 #' print(AppraisalRatio(portfolio_bacon[,1], portfolio_bacon[,2], method="alternative"))
 #'

Modified: pkg/PerformanceAnalytics/R/DownsideDeviation.R
===================================================================
--- pkg/PerformanceAnalytics/R/DownsideDeviation.R	2012-08-19 15:52:39 UTC (rev 2249)
+++ pkg/PerformanceAnalytics/R/DownsideDeviation.R	2012-08-19 16:44:29 UTC (rev 2250)
@@ -84,8 +84,8 @@
 #'
 #' data(portfolio_bacon)
 #' MAR = 0.5
-#' DownsideDeviation(portfolio_bacon, MAR) #expected 2.55
-#' DownsidePotential(portfolio_bacon, MAR) #expected 1.37
+#' DownsideDeviation(portfolio_bacon[,1], MAR) #expected 0.493
+#' DownsidePotential(portfolio_bacon[,1], MAR) #expected 0.491
 #' 
 #' #with data of managers
 #'

Modified: pkg/PerformanceAnalytics/R/FamaBeta.R
===================================================================
--- pkg/PerformanceAnalytics/R/FamaBeta.R	2012-08-19 15:52:39 UTC (rev 2249)
+++ pkg/PerformanceAnalytics/R/FamaBeta.R	2012-08-19 16:44:29 UTC (rev 2250)
@@ -1,6 +1,6 @@
 #' Fama beta of the return distribution
 #'
-#' Fama beta is a beta used to calculate the loss of diversification. It is made so
+#' Fama beta is a beta used to calculate the loss of diversification. It is made
 #' so that the systematic risk is equivalent to the total portfolio risk.
 #'
 #' \deqn{\beta_F = \frac{\sigma_P}{\sigma_M}}{Fama beta = portfolio standard deviation / benchmark standard deviation}

Modified: pkg/PerformanceAnalytics/R/MeanAbsoluteDeviation.R
===================================================================
--- pkg/PerformanceAnalytics/R/MeanAbsoluteDeviation.R	2012-08-19 15:52:39 UTC (rev 2249)
+++ pkg/PerformanceAnalytics/R/MeanAbsoluteDeviation.R	2012-08-19 16:44:29 UTC (rev 2250)
@@ -18,7 +18,7 @@
 #' @keywords ts multivariate distribution models
 #' @examples
 #' data(portfolio_bacon)
-#' print(MeanAbsoluteDeviation(portfolio_bacon)) #expected 1.78
+#' print(MeanAbsoluteDeviation(portfolio_bacon[,1])) #expected 0.0310
 #'
 #' data(managers)
 #' print(MeanAbsoluteDeviation(managers['1996']))

Modified: pkg/PerformanceAnalytics/R/NetSelectivity.R
===================================================================
--- pkg/PerformanceAnalytics/R/NetSelectivity.R	2012-08-19 15:52:39 UTC (rev 2249)
+++ pkg/PerformanceAnalytics/R/NetSelectivity.R	2012-08-19 16:44:29 UTC (rev 2250)
@@ -24,7 +24,7 @@
 #' @examples
 #'
 #' data(portfolio_bacon)
-#' print(NetSelectivity(portfolio_bacon[,1], portfolio_bacon[,2])) #expected -1.41
+#' print(NetSelectivity(portfolio_bacon[,1], portfolio_bacon[,2])) #expected -0.017
 #'
 #' data(managers)
 #' print(NetSelectivity(managers['1996',1], managers['1996',8]))

Modified: pkg/PerformanceAnalytics/R/OmegaSharpeRatio.R
===================================================================
--- pkg/PerformanceAnalytics/R/OmegaSharpeRatio.R	2012-08-19 15:52:39 UTC (rev 2249)
+++ pkg/PerformanceAnalytics/R/OmegaSharpeRatio.R	2012-08-19 16:44:29 UTC (rev 2250)
@@ -1,6 +1,6 @@
 #' Omega-Sharpe ratio of the return distribution
 #'
-#' The omega ratio is a conversion of the omega ratio to a ranking statistic 
+#' The Omega-Sharpe ratio is a conversion of the omega ratio to a ranking statistic 
 #' in familiar form to the Sharpe ratio.
 #'
 #' To calculate the Omega-Sharpe ration we subtract the target (or Minimum

Modified: pkg/PerformanceAnalytics/R/PainIndex.R
===================================================================
--- pkg/PerformanceAnalytics/R/PainIndex.R	2012-08-19 15:52:39 UTC (rev 2249)
+++ pkg/PerformanceAnalytics/R/PainIndex.R	2012-08-19 16:44:29 UTC (rev 2250)
@@ -26,7 +26,7 @@
 #' @keywords ts multivariate distribution models
 #' @examples
 #' data(portfolio_bacon)
-#' print(PainIndex(portfolio_bacon[,1])) #expected 4.0
+#' print(PainIndex(portfolio_bacon[,1])) #expected 0.04
 #'
 #' data(managers)
 #' print(PainIndex(100*managers['1996']))

Modified: pkg/PerformanceAnalytics/R/ProspectRatio.R
===================================================================
--- pkg/PerformanceAnalytics/R/ProspectRatio.R	2012-08-19 15:52:39 UTC (rev 2249)
+++ pkg/PerformanceAnalytics/R/ProspectRatio.R	2012-08-19 16:44:29 UTC (rev 2250)
@@ -20,7 +20,7 @@
 #' @examples
 #' data(portfolio_bacon)
 #' MAR = 0.05
-#' print(ProspectRatio(portfolio_bacon[,1], MAR)) #expected -0.221
+#' print(ProspectRatio(portfolio_bacon[,1], MAR)) #expected -0.134
 #'
 #' data(managers)
 #' MAR = 0

Modified: pkg/PerformanceAnalytics/R/Selectivity.R
===================================================================
--- pkg/PerformanceAnalytics/R/Selectivity.R	2012-08-19 15:52:39 UTC (rev 2249)
+++ pkg/PerformanceAnalytics/R/Selectivity.R	2012-08-19 16:44:29 UTC (rev 2250)
@@ -21,7 +21,7 @@
 #' @examples
 #'
 #' data(portfolio_bacon)
-#' print(Selectivity(portfolio_bacon[,1], portfolio_bacon[,2])) #expected -1.41
+#' print(Selectivity(portfolio_bacon[,1], portfolio_bacon[,2])) #expected -0.0141
 #'
 #' data(managers)
 #' print(Selectivity(managers['1996',1], managers['1996',8]))

Modified: pkg/PerformanceAnalytics/R/SkewnessKurtosisRatio.R
===================================================================
--- pkg/PerformanceAnalytics/R/SkewnessKurtosisRatio.R	2012-08-19 15:52:39 UTC (rev 2249)
+++ pkg/PerformanceAnalytics/R/SkewnessKurtosisRatio.R	2012-08-19 16:44:29 UTC (rev 2250)
@@ -21,7 +21,7 @@
 #' @examples
 #'
 #' data(portfolio_bacon)
-#' print(SkewnessKurtosisRatio(portfolio_bacon[,1])) #expected -0.0318
+#' print(SkewnessKurtosisRatio(portfolio_bacon[,1])) #expected -0.034
 #'
 #' data(managers)
 #' print(SkewnessKurtosisRatio(managers['1996']))

Modified: pkg/PerformanceAnalytics/R/TotalRisk.R
===================================================================
--- pkg/PerformanceAnalytics/R/TotalRisk.R	2012-08-19 15:52:39 UTC (rev 2249)
+++ pkg/PerformanceAnalytics/R/TotalRisk.R	2012-08-19 16:44:29 UTC (rev 2250)
@@ -20,7 +20,7 @@
 #' @examples
 #'
 #' data(portfolio_bacon)
-#' print(TotalRisk(portfolio_bacon[,1], portfolio_bacon[,2])) #expected 13.4
+#' print(TotalRisk(portfolio_bacon[,1], portfolio_bacon[,2])) #expected 0.0134
 #'
 #' data(managers)
 #' print(TotalRisk(managers['1996',1], managers['1996',8]))

Modified: pkg/PerformanceAnalytics/R/UpsideRisk.R
===================================================================
--- pkg/PerformanceAnalytics/R/UpsideRisk.R	2012-08-19 15:52:39 UTC (rev 2249)
+++ pkg/PerformanceAnalytics/R/UpsideRisk.R	2012-08-19 16:44:29 UTC (rev 2250)
@@ -40,9 +40,9 @@
 #'
 #' data(portfolio_bacon)
 #' MAR = 0.005
-#' print(UpsideRisk(portfolio_bacon[,1], MAR, stat="risk")) #expected 2.937
-#' print(UpsideRisk(portfolio_bacon[,1], MAR, stat="variance")) #expected 8.628
-#' print(UpsideRisk(portfolio_bacon[,1], MAR, stat="potential")) #expected 1.771
+#' print(UpsideRisk(portfolio_bacon[,1], MAR, stat="risk")) #expected 0.02937
+#' print(UpsideRisk(portfolio_bacon[,1], MAR, stat="variance")) #expected 0.08628
+#' print(UpsideRisk(portfolio_bacon[,1], MAR, stat="potential")) #expected 0.01771
 #'
 #' MAR = 0
 #' data(managers)

Added: pkg/PerformanceAnalytics/inst/doc/PA-Bacon.Rnw
===================================================================
--- pkg/PerformanceAnalytics/inst/doc/PA-Bacon.Rnw	                        (rev 0)
+++ pkg/PerformanceAnalytics/inst/doc/PA-Bacon.Rnw	2012-08-19 16:44:29 UTC (rev 2250)
@@ -0,0 +1,767 @@
+%% no need for  \DeclareGraphicsExtensions{.pdf,.eps}
+
+\documentclass[12pt,letterpaper,english]{article}
+\usepackage{times}
+\usepackage[T1]{fontenc}
+\IfFileExists{url.sty}{\usepackage{url}}
+                      {\newcommand{\url}{\texttt}}
+
+\usepackage{babel}
+\usepackage{noweb}
+\usepackage{Rd}
+
+\usepackage{Sweave}
+\SweaveOpts{engine=R,eps=FALSE}
+%\VignetteIndexEntry{Performance Attribution from Bacon}
+%\VignetteDepends{PerformanceAnalytics}
+%\VignetteKeywords{returns, performance, risk, benchmark, portfolio}
+%\VignettePackage{PerformanceAnalytics}
+
+
+\begin{document}
+
+\author {Matthieu Lestel}
+
+\title{Performance Attribution from Bacon}
+
+% \keywords{returns, performance, risk, benchmark, portfolio}
+
+\makeatletter
+\makeatother
+\maketitle
+
+\begin{abstract}
+  This vignette gives a brief overview of the functions developed in Bacon(2008) to evaluate the performance and risk of portfolios that are included in \pkg{PerformanceAnalytics} and how to use them. There are some tables at the end which give a quick overview of similar functions. The page number next to each function is the location of the function in Bacon(2008)
+\end{abstract}
+
+\tableofcontents
+
+<<echo = FALSE>>=
+library(PerformanceAnalytics)
+@
+
+\section{Risk Measure}
+
+\subsection{Mean absolute deviation (p.62)}
+
+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.
+
+ \deqn{MeanAbsoluteDeviation = \frac{\sum^{n}_{i=1}\mid r_i - \overline{r}\mid}{n}}{MeanAbsoluteDeviation = sum(|r-mean(r)|)/n }
+
+where \eqn{n} is the number of observations of the entire series, \eqn{r_i} is the return in month i and \eqn{\overline{r}} is the mean return
+
+<<>>=
+data(portfolio_bacon)
+print(MeanAbsoluteDeviation(portfolio_bacon[,1])) #expected 0.0310
+@
+
+\subsection{Frequency (p.64)}
+
+Gives the period of the return distribution (ie 12 if monthly return, 4 if quarterly return)
+
+<<>>=
+data(portfolio_bacon)
+print(Frequency(portfolio_bacon[,1])) #expected 12
+@
+
+\subsection{Sharpe Ratio (p.64)}
+
+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.
+ 
+\deqn{\frac{\overline{(R_{a}-R_{f})}}{\sqrt{\sigma_{(R_{a}-R_{f})}}}}
+
+<<>>=
+data(managers)
+SharpeRatio(managers[,1,drop=FALSE], Rf=.035/12, FUN="StdDev") 
+@
+
+\subsection{Risk-adjusted return: MSquared (p.67)}
+
+\eqn{M^2} is a risk adjusted return useful to judge the size of relative performance between differents portfolios. With it you can compare portfolios with different levels of risk.
+
+\deqn{M^2 = r_P + SR * (\sigma_M - \sigma_P) = (r_P - r_F) * \frac{\sigma_M}{\sigma_P} + r_F}{M squared = Rp + SR * (Market risk - Portfolio risk) = (Rp - Rf) * Market risk / Portfolio risk + Rf}
+
+where \eqn{r_P}. is the portfolio return annualized, \eqn{\sigma_M}. is the market risk and \eqn{\sigma_P} is the portfolio risk
+
+<<>>=
+data(portfolio_bacon)
+print(MSquared(portfolio_bacon[,1], portfolio_bacon[,2])) #expected 0.1068
+@
+
+\subsection{MSquared Excess (p.68)}
+
+\eqn{M^2} excess is the quantity above the standard M. There is a geometric excess return which is better for Bacon and an arithmetic excess return
+
+\deqn{M^2 excess (geometric) = \frac{1 + M^2}{1 + b} - 1}{MSquared excess (geometric) = (1+M^2)/(1+b) - 1}
+\deqn{M^2 excess (arithmetic) = M^2 - b}{MSquared excess (arithmetic) = M^2 - b}
+
+where \eqn{M^2}. is MSquared and \eqn{b}. is the benchmark annualised return.
+
+<<>>=
+data(portfolio_bacon)
+print(MSquaredExcess(portfolio_bacon[,1], portfolio_bacon[,2])) #expected -0.00998
+print(MSquaredExcess(portfolio_bacon[,1], portfolio_bacon[,2], Method="arithmetic")) #expected -0.011
+@
+
+\section{Regression analysis}
+
+\subsection{Regression equation (p.71)}
+
+\deqn{r_P = \alpha + \beta * b + \epsilon}
+
+\subsection{Regression alpha (p.71)}
+
+"Alpha" purports to be a measure of a manager's skill by measuring the portion of the managers returns that are not attributable to "Beta", or the portion of performance attributable to a benchmark.
+
+<<>>=
+data(managers)
+print(CAPM.alpha(managers[,1,drop=FALSE], managers[,8,drop=FALSE], Rf=.035/12))
+@
+
+\subsection{Regression beta (p.71)}
+
+CAPM Beta is the beta of an asset to the variance and covariance of an initial portfolio.  Used to determine diversification potential.
+
+<<>>=
+data(managers)
+CAPM.beta(managers[, "HAM2", drop=FALSE], managers[, "SP500 TR", drop=FALSE], Rf = managers[, "US 3m TR", drop=FALSE])
+@
+
+\subsection{Regression epsilon (p.71)}
+
+The regression epsilon is an error term measuring the vertical distance between the return predicted by the equation and the real result.
+
+\deqn{\epsilon_r = r_p - \alpha_r - \beta_r * b}{epsilon_r = r_p - alpha_r - beta_r * b}
+
+where \eqn{\alpha_r} is the regression alpha, \eqn{\beta_r} is the regression beta, \eqn{r_p} is the portfolio return and b is the benchmark return
+
+<<>>=
+data(managers)
+print(CAPM.epsilon(portfolio_bacon[,1], portfolio_bacon[,2])) #expected -0.013
+@
+
+\subsection{Jensen's alpha (p.72)}
+
+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.
+
+\deqn{\alpha = r_p - r_f - \beta_p * (b - r_f)}{alpha = r_p - r_f - beta_p * (b - r_f)}
+
+where \eqn{r_f}. is the risk free rate, \eqn{\beta_r}. is the regression beta, \eqn{r_p}. is the portfolio return and b is the benchmark return
+
+<<>>=
+data(portfolio_bacon)
+print(CAPM.jensenAlpha(portfolio_bacon[,1], portfolio_bacon[,2])) #expected -0.014
+@
+
+\subsection{Systematic Risk (p.75)}
+
+Systematic risk as defined by Bacon(2008) is the product of beta by market risk. Be careful ! It's not the same definition as the one given by Michael Jensen. Market risk is the standard deviation of the benchmark. The systematic risk is annualized
+
+\deqn{\sigma_s = \beta * \sigma_m}{systematic risk = beta * market risk}
+
+where \eqn{\sigma_s}. is the systematic risk, \eqn{\beta}. is the regression beta, and \eqn{\sigma_m} is the market risk
+
+<<>>=
+data(portfolio_bacon)
+print(SystematicRisk(portfolio_bacon[,1], portfolio_bacon[,2])) #expected 0.013
+@
+
+\subsection{Specific Risk (p.75)}
+
+Specific risk is the standard deviation of the error term in the regression equation.
+
+<<>>=
+data(portfolio_bacon)
+print(SpecificRisk(portfolio_bacon[,1], portfolio_bacon[,2])) #expected 0.0329
+@
+
+\subsection{Total Risk (p.75)}
+
+The square of total risk is the sum of the square of systematic risk and the square of specific risk. Specific risk is the standard deviation of the error term in the regression equation. Both terms are annualized to calculate total risk.
+
+\deqn{Total Risk = \sqrt{Systematic Risk^2 + Specific Risk^2}}{Total Risk^2 = Systematic Risk^2 + Specific Risk^2}
+
+<<>>=
+data(portfolio_bacon)
+print(TotalRisk(portfolio_bacon[,1], portfolio_bacon[,2])) #expected 0.0134
+@
+
+\subsection{Treynor ratio (p.75)}
+
+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).
+
+\deqn{TreynorRatio = \frac{\overline{(R_{a}-R_{f})}}{\beta_{a,b}}}{(mean(Ra-Rf))/(Beta(Ra,Rb))}
+
+<<>>=
+data(managers)
+print(round(TreynorRatio(managers[,1,drop=FALSE], managers[,8,drop=FALSE], Rf=.035/12),4))
+@
+
+\subsection{Modified Treynor ratio (p.77)}
+
+To calculate modified Treynor ratio, we divide the numerator by the systematic risk instead of the beta.
+<<>>=
+data(portfolio_bacon) 
+print(TreynorRatio(portfolio_bacon[,1], portfolio_bacon[,2], modified = TRUE)) #expected 1.677 
+@
+
+\subsection{Appraisal ratio (or Treynor-Black ratio) (p.77)}
+
+Appraisal ratio is the Jensen's alpha adjusted for specific risk. The numerator is divided by specific risk instead of total risk.
+
+\deqn{Appraisal ratio = \frac{\alpha}{\sigma_{\epsilon}}}{Appraisal ratio = Jensen's alpha / specific risk}
+
+where \eqn{alpha}. is the Jensen's alpha, \eqn{\sigma_{epsilon}}. is the specific risk
+
+<<>>=
+data(portfolio_bacon)
+print(AppraisalRatio(portfolio_bacon[,1], portfolio_bacon[,2], method="appraisal")) #expected -0.430
+@
+
+\subsection{Modified Jensen (p.77)}
+
+Modified Jensen's alpha is Jensen's alpha divided by beta.
+
+\deqn{Modified Jensen's alpha = \frac{\alpha}{\beta}}{Modified Jensen's alpha = Jensen's alpha / beta}
+
+where \eqn{alpha}. is the Jensen's alpha
+
+<<>>=
+data(portfolio_bacon)
+print(AppraisalRatio(portfolio_bacon[,1], portfolio_bacon[,2], method="modified")) 
+@
+
+\subsection{Fama decomposition (p.77)}
+
+Fama beta is a beta used to calculate the loss of diversification. It is made so that the systematic risk is equivalent to the total portfolio risk.
+
+\deqn{\beta_F = \frac{\sigma_P}{\sigma_M}}{Fama beta = portfolio standard deviation / benchmark standard deviation}
+
+where \eqn{\sigma_P}. is the portfolio standard deviation and \eqn{\sigma_M}. is the market risk
+
+<<>>=
+data(portfolio_bacon)
+print(FamaBeta(portfolio_bacon[,1], portfolio_bacon[,2])) #expected 1.03
+@
+
+\subsection{Selectivity (p.78)}
+
+Selectivity is the same as Jensen's alpha
+
+\deqn{Selectivity = r_p - r_f - \beta_p * (b - r_f)}{Selectivity = r_p - r_f - beta_p * (b - r_f)}
+
+where \eqn{r_f}. is the risk free rate, \eqn{\beta_r}. is the regression beta, \eqn{r_p}. is the portfolio return and b is the benchmark return
+
+<<>>=
+data(portfolio_bacon)
+print(Selectivity(portfolio_bacon[,1], portfolio_bacon[,2])) #expected -0.0141
+@
+
+\subsection{Net selectivity (p.78)}
+
+Net selectivity is the remaining selectivity after deducting the amount of return require to justify not being fully diversified
+
+If net selectivity is negative the portfolio manager has not justified the loss of diversification
+
+\deqn{Net selectivity = \alpha - d}{Net selectivity = Selectity - diversification}
+
+where \eqn{\alpha}. is the selectivity and \eqn{d}. is the diversification
+
+<<>>=
+data(portfolio_bacon)
+print(NetSelectivity(portfolio_bacon[,1], portfolio_bacon[,2])) #expected -0.017
+@
+
+\section{Relative Risk}
+
+\subsection{Tracking error (p.78)}
+
+A measure of the unexplained portion of performance relative to a benchmark.
+ 
+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.
+
+\deqn{ TrackingError = \sqrt{\sum\frac{(R_{a}-R_{b})^{2}}{len(R_{a})\sqrt{scale}}} }{ TrackingError = sqrt(sum(Ra - Rb)^2 / (length(R) - 1)) * sqrt(scale)}
+
+<<>>=
+data(managers)
+TrackingError(managers[,1,drop=FALSE], managers[,8,drop=FALSE]) 
+@
+
+\subsection{Information ratio (p.80)}
+
+The Active Premium divided by the Tracking Error.
+ 
+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.
+
+<<>>=
+data(managers)
+InformationRatio(managers[,"HAM1",drop=FALSE], managers[, "SP500 TR", drop=FALSE])
+@
+
+\section{Return Distribution}
+
+\subsection{Skewness (p.83)}
+
+measures the deformation from a normal deformation
+
+\deqn{Skewness = \frac{1}{n}*\sum^{n}_{i=1}(\frac{r_i - \overline{r}}{\sigma_P})^3}{Skewness(moment) = sum((x-mean(x))^3/var(x)^(3/2))/length(x)}
+
+where \eqn{n}. is the number of return, \eqn{\overline{r}}. is the mean of the return distribution, \eqn{\sigma_P}. is its standard deviation and \eqn{\sigma_{S_P}} is its sample standard deviation
+
+<<>>=
+data(managers)
+skewness(managers)
+@
+
+\subsection{Sample skewness (p.84)}
+
+\deqn{Sample Skewness =  \frac{n}{(n-1)*(n-2)}*\sum^{n}_{i=1}(\frac{r_i - \overline{r}}{\sigma_{S_P}})^3 }{skewness(sample) = sum(((x-mean(x))/var(x))^3)*n/((n-1)*(n-2))}
+
+where \eqn{n}. is the number of return, \eqn{\overline{r}}. is the mean of the return distribution, \eqn{\sigma_P}. is its standard deviation and \eqn{\sigma_{S_P}}. is its sample standard deviation
+
+<<>>=
+data(portfolio_bacon)
+print(skewness(portfolio_bacon[,1], method="sample")) #expected -0.09
+@
+
+\subsection{Kurtosis (p.84)} 
+
+Kurtosis measures the weight or returns in the tails of the distribution relative to standard deviation.
+
+\deqn{Kurtosis(moment) = \frac{1}{n}*\sum^{n}_{i=1}(\frac{r_i - \overline{r}}{\sigma_P})^4}{kurtosis(moment) = sum((x-mean(x))^4/var(x)^2)/length(x)}
+
+where \eqn{n}. is the number of return, \eqn{\overline{r}}. is the mean of the return distribution, \eqn{\sigma_P}. is its standard deviation and \eqn{\sigma_{S_P}}. is its sample standard deviation
+
+<<>>=
+data(portfolio_bacon)
+print(kurtosis(portfolio_bacon[,1], method="moment")) #expected 2.43
+@
+
+\subsection{Excess kurtosis (p.85)}
+
+\deqn{Excess Kurtosis = \frac{1}{n}*\sum^{n}_{i=1}(\frac{r_i - \overline{r}}{\sigma_P})^4 - 3}{kurtosis(excess) = sum((x-mean(x))^4/var(x)^2)/length(x) - 3}
+
+where \eqn{n}. is the number of return, \eqn{\overline{r}}. is the mean of the return distribution, \eqn{\sigma_P}. is its standard deviation and \eqn{\sigma_{S_P}}. is its sample standard deviation
+
+<<>>=
+data(portfolio_bacon)
+print(kurtosis(portfolio_bacon[,1], method="excess")) #expected -0.57
+@
+
+\subsection{Sample kurtosis (p.85)}
+
+\deqn{Sample kurtosis =  \frac{n*(n+1)}{(n-1)*(n-2)*(n-3)}*\sum^{n}_{i=1}(\frac{r_i - \overline{r}}{\sigma_{S_P}})^4 }{kurtosis(sample) = sum(((x-mean(x))/var(x))^4)*n*(n+1)/((n-1)*(n-2)*(n-3))}
+
+where \eqn{n}. is the number of return, \eqn{\overline{r}}. is the mean of the return distribution, \eqn{\sigma_P}. is its standard deviation and \eqn{\sigma_{S_P}}. is its sample standard deviation
+
+<<>>=
+data(portfolio_bacon)
+print(kurtosis(portfolio_bacon[,1], method="sample")) #expected 3.03
+@
+
+\subsection{Sample excess kurtosis (p.85)}
+
+\deqn{Sample excess kurtosis =  \frac{n*(n+1)}{(n-1)*(n-2)*(n-3)}*\sum^{n}_{i=1}(\frac{r_i - \overline{r}}{\sigma_{S_P}})^4  - \frac{3*(n-1)^2}{(n-2)*(n-3)}}{kurtosis(sample excess) = sum(((x-mean(x))/var(x))^4)*n*(n+1)/((n-1)*(n-2)*(n-3)) - 3*(n-1)^2/((n-2)*(n-3))}
+
+where \eqn{n}. is the number of return, \eqn{\overline{r}}. is the mean of the return distribution, \eqn{\sigma_P}. is its standard deviation and \eqn{\sigma_{S_P}}. is its sample standard deviation
+
+<<>>=
+data(portfolio_bacon)
+print(kurtosis(portfolio_bacon[,1], method="sample_excess")) #expected -0.41
+@
+
+\section{Drawdown}
+
+\subsection{Pain index (p.89)}
+
+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. 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.
+
+\deqn{Pain index = \sum^{n}_{i=1} \frac{\mid D'_i \mid}{n}}{Pain index = sum(|D'i|/n)}
+
+where \eqn{n}. is the number of observations of the entire series, \eqn{D'_i}. is the drawdown since previous peak in period i
+
+<<>>=
+data(portfolio_bacon)
+print(PainIndex(portfolio_bacon[,1])) #expected 0.04
+@
+
+\subsection{Calmar ratio (p.89)}
+
+Calmar ratio is another method of creating a risk-adjusted measure for ranking investments similar to the Sharpe ratio.
+
+<<>>=
+data(managers)
+CalmarRatio(managers[,1,drop=FALSE])
+@
+
+\subsection{Sterling ratio (p.89)}
+
+Sterling ratio is another method of creating a risk-adjusted measure for ranking investments similar to the Sharpe ratio.
+
+<<>>=
+data(managers)
+SterlingRatio(managers[,1,drop=FALSE])
+@
+
+\subsection{Burke ratio (p.90)}
+
+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.
+
+\deqn{Burke Ratio = \frac{r_P - r_F}{\sqrt{\sum^{d}_{t=1}{D_t}^2}}}{Burke Ratio = (Rp - Rf) / (sqrt(sum(t=1..n)(Dt^2)))}
+
+where \eqn{d}. is number of drawdowns, \eqn{r_P} is the portfolio return, \eqn{r_F}. is the risk free rate and \eqn{D_t}. the \eqn{t^{th}} drawdown.
+
+<<>>=
+data(portfolio_bacon)
+print(BurkeRatio(portfolio_bacon[,1])) #expected 0.74
+@
+
+\subsection{Modified Burke ratio (p.91)}
+
+To calculate the modified Burke ratio we just multiply the Burke ratio by the square root of the number of datas.
+
+\deqn{Modified Burke Ratio = \frac{r_P - r_F}{\sqrt{\sum^{d}_{t=1}\frac{{D_t}^2}{n}}}}{Modified Burke Ratio = (Rp - Rf) / (sqrt(sum(t=1..n)(Dt^2 / n)))}
+
+where \eqn{n}. is the number of observations of the entire series, \eqn{d} is number of drawdowns, \eqn{r_P}. is the portfolio return, \eqn{r_F}. is the risk free rate and \eqn{D_t}. the \eqn{t^{th}}. drawdown.
+
+<<>>=
+data(portfolio_bacon)
+print(BurkeRatio(portfolio_bacon[,1], modified = TRUE)) #expected 3.65
+@
+
+\subsection{Martin ratio (p.91)}
+
+To calculate Martin ratio we divide the difference of the portfolio return and the risk free rate by the Ulcer index
+
+\deqn{Martin ratio = \frac{r_P - r_F}{\sqrt{\sum^{n}_{i=1} \frac{{D'_i}^2}{n}}}}{Martin ratio = (rp - rf) / Ulcer index}
+
+where \eqn{r_P}. is the annualized portfolio return, \eqn{r_F}. is the risk free rate, \eqn{n}. is the number of observations of the entire series, \eqn{D'_i}. is the drawdown since previous peak in period i
+
+<<>>=
+data(portfolio_bacon)
+print(MartinRatio(portfolio_bacon[,1])) #expected 1.70
+@
+
+\subsection{Pain ratio (p.91)}
+
+To calculate Pain ratio we divide the difference of the portfolio return and the risk free rate by the Pain index
+
+\deqn{Pain ratio = \frac{r_P - r_F}{\sum^{n}_{i=1} \frac{\mid D'_i \mid}{n}}}{Pain ratio = (rp - rf) / Pain index}
+
+where \eqn{r_P}. is the annualized portfolio return, \eqn{r_F}. is the risk free rate, \eqn{n}. is the number of observations of the entire series, \eqn{D'_i}. is the drawdown since previous peak in period i
+
+<<>>=
+data(portfolio_bacon)
+print(PainRatio(portfolio_bacon[,1])) #expected 2.66
+@
+
+\section{Downside risk}
+
+\subsection{Downside risk (p.92)}
+
+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.
+
+\deqn{DownsideDeviation(R , MAR) = \delta_{MAR} = \sqrt{\sum^{n}_{t=1}\frac{min[(R_{t} - MAR), 0]^2}{n}}}{DownsideDeviation(R, MAR) = sqrt(1/n * sum(t=1..n)((min(R(t)-MAR, 0))^2))}
+
+\deqn{ DownsideVariance(R, MAR) = \sum^{n}_{t=1}\frac{min[(R_{t} - MAR), 0]^2}{n}}{DownsideVariance(R, MAR) = 1/n * sum(t=1..n)((min(R(t)-MAR, 0))^2)}
+
+\deqn{DownsidePotential(R, MAR) = \sum^{n}_{t=1}\frac{min[(R_{t} - MAR), 0]} {n}}{DownsidePotential(R, MAR) =  1/n * sum(t=1..n)(min(R(t)-MAR, 0))}
+
+where \eqn{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.
+
+<<>>=
+data(portfolio_bacon)
+MAR = 0.5
+DownsideDeviation(portfolio_bacon[,1], MAR) #expected 0.493
+DownsidePotential(portfolio_bacon[,1], MAR) #expected 0.491
+@
+
+\subsection{UpsideRisk (p.92)}
+
+Upside Risk is the similar of semideviation taking the return above the Minimum Acceptable Return instead of using the mean return or zero.
+
+\deqn{ UpsideRisk(R , MAR) = \sqrt{\sum^{n}_{t=1}\frac{max[(R_{t} - MAR), 0]^2}{n}}}{UpsideRisk(R, MAR) = sqrt(1/n * sum(t=1..n)((max(R(t)-MAR, 0))^2))}
+
+\deqn{ UpsideVariance(R, MAR) = \sum^{n}_{t=1}\frac{max[(R_{t} - MAR), 0]^2} {n}}{UpsideVariance(R, MAR) = 1/n * sum(t=1..n)((max(R(t)-MAR, 0))^2)}
+
+\deqn{UpsidePotential(R, MAR) = \sum^{n}_{t=1}\frac{max[(R_{t} - MAR), 0]} {n}}{DownsidePotential(R, MAR) =  1/n * sum(t=1..n)(max(R(t)-MAR, 0))}
+
+where \eqn{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.
+
+
+<<>>=
+data(portfolio_bacon)
+MAR = 0.005
+print(UpsideRisk(portfolio_bacon[,1], MAR, stat="risk")) #expected 0.02937
+print(UpsideRisk(portfolio_bacon[,1], MAR, stat="variance")) #expected 0.08628
+print(UpsideRisk(portfolio_bacon[,1], MAR, stat="potential")) #expected 0.01771
+@
+
+\subsection{Downside frequency (p.94)}
+
+To calculate Downside Frequency, we take the subset of returns that are less than the target (or Minimum Acceptable Returns (MAR)) returns and divide the length of this subset by the total number of returns.
+
+\deqn{ DownsideFrequency(R , MAR) = \sum^{n}_{t=1}\frac{min[(R_{t} - MAR),0]}{R_{t}*n}}{DownsideFrequency(R, MAR) = length(subset of returns below MAR) / length(total returns)}
+
+where \eqn{n}. is the number of observations of the entire series
+
+<<>>=
+data(portfolio_bacon)
+MAR = 0.005
+print(DownsideFrequency(portfolio_bacon[,1], MAR)) #expected 0.458
+@
+
+\subsection{Bernardo and Ledoit ratio (p.95)}
+
+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
+
+\deqn{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)}}}{BernardoLedoitRatio(R) = 1/n*sum(t=1..n)(max(R(t),0)) / 1/n*sum(t=1..n)(max(-R(t),0))}
+
+where \eqn{n}. is the number of observations of the entire series
+
+<<>>=
+data(portfolio_bacon)
+print(BernardoLedoitRatio(portfolio_bacon[,1])) #expected 1.78
+@
+
+\subsection{d ratio (p.95)}
+
+The d ratio is similar to the Bernado Ledoit ratio but inverted and taking into account the frequency of positive and negative returns.
+
+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.
+
+\deqn{DRatio(R) = \frac{n_{d}*\sum^{n}_{t=1}{max(-R_{t},0)}}{n_{u}*\sum^{n}_{t=1}{max(R_{t},0)}}}{DRatio(R) = nd*sum(t=1..n)(max(-R(t),0)) / nu*sum(t=1..n)(max(R(t),0))}
+
+where \eqn{n}. is the number of observations of the entire series, \eqn{n_{d}}. is the number of observations less than zero, \eqn{n_{u}}. is the number of observations greater than zero
+
+<<>>=
+data(portfolio_bacon)
+print(DRatio(portfolio_bacon[,1])) #expected 0.401
+@
+
+\subsection{Omega-Sharpe ratio (p.95)}
+
+The Omega-Sharpe ratio is a conversion of the omega ratio to a ranking statistic in familiar form to the Sharpe ratio.
+
+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.
+
+\deqn{OmegaSharpeRatio(R,MAR) = \frac{r_p - r_t}{\sum^n_{t=1}\frac{max(r_t - r_i, 0)}{n}}}{OmegaSharpeRatio(R,MAR) = (Rp - Rt) / -DownsidePotential(R,MAR)}
+
+where \eqn{n}. is the number of observations of the entire series
+
+<<>>=
+data(portfolio_bacon)
+MAR = 0.005
+print(OmegaSharpeRatio(portfolio_bacon[,1], MAR)) #expected 0.29
+@
+
+\subsection{Sortino ratio (p.96)}
+
+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.
+
+\deqn{ SortinoRatio=\frac{(\overline{R_{a} - MAR})}{\delta_{MAR}} } 
+
+where \eqn{\delta_{MAR}}. is the \code{\link{DownsideDeviation}}.
+
+<<>>=
+data(managers)
+round(SortinoRatio(managers[, 1]),4)
+@
+
+\subsection{Kappa (p.96)}
+
+Introduced by Kaplan and Knowles (2004), Kappa is a generalized downside risk-adjusted performance measure.
+
+To calculate it, we take the difference of the mean of the distribution to the target and we divide it by the l-root of the lth lower partial moment. To calculate the lth lower partial moment we take the subset of returns below the target and we sum the differences of the target to these returns. We then return return this sum divided by the length of the whole distribution.
+
+\deqn{Kappa(R, MAR, l) = \frac{r_{p}-MAR}{\sqrt[l]{\frac{1}{n}*\sum^n_{t=1}max(MAR-R_{t}, 0)^l}}}{Kappa(R, MAR, l) = (rp - MAR)/(\sqrt[l](1/n*sum(t=1..n)(max(MAR-r(t),0)^l)))}
+
+<<>>=
+data(portfolio_bacon)
+MAR = 0.005
+l = 2
+print(Kappa(portfolio_bacon[,1], MAR, l)) #expected 0.157
+@
+
+\subsection{Upside potential ratio (p.97)}
+ 
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/returnanalytics -r 2250


More information about the Returnanalytics-commits mailing list