[Returnanalytics-commits] r2427 - pkg/PortfolioAnalytics/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Tue Jun 25 05:44:37 CEST 2013
Author: rossbennett34
Date: 2013-06-25 05:44:36 +0200 (Tue, 25 Jun 2013)
New Revision: 2427
Modified:
pkg/PortfolioAnalytics/R/constraints.R
Log:
adding functionality to specify volatility constraint
Modified: pkg/PortfolioAnalytics/R/constraints.R
===================================================================
--- pkg/PortfolioAnalytics/R/constraints.R 2013-06-25 03:19:25 UTC (rev 2426)
+++ pkg/PortfolioAnalytics/R/constraints.R 2013-06-25 03:44:36 UTC (rev 2427)
@@ -226,6 +226,11 @@
enabled=enabled,
...=...)
},
+ # Volatility constraint
+ volatility = {tmp_constraint <- volatility_constraint(type=type,
+ enabled=enabled,
+ ...=...)
+ },
# Do nothing and return the portfolio object if type is NULL
null = {return(portfolio)}
)
@@ -509,6 +514,26 @@
return(Constraint)
}
+#' constructor for volatility_constraint
+#'
+#' This function is called by add.constraint when type="volatility" is specified, \code{\link{add.constraint}}
+#' If portfolio standard deviation is less than min.vol, add penalty to maximize
+#' If portfolio standard deviation is greater than max.vol, add penalty to minimize
+#'
+#' @param type character type of the constraint
+#' @param min.vol minimum volatility constraint
+#' @param max.vol maximum volatilty constraint
+#' @param enabled TRUE/FALSE
+#' @param \dots any other passthru parameters to specify box and/or group constraints
+#' @author Ross Bennett
+#' @export
+volatility_constraint <- function(type, min.vol, max.vol, enabled=FALSE, ...){
+ Constraint <- constraint_v2(type, enabled=enabled, ...)
+ Constraint$min.vol <- min.vol
+ Constraint$max.vol <- max.vol
+ return(Constraint)
+}
+
#' function for updating constrints, not well tested, may be broken
#'
#' can we use the generic update.default function?
More information about the Returnanalytics-commits
mailing list