Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Intermediate Portfolio Analysis in R

Cursus bekijken

Oefeninstructies

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.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# 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 bewerken en uitvoeren