[Returnanalytics-commits] r2728 - pkg/PerformanceAnalytics/sandbox/pulkit/week6
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Aug 6 11:49:20 CEST 2013
Author: pulkit
Date: 2013-08-06 11:49:20 +0200 (Tue, 06 Aug 2013)
New Revision: 2728
Modified:
pkg/PerformanceAnalytics/sandbox/pulkit/week6/DrawdownBeta.R
pkg/PerformanceAnalytics/sandbox/pulkit/week6/Drawdownalpha.R
Log:
Average and Max drawdown for alpha and beta drawdown
Modified: pkg/PerformanceAnalytics/sandbox/pulkit/week6/DrawdownBeta.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/week6/DrawdownBeta.R 2013-08-06 09:34:38 UTC (rev 2727)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/week6/DrawdownBeta.R 2013-08-06 09:49:20 UTC (rev 2728)
@@ -30,7 +30,8 @@
#'@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 invert TRUE/FALSE whether to invert the drawdown measure. see Details.
+#' @param type The type of BetaDrawdown if specified alpha then the alpha value given is taken (default 0.95). If "average" then
+#' alpha = 0 and if "max" then alpha = 1 is taken.
#'@param \dots any passthru variable.
#'
#'@references
@@ -42,7 +43,7 @@
#'
#'BetaDrawdown(edhec[,1],edhec[,2]) #expected value 0.5390431
-BetaDrawdown<-function(R,Rm,h=0,p=0.95,weights=NULL,geometric=TRUE,...){
+BetaDrawdown<-function(R,Rm,h=0,p=0.95,weights=NULL,geometric=TRUE,type=c("alpha","average","max"),...){
# DESCRIPTION:
#
@@ -61,6 +62,13 @@
columnnames = colnames(R)
columns = ncol(R)
drawdowns_m = Drawdowns(Rm)
+ type = type[1]
+ if(type=="average"){
+ p = 0
+ }
+ if(type == "max"){
+ p = 1
+ }
if(!is.null(weights)){
x = Returns.portfolio(R,weights)
}
@@ -116,3 +124,5 @@
return(beta)
}
+
+
Modified: pkg/PerformanceAnalytics/sandbox/pulkit/week6/Drawdownalpha.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/pulkit/week6/Drawdownalpha.R 2013-08-06 09:34:38 UTC (rev 2727)
+++ pkg/PerformanceAnalytics/sandbox/pulkit/week6/Drawdownalpha.R 2013-08-06 09:49:20 UTC (rev 2728)
@@ -22,7 +22,9 @@
#'@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 type The type of BetaDrawdown if specified alpha then the alpha value given is taken (default 0.95). If "average" then alpha = 0 and if "max" then alpha = 1 is taken.
#'@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
@@ -30,24 +32,35 @@
#'
#'@examples
#'
+#'AlphaDrawdown(edhec[,1],edhec[,2]) ## expected value : 0.5141929
#'
-AlphaDrawdown<-function(R,Rm,p=0.95,weights = NULL,geometric = TRUE,...){
+#'AlphaDrawdown(edhec[,1],edhec[,2],type="max") ## expected value : 0.8983177
+#'
+#'AlphaDrawdown(edhec[,1],edhec[,2],type="average") ## expected value : 1.692592
+#'@export
+
+
+AlphaDrawdown<-function(R,Rm,p=0.95,weights = NULL,geometric = TRUE,type=c("alpha","average","max"),...){
# 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
+ # 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 !!
+ # TODO ERROR HANDLING
+ if(ncol(R) != ncol(Rm)){
+ stop("The number of columns in R and Rm should be equal")
+ }
x = checkData(R)
xm = checkData(Rm)
- beta = BetaDrawdown(R,Rm,p = p,weights=weights,geometric=geometric,...)
+ beta = BetaDrawdown(R,Rm,p = p,weights=weights,geometric=geometric,type=type,...)
if(!is.null(weights)){
x = Returns.portfolio(R,weights)
}
More information about the Returnanalytics-commits
mailing list