[Returnanalytics-commits] r2425 - pkg/PortfolioAnalytics/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jun 25 04:59:58 CEST 2013


Author: rossbennett34
Date: 2013-06-25 04:59:57 +0200 (Tue, 25 Jun 2013)
New Revision: 2425

Modified:
   pkg/PortfolioAnalytics/R/constraintsFUN.R
Log:
adding function to compute diversification for implementing as a constraint

Modified: pkg/PortfolioAnalytics/R/constraintsFUN.R
===================================================================
--- pkg/PortfolioAnalytics/R/constraintsFUN.R	2013-06-25 00:35:55 UTC (rev 2424)
+++ pkg/PortfolioAnalytics/R/constraintsFUN.R	2013-06-25 02:59:57 UTC (rev 2425)
@@ -62,3 +62,16 @@
   # the group constraints? Or another way?
   return(weights)
 }
+
+#' Function to compute diversification as a constraint
+#' 
+#' Diversification is defined as 1 minus the sum of the squared weights
+#' diversification <- 1 - sum(w^2)
+#' 
+#' @param weights vector of asset weights
+#' @author Ross Bennett
+#' @export
+diversification <- function(weights){
+   div <- 1 - sum(weights^2)
+   return(div)
+}



More information about the Returnanalytics-commits mailing list