[Returnanalytics-commits] r2771 - pkg/PerformanceAnalytics/sandbox/Shubhankit/Week5/Code

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Aug 13 00:39:54 CEST 2013


Author: shubhanm
Date: 2013-08-13 00:39:54 +0200 (Tue, 13 Aug 2013)
New Revision: 2771

Added:
   pkg/PerformanceAnalytics/sandbox/Shubhankit/Week5/Code/CDDopt.R
Log:
Conditional Draw down Optimization Code

Added: pkg/PerformanceAnalytics/sandbox/Shubhankit/Week5/Code/CDDopt.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Shubhankit/Week5/Code/CDDopt.R	                        (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/Shubhankit/Week5/Code/CDDopt.R	2013-08-12 22:39:54 UTC (rev 2771)
@@ -0,0 +1,24 @@
+cDDOpt = function(rmat, alpha=0.05, rmin=0, wmin=0, wmax=1, weight.sum=1)
+{
+  require(Rglpk)
+  n = ncol(rmat) # number of assets
+  s = nrow(rmat) # number of scenarios i.e. periods
+  averet = colMeans(rmat)
+  # creat objective vector, constraint matrix, constraint rhs
+  Amat = rbind(cbind(rbind(1,averet),matrix(data=0,nrow=2,ncol=s+1)),
+               cbind(rmat,diag(s),1))
+  objL = c(rep(0,n), as.numeric(Cdrawdown(rmat,.9)), -1)
+  bvec = c(weight.sum,rmin,rep(0,s))
+  # direction vector
+  dir.vec = c("==",">=",rep(">=",s))
+  # bounds on weights
+  bounds = list(lower = list(ind = 1:n, val = rep(wmin,n)),
+                upper = list(ind = 1:n, val = rep(wmax,n)))
+  res = Rglpk_solve_LP(obj=objL, mat=Amat, dir=dir.vec, rhs=bvec,
+                       types=rep("C",length(objL)), max=T, bounds=bounds)
+  w = as.numeric(res$solution[1:n])
+  return(list(w=w,status=res$status))
+}
+#' Guy Yollin work
+#' 
+#' 



More information about the Returnanalytics-commits mailing list