Get startedGet started for free

Portfolio specification, constraints, and objectives

1. Portfolio specification, constraints, and objectives

You will now learn the details of each step of the workflow to solve portfolio optimization problems in PortfolioAnalytics.

2. Workflow overview

The first step in setting up a portfolio optimization problem in PortfolioAnalytics is creating the portfolio specification. Once you have created the portfolio specification, the next step is to add constraints and objectives to the portfolio specification. The next step is to run the optimization given the portfolio specification, constraints, and objectives. The final step is to analyze the output of the optimization.

3. Workflow: portfolio specification

The first step in the workflow is creating the portfolio specification with the portfolio-dot-spec function. The portfolio specification is an S3 object that holds portfolio level data, constraints, and objectives. The only required argument to portfolio-dot-spec is assets. The other arguments are optional and are not important for this course. The assets argument can be a character vector of asset names, a named vector of initial weights, or a scalar specifying the number of assets. The slide demonstrates these different ways of defining the assets argument.

4. Workflow: add constraints

You will add constraints to the portfolio specification with the add-dot-constraint function. The portfolio argument is the portfolio specification object that you want to add the constraint to. The type must be one of the supported constraint types. The constraint types that you will use the most in the course are 'weight_sum' and 'box'. The weight_sum type is a constraint on the sum of the weights and the box type is a constraint on the minimum and maximum weight of an individual asset. Note that the 'full_investment' type is a special case of the 'weight_sum' type that sets min_sum and max_sum equal to 1. Named arguments are passed via dots to the constructor of the specified constraint type. You can see an example of this in the slide where min equals 0-point-2 and max equals 0-point-6 are passed in for the box constraint. This means that you are adding a box constraint such that the minimum weight of any asset is 0.2 and the maximum weight of any asset is 0-point-6. It is important to point out that each constraint you add is a separate object and stored in the constraints slot in the portfolio object. In this way, the constraints are modular and one can easily add, remove, or modify the constraints in the portfolio object.

5. Workflow: add objectives

Similar to adding constraints, you will add objectives to the portfolio specification with the add-dot-objective function. The portfolio argument is the portfolio specification object that you want to add the objective to. The type must be one of the supported objective types. The objective types that you will use the most in the course are 'return' and 'risk'. An objective type of 'return' means that you are seeking to maximize the objective value whereas the 'risk' objective type means that you seek to minimize the objective value. The name should correspond to the name of the objective function. For example, "ES" is a function from the PerformanceAnalytics package that calculates portfolio expected shortfall. Additional arguments to the objective function can be passed in as a named list to arguments. You can see an example of this in the slide where we add the risk objective to minimize portfolio expected shortfall with 90% confidence level (p equals 0-point-90) and use the gaussian method in the estimate. Just like the constraints, each objective you add is a separate object and stored in the objectives slot in the portfolio object. In this way, the objectives are modular and one can easily add, remove, or modify the objectives in the portfolio object.

6. Let's practice!

Now let's move on to some exercises.