LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Intermediate Portfolio Analysis in R

Kurs anzeigen

Anleitung zur Übung

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.

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# 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
Code bearbeiten und ausführen