CommencerCommencer gratuitement

Optimization with custom moment function

Now we would like to run the optimization using our custom moment function. Recall that the portfolio moments are set in optimize.portfolio() when the moment function is evaluated. We use the custom moment function by passing in the name to the momentFUN argument in optimize.portfolio(). Note how we can use PortfolioAnalytics to easily run optimizations using different methods for estimating moments, which will allow us to evaluate different techniques for moment estimates and refine those estimates by analyzing the optimization results.

Cet exercice fait partie du cours

Intermediate Portfolio Analysis in R

Afficher le cours

Instructions

A portfolio specification object, port_spec, and custom moment function, moments_robust(), have already been created for use with this exercise.

  • Run the optimization with the custom moment estimates. Assign this to a variable named opt_custom.
  • Print the output of opt_custom.
  • Run the optimization with sample moment estimates. Assign this to a variable named opt_sample.
  • Print the output of opt_sample.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Run the optimization with custom moment estimates
opt_custom <- optimize.portfolio(R = ___, portfolio = ___, optimize_method = "random", rp = rp, momentFUN = ___)

# Print the results of the optimization with custom moment estimates


# Run the optimization with sample moment estimates
opt_sample <- optimize.portfolio(R = ___, portfolio = ___, optimize_method = "random", rp = rp)

# Print the results of the optimization with sample moment estimates
Modifier et exécuter le code