optimize_statfolio: Optimize a portfolio of assets N times to get asset weight...

Description Usage Arguments Details Value See Also

View source: R/optimize_statfolio.R

Description

Optimze a portfolio of assets N times in order to gather statistics on the portfolio asset weights. The optimization is performed at the most recent date as provided by the xts matrix of returns.

Usage

1
2
3
optimize_statfolio(rets, portfolio, train_window = 63, N = 1,
  weightFUN = "mean", maxwtsmat = NA, optimize_method = "DEoptim",
  seed = 1, ...)

Arguments

rets

An xts matrix of asset returns.

portfolio

An object of type "portfolio" specifying the constraints and objective function.

train_window

The training window (in days) used to subset rets to calculate the optimization matrix. This is normally the same as the rolling_window if WFO optimization is used.

N

The number of times to repeatedly call function optimize.portfolio to generate weight statistics. Default is 1.

weightFUN

Sets the method used to compute the asset weights returned from N multiple runs of optimize.portfolio. Default is "mean", but it can be any valid function name such as "median".

maxwtsmat

The maximum weights xts matrix. It should include a row with the current optimization date, which will be extracted as a vector and added as a constraint in the optimize.portfolio function call. If the maximum weights are NOT a function of the date, then this can be specified as a named vector. Ignored if not specified.

optimize_method

Sets the optimization method used by optimize.portfolio. Default is "DEoptim".

seed

The random seed used to make a model reproducible.

...

Additional arguments passed through to optimize.portfolio.

objfnmat

The feature matrix passed to the custom objective function, if specified, used by optimize.portfolio. NOT USED

Details

This function leverages the optimize.portfolio function from package PortfolioAnalytics. It differs from optimize.portfolio in several ways. First, an argument N is provided to repeatedly call optimize.portfolio in order to gather statistics on the asset weights. This is relevant because often, the optimization of the objective function results in a somewhat unstable optimum, resulting in many possible asset weights.

See the vignette xtsanalytics for more details on the statfolio data structure.

Value

Returns a list containing the same elements as what optimize.portfolio normally returns, with the following exceptions:

$weights

A named vector containing the optimal set of weights for the portfolio. If N > 1, then this is a statistic computed from all optimize.portfolio runs. The choice of statistic is a function named using argument weightFUN. Default is "mean".

$N

The number of times function optimize.portfolio was called.

$allweights

A matrix containing the optimized asset weights for each run of optimize.portfolio

$SD_weights

A named vector containing the standard deviations of the weight values, computed by taking the StdDev of $allweights. If N = 1, then this will be all zeroes.

See Also

optimize.portfolio


jeanmarcgp/ResilientPortfolio documentation built on April 8, 2018, 5:43 p.m.