[Returnanalytics-commits] r2116 - in pkg/PerformanceAnalytics: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Fri Jul 6 19:16:24 CEST 2012
Author: matthieu_lestel
Date: 2012-07-06 19:16:23 +0200 (Fri, 06 Jul 2012)
New Revision: 2116
Added:
pkg/PerformanceAnalytics/R/BurkeRatio.R
pkg/PerformanceAnalytics/man/BurkeRatio.Rd
Log:
Burke ratio and modified Burke ratio with examples and documentation
Added: pkg/PerformanceAnalytics/R/BurkeRatio.R
===================================================================
--- pkg/PerformanceAnalytics/R/BurkeRatio.R (rev 0)
+++ pkg/PerformanceAnalytics/R/BurkeRatio.R 2012-07-06 17:16:23 UTC (rev 2116)
@@ -0,0 +1,130 @@
+#' Burke ratio of the return distribution
+#'
+#' 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.
+#'
+#' \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)))}
+#'
+#' \deqn{Burke Ratio = \frac{r_P - r_F}{\sqrt{\sum^{d}_{t=1}\frac{{D_t}^2}{n}}}}
+#' {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.
+#'
+#' @aliases Burke ratio
+#' @param R an xts, vector, matrix, data frame, timeSeries or zoo object of
+#' asset returns
+#' @param Rf the risk free rate
+#' @param modified a boolean to decide which ratio to calculate between Burke ratio and modified Burke ratio.
+#' @param period the number of returns in a year (ie 12 for monthly returns, 4 for quaterly returns)
+#' @param \dots any other passthru parameters
+#' @author Matthieu Lestel
+#' @references Carl Bacon, \emph{Practical portfolio performance measurement
+#' and attribution}, second edition 2008 p.90-91
+#'
+#' @keywords ts multivariate distribution models
+#' @examples
+#' data(portfolio_bacon)
+#' print(BurkeRatio(portfolio_bacon[,1])) #expected 0.79
+#' print(BurkeRatio(portfolio_bacon[,1], modified = TRUE)) #expected 3.86
+#'
+#' data(managers)
+#' print(BurkeRatio(managers['1996']))
+#' print(BurkeRatio(managers['1996',1]))
+#' print(BurkeRatio(managers['1996'], modified = TRUE))
+#' print(BurkeRatio(managers['1996',1], modified = TRUE))
+#'
+#' @export
+
+BurkeRatio <- function (R, Rf = 0, modified = FALSE, period = 12, ...)
+{
+ drawdown = c()
+ R0 <- R
+ R = checkData(R, method="matrix")
+
+ if (ncol(R)==1 || is.null(R) || is.vector(R)) {
+ calcul = FALSE
+ n = length(R)
+
+ number_drawdown = 0
+ in_drawdown = FALSE
+ peak = 1
+
+ for (i in (1:length(R))) {
+ if (!is.na(R[i])) {
+ calcul = TRUE
+ }
+ }
+
+ R = na.omit(R)
+ if(!calcul) {
+ result = NA
+ }
+ else
+ {
+
+ for (i in (2:length(R))) {
+ if (R[i]<0)
+ {
+ if (!in_drawdown)
+ {
+ peak = i-1
+ number_drawdown = number_drawdown + 1
+ in_drawdown = TRUE
+ }
+ }
+ else
+ {
+ if (in_drawdown)
+ {
+ temp = 1
+ boundary1 = peak+1
+ boundary2 = i-1
+ for(j in (boundary1:boundary2)) {
+ temp = temp*(1+R[j]*0.01)
+ }
+ drawdown = c(drawdown, (temp - 1) * 100)
+ in_drawdown = FALSE
+ }
+ }
+ }
+ if (in_drawdown)
+ {
+ temp = 1
+ boundary1 = peak+1
+ boundary2 = i
+ for(j in (boundary1:boundary2)) {
+ temp = temp*(1+R[j]*0.01)
+ }
+ drawdown = c(drawdown, (temp - 1) * 100)
+ in_drawdown = FALSE
+ }
+
+ Rp = period/n*sum(R)
+ result = (Rp - Rf)/sqrt(sum(drawdown^2))
+ if(modified)
+ {
+ result = result * sqrt(n)
+ }
+}
+ reclass(result, R0)
+ return(result)
+ }
+ else {
+ R = checkData(R)
+ result = apply(R, MARGIN = 2, BurkeRatio, Rf = Rf, modified = modified, ...)
+ result<-t(result)
+ colnames(result) = colnames(R)
+ if (modified)
+ {
+ rownames(result) = paste("Modified Burke ratio (Risk free = ",Rf,")", sep="")
+ }
+ else
+ {
+ rownames(result) = paste("Burke ratio (Risk free = ",Rf,")", sep="")
+ }
+ return(result)
+ }
+}
\ No newline at end of file
Added: pkg/PerformanceAnalytics/man/BurkeRatio.Rd
===================================================================
--- pkg/PerformanceAnalytics/man/BurkeRatio.Rd (rev 0)
+++ pkg/PerformanceAnalytics/man/BurkeRatio.Rd 2012-07-06 17:16:23 UTC (rev 2116)
@@ -0,0 +1,67 @@
+\name{BurkeRatio}
+\alias{Burke}
+\alias{BurkeRatio}
+\alias{ratio}
+\title{Burke ratio of the return distribution}
+\usage{
+ BurkeRatio(R, Rf = 0, modified = FALSE, period = 12, ...)
+}
+\arguments{
+ \item{R}{an xts, vector, matrix, data frame, timeSeries
+ or zoo object of asset returns}
+
+ \item{Rf}{the risk free rate}
+
+ \item{modified}{a boolean to decide which ratio to
+ calculate between Burke ratio and modified Burke ratio.}
+
+ \item{period}{the number of returns in a year (ie 12 for
+ monthly returns, 4 for quaterly returns)}
+
+ \item{\dots}{any other passthru parameters}
+}
+\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.
+}
+\details{
+ \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)))}
+
+ \deqn{Burke Ratio = \frac{r_P -
+ r_F}{\sqrt{\sum^{d}_{t=1}\frac{{D_t}^2}{n}}}} {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.
+}
+\examples{
+data(portfolio_bacon)
+print(BurkeRatio(portfolio_bacon[,1])) #expected 0.79
+print(BurkeRatio(portfolio_bacon[,1], modified = TRUE)) #expected 3.86
+
+data(managers)
+print(BurkeRatio(managers['1996']))
+print(BurkeRatio(managers['1996',1]))
+print(BurkeRatio(managers['1996'], modified = TRUE))
+print(BurkeRatio(managers['1996',1], modified = TRUE))
+}
+\author{
+ Matthieu Lestel
+}
+\references{
+ Carl Bacon, \emph{Practical portfolio performance
+ measurement and attribution}, second edition 2008 p.90-91
+}
+\keyword{distribution}
+\keyword{models}
+\keyword{multivariate}
+\keyword{ts}
+
More information about the Returnanalytics-commits
mailing list