[Returnanalytics-commits] r2719 - pkg/PerformanceAnalytics/sandbox/pulkit/week6
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Aug 5 15:56:28 CEST 2013
Author: pulkit
Date: 2013-08-05 15:56:28 +0200 (Mon, 05 Aug 2013)
New Revision: 2719
Added:
pkg/PerformanceAnalytics/sandbox/pulkit/week6/Drawdownalpha.R
Modified:
pkg/PerformanceAnalytics/sandbox/pulkit/week6/DrawdownBeta.R
Log:
Added files for alpha drawdown
Modified: pkg/PerformanceAnalytics/sandbox/pulkit/week6/DrawdownBeta.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/week6/DrawdownBeta.R 2013-08-05 10:51:30 UTC (rev 2718)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/week6/DrawdownBeta.R 2013-08-05 13:56:28 UTC (rev 2719)
@@ -40,7 +40,7 @@
#'
#'@examples
#'
-#'BetaDrawdown(edhec[,1],edhec[,2]) #expected value
+#'BetaDrawdown(edhec[,1],edhec[,2]) #expected value 0.5390431
BetaDrawdown<-function(R,Rm,h=0,p=0.95,weights=NULL,geometric=TRUE,...){
@@ -82,7 +82,18 @@
}
else q=c(q,0)
}
- beta_dd = sum((as.numeric(x[which(cumul_xm==max(cumul_xm))])-x)*q)/CDaR(Rm,p=p)
+ boolean = (cummax(cumul_xm)==cumul_xm)
+ index = NULL
+ for(j in 1:nrow(Rm)){
+ if(boolean[j] == TRUE){
+ index = c(index,j)
+ b = j
+ }
+ else{
+ index = c(index,b)
+ }
+ }
+ beta_dd = sum((as.numeric(x[index])-x)*q)/CDaR(Rm,p=p)
return(beta_dd)
}
@@ -99,7 +110,6 @@
if(columns==1){
return(beta)
}
- print(beta)
colnames(beta) = columnnames
rownames(beta) = paste("Drawdown Beta (p =",p*100,"%)")
beta = reclass(beta,R)
Added: pkg/PerformanceAnalytics/sandbox/pulkit/week6/Drawdownalpha.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/week6/Drawdownalpha.R (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/week6/Drawdownalpha.R 2013-08-05 13:56:28 UTC (rev 2719)
@@ -0,0 +1,71 @@
+#' @title
+#' Drawdown alpha
+#'
+#' @description
+#' Then the difference between the actual rate of return and the rate of
+#' return of the instrument estimated by \eqn{\beta_DD{w_T}} is called CDaR
+#' alpha and is given by
+#'
+#' \deqn{\alpha_DD = w_T - \beta_DD{w_T^M}}
+#'
+#' here \eqn{\beta_DD} is the beta drawdown. The code for beta drawdown can
+#' be found here \code{BetaDrawdown}.
+#'
+#' Postive \eqn{\alpha_DD} implies that the instrument did better than it was
+#' predicted, and consequently, \eqn{\alpha_DD} can be used as a performance
+#' measure to rank instrument and to identify those that outperformed their
+#' CAPM predictions
+#'
+#'
+#'@param R an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns
+#'@param Rm Return series of the optimal portfolio an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns
+#'@param p confidence level for calculation ,default(p=0.95)
+#'@param weights portfolio weighting vector, default NULL, see Details
+#' @param geometric utilize geometric chaining (TRUE) or simple/arithmetic chaining (FALSE) to aggregate returns, default TRUE
+#'@param \dots any passthru variable
+#'@references
+#'Zabarankin, M., Pavlikov, K., and S. Uryasev. Capital Asset Pricing Model
+#'(CAPM) with Drawdown Measure.Research Report 2012-9, ISE Dept., University
+#'of Florida,September 2012.
+#'
+#'@examples
+#'
+#'
+AlphaDrawdown<-function(R,Rm,p=0.95,weights = NULL,geometric = TRUE,...){
+ # DESCRIPTION:
+ # This function calculates the drawdown alpha given the return series
+ # and the optimal return series
+ #
+ # INPUTS:
+ # The return series of the portfolio , the return series of the optimal portfolio
+ # The confidence level, the weights and the type of cumulative returns
+
+ # OUTPUT:
+ # The drawdown alpha is given as the output
+
+
+ # ERROR HANDLING !!
+ x = checkData(R)
+ xm = checkData(Rm)
+ beta = BetaDrawdown(R,Rm,p = p,weights=weights,geometric=geometric,...)
+ if(!is.null(weights)){
+ x = Returns.portfolio(R,weights)
+ }
+ if(geometric){
+ cumul_x = cumprod(x+1)-1
+ cumul_xm = cumprod(xm+1)-1
+ }
+ else{
+ cumul_x = cumsum(x)
+ cumul_xm = cumsum(xm)
+ }
+ x_expected = mean(cumul_x)
+ xm_expected = mean(cumul_xm)
+ alpha = x_expected - beta*xm_expected
+ return(alpha)
+}
+
+
+
+
+
More information about the Returnanalytics-commits
mailing list