[Returnanalytics-commits] r3643 - in pkg/PortfolioAnalytics: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon May 4 12:05:21 CEST 2015


Author: rossbennett34
Date: 2015-05-04 12:05:21 +0200 (Mon, 04 May 2015)
New Revision: 3643

Modified:
   pkg/PortfolioAnalytics/R/optimize.portfolio.R
   pkg/PortfolioAnalytics/man/optimize.portfolio.rebalancing.Rd
Log:
Improve default behavior and help file for optimize.portfolio.rebalancing

- Improving documentation for optimize.portfolio.rebalancing  to better explain the default behavior and how the optimization is done if training_period != rolling_window
- Set training_period equal to rolling_window if training_period is null and rolling_window is specified

Modified: pkg/PortfolioAnalytics/R/optimize.portfolio.R
===================================================================
--- pkg/PortfolioAnalytics/R/optimize.portfolio.R	2015-05-03 21:41:48 UTC (rev 3642)
+++ pkg/PortfolioAnalytics/R/optimize.portfolio.R	2015-05-04 10:05:21 UTC (rev 3643)
@@ -686,6 +686,7 @@
     
     DEcformals <- formals(DEoptim::DEoptim.control)
     DEcargs <- names(DEcformals)
+    print(names(dotargs))
     if( is.list(dotargs) ){
       pm <- pmatch(names(dotargs), DEcargs, nomatch = 0L)
       names(dotargs[pm > 0L]) <- DEcargs[pm]
@@ -732,7 +733,7 @@
     }
     if(hasArg(traceDE)) traceDE=match.call(expand.dots=TRUE)$traceDE else traceDE=TRUE
     DEcformals$trace <- traceDE
-    
+    print(DEcformals)
     if(isTRUE(trace)) { 
       #we can't pass trace=TRUE into constrained objective with DEoptim, because it expects a single numeric return
       tmptrace <- trace 
@@ -1402,8 +1403,42 @@
 #' Run portfolio optimization with periodic rebalancing at specified time periods. 
 #' Running the portfolio optimization with periodic rebalancing can help 
 #' refine the constraints and objectives by evaluating the out of sample
-#' performance of the portfolio based on historical data
+#' performance of the portfolio based on historical data.
 #' 
+#' If both \code{training_period} and \code{rolling_window} are \code{NULL}, 
+#' then \code{training_period} is set to a default value of 36. 
+#' 
+#' If \code{training_period} is \code{NULL} and a \code{rolling_window} is 
+#' specified, then \code{training_period} is set to the value of 
+#' \code{rolling_window}.
+#' 
+#' The user should be aware of the following behavior when both 
+#' \code{training_period} and \code{rolling_window} are specified and have 
+#' different values
+#' \itemize{
+#'   \item{\code{training_period < rolling_window}: }{For example, if you have 
+#'   \code{rolling_window=60}, \code{training_period=50}, and the periodicity 
+#'   of the data is the same as the rebalance frequency (i.e. monthly data with 
+#'   \code{rebalance_on="months")} then the returns data used in the optimization 
+#'   at each iteration are as follows:
+#'   \itemize{
+#'   \item{1: R[1:50,]}
+#'   \item{2: R[1:51,]}
+#'   \item{...}
+#'   \item{11: R[1:60,]}
+#'   \item{12: R[1:61,]}
+#'   \item{13: R[2:62,]}
+#'   \item{...}
+#'   }
+#'   This results in a growing window for several optimizations initially while
+#'   the endpoint iterator (i.e. \code{[50, 51, ...]}) is less than the 
+#'   rolling window width.}
+#'   \item{\code{training_period > rolling_window}: }{The data used in the initial 
+#'   optimization is \code{R[(training_period - rolling_window):training_period,]}. 
+#'   This results in some of the data being "thrown away", i.e. periods 1 to 
+#'   \code{(training_period - rolling_window - 1)} are not used in the optimization.}
+#' }
+#' 
 #' This function is a essentially a wrapper around \code{optimize.portfolio} 
 #' and thus the discussion in the Details section of the 
 #' \code{\link{optimize.portfolio}} help file is valid here as well.
@@ -1577,6 +1612,10 @@
   } else {
     rp = NULL
   }
+  # set training_period equal to rolling_window if training_period is null
+  # and rolling_window is not null
+  if(is.null(training_period) & !is.null(rolling_window))
+    training_period <- rolling_window
   
   if(is.null(training_period)) {if(nrow(R)<36) training_period=nrow(R) else training_period=36}
   if (is.null(rolling_window)){

Modified: pkg/PortfolioAnalytics/man/optimize.portfolio.rebalancing.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/optimize.portfolio.rebalancing.Rd	2015-05-03 21:41:48 UTC (rev 3642)
+++ pkg/PortfolioAnalytics/man/optimize.portfolio.rebalancing.Rd	2015-05-04 10:05:21 UTC (rev 3643)
@@ -1,4 +1,5 @@
-% Generated by roxygen2 (4.0.1): do not edit by hand
+% Generated by roxygen2 (4.1.1): do not edit by hand
+% Please edit documentation in R/optimize.portfolio.R
 \name{optimize.portfolio.rebalancing}
 \alias{optimize.portfolio.rebalancing}
 \alias{optimize.portfolio.rebalancing_v1}
@@ -17,13 +18,8 @@
 \arguments{
 \item{R}{an xts, vector, matrix, data frame, timeSeries or zoo object of asset returns}
 
-\item{portfolio}{an object of type "portfolio" specifying the constraints
-and objectives for the optimization}
-
 \item{constraints}{default NULL, a list of constraint objects}
 
-\item{objectives}{default NULL, a list of objective objects}
-
 \item{optimize_method}{one of "DEoptim", "random", "pso", "GenSA", or "ROI"}
 
 \item{search_size}{integer, how many portfolios to test, default 20,000}
@@ -31,8 +27,6 @@
 \item{trace}{TRUE/FALSE if TRUE will attempt to return additional
 information on the path or portfolios searched}
 
-\item{\dots}{any other passthru parameters to \code{\link{optimize.portfolio}}}
-
 \item{rp}{a set of random portfolios passed into the function to prevent recalculation}
 
 \item{rebalance_on}{character string of period to rebalance on. See
@@ -44,6 +38,13 @@
 \item{rolling_window}{an integer of the width (i.e. number of periods)
 of the rolling window, the default of NULL will run the optimization
 using the data from inception.}
+
+\item{portfolio}{an object of type "portfolio" specifying the constraints
+and objectives for the optimization}
+
+\item{objectives}{default NULL, a list of objective objects}
+
+\item{\dots}{any other passthru parameters to \code{\link{optimize.portfolio}}}
 }
 \value{
 a list containing the following elements
@@ -65,8 +66,42 @@
 Run portfolio optimization with periodic rebalancing at specified time periods.
 Running the portfolio optimization with periodic rebalancing can help
 refine the constraints and objectives by evaluating the out of sample
-performance of the portfolio based on historical data
+performance of the portfolio based on historical data.
 
+If both \code{training_period} and \code{rolling_window} are \code{NULL},
+then \code{training_period} is set to a default value of 36.
+
+If \code{training_period} is \code{NULL} and a \code{rolling_window} is
+specified, then \code{training_period} is set to the value of
+\code{rolling_window}.
+
+The user should be aware of the following behavior when both
+\code{training_period} and \code{rolling_window} are specified and have
+different values
+\itemize{
+  \item{\code{training_period < rolling_window}: }{For example, if you have
+  \code{rolling_window=60}, \code{training_period=50}, and the periodicity
+  of the data is the same as the rebalance frequency (i.e. monthly data with
+  \code{rebalance_on="months")} then the returns data used in the optimization
+  at each iteration are as follows:
+  \itemize{
+  \item{1: R[1:50,]}
+  \item{2: R[1:51,]}
+  \item{...}
+  \item{11: R[1:60,]}
+  \item{12: R[1:61,]}
+  \item{13: R[2:62,]}
+  \item{...}
+  }
+  This results in a growing window for several optimizations initially while
+  the endpoint iterator (i.e. \code{[50, 51, ...]}) is less than the
+  rolling window width.}
+  \item{\code{training_period > rolling_window}: }{The data used in the initial
+  optimization is \code{R[(training_period - rolling_window):training_period,]}.
+  This results in some of the data being "thrown away", i.e. periods 1 to
+  \code{(training_period - rolling_window - 1)} are not used in the optimization.}
+}
+
 This function is a essentially a wrapper around \code{optimize.portfolio}
 and thus the discussion in the Details section of the
 \code{\link{optimize.portfolio}} help file is valid here as well.



More information about the Returnanalytics-commits mailing list