optimize_portfolio_rebalancing: Optimize and Rebalance Portfolios Using Custom Functions

Description Usage Arguments Details Value See Also Examples

View source: R/optimize_portfolio_rebalancing.R

Description

A wrapper around optimize.portfolio.rebalancing() that allows the user to quickly add forecasts for the mean and the variance.

Usage

 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, ...)

Arguments

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()].

Details

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_.

Value

Same output of optimize.portfolio.rebalancing.

See Also

[PortfolioAnalytics::optimize.portfolio.rebalancing()] and [purrr::as_mapper()]

Examples

 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)

Reckziegel/PortfolioMoments documentation built on May 29, 2019, 1:21 p.m.