1. Learn
  2. /
  3. Courses
  4. /
  5. Intermediate Portfolio Analysis in R

Exercise

Maximize quadratic utility function

In the video on challenges of portfolio optimization, you saw how to solve a quadratic utility optimization problem with the package quadprog. This exercise will show you how to solve a quadratic utility problem using the PortfolioAnalytics package. Recall the quadratic utility formulation has two terms, one for portfolio mean return and another for portfolio variance with a risk aversion parameter, lambda.

Instructions

100 XP
  • Create a portfolio specification object using asset names from the index_returns dataset and name the portfolio specification object port_spec.
  • Add a full investment constraint such that the weights sum to 1 to the port_spec object.
  • Add a long only constraint such that the weight of an asset is between 0 and 1 to the port_spec object.
  • Add an objective to maximize portfolio mean return to the port_spec object.
  • Add an objective to minimize portfolio variance to the port_spec object. Risk aversion should be set to 10.
  • Run the optimization. This problem can be solved by a quadratic programming solver so we specify optimize_method = "ROI"