BaşlayınÜcretsiz Başlayın

Optimization with custom objective function

This exercise builds on the previous exercise and we will run the optimization with the custom objective function that computes portfolio annualized standard deviation. Because an objective function can be any valid R function, we add a risk objective for the pasd() function. The set.portfolio.moments() function will not recognize the pasd() objective name, so we need to create a custom moment function to calculate the second moment, sigma. We will solve the problem using random portfolios as the optimization method.

Bu egzersiz

Intermediate Portfolio Analysis in R

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Add the custom objective function you created in the previous exercise to the portfolio specification object.
  • Print the portfolio specification object to see the constraints and objective.
  • Run the optimization. The name of the custom moment function is set_sigma.
  • Print the results of the optimization.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.


# Add custom objective to portfolio specification
port_spec <- add.objective(portfolio = ___, type = ___, name = ___)

# Print the portfolio specificaton object


# Run the optimization
opt <- optimize.portfolio(R = ___, portfolio = ___, momentFUN = ___, optimize_method = "random", rp = rp)

# Print the results of the optimization

Kodu Düzenle ve Çalıştır