Description Usage Arguments Details Value See Also Examples
View source: R/optimize_portfolio_rebalancing.R
A wrapper around optimize.portfolio.rebalancing()
that allows the user to quickly add forecasts for the mean and the variance.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | optimize_portfolio_rebalancing(R, ...)
## Default S3 method:
optimize_portfolio_rebalancing(R, ...)
## S3 method for class 'matrix'
optimize_portfolio_rebalancing(R, ...)
## S3 method for class 'xts'
optimize_portfolio_rebalancing(R, ...)
## S3 method for class 'zoo'
optimize_portfolio_rebalancing(R, ...)
## S3 method for class 'data.frame'
optimize_portfolio_rebalancing(R, ...)
|
R |
An xts, matrix, data frame, timeSeries, zoo or tibble object of asset returns. The data cannot be "tidy". |
... |
Any other paramenters to be passed into [PortfolioAnalytics::optimize.portfolio.rebalancing()]. |
As explained in the vignette "Custom Moment and Objective Functions", Portfolio Analytics works more efficiently when the mean is specified as _mu_ and the variance as _sigma_.
Same output of optimize.portfolio.rebalancing
.
[PortfolioAnalytics::optimize.portfolio.rebalancing()] and [purrr::as_mapper()]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | # load data
library(dplyr)
library(PortfolioAnalytics)
data(edhec)
# create a mean-variance portfolio (long-only)
# that uses the \code{auto.arima} function from the \code{forecast} package
# as one step ahead forecasts for the mean
# and the famous "Bayes-Stein" estimator the covariance
mean_var_spec <- portfolio.spec(assets = colnames(edhec)) %>%
add.constraint(type = "box", min = 0.00, max = 1.00) %>%
add.objective(type = "risk", name = "var") %>%
add.objective(type = "return", name = "mean")
optimize_portfolio_rebalancing(
R = edhec,
portfolio = mean_var_spec,
optimize_method = 'random',
rebalance_on = "months",
training_period = 120,
rolling_window = 120,
search_size = 100,
mu = forecast::ets,
sigma = cov_shrink_to_bayes_stein,
message = FALSE,
trace = FALSE
)
# \code{PortfolioMoments} aloows you to use the same formulas syntax as \code{purrr}.
# Suppose you want to add restrictions to the \code{auto.arima} model above.
## Not run:
optimize_portfolio(
R = edhec,
portfolio = mean_var_spec,
optimize_method = 'random',
rebalance_on = "months",
training_period = 120,
rolling_window = 120,
search_size = 100,
mu = ~ forecast::auto.arima(., max.p = 2, max.q = 2, seasonal = FALSE),
sigma = cov_shrink_to_bayes_stein,
message = FALSE,
trace = FALSE
)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.