Get startedGet started for free

Create a portfolio specification

The first step in the workflow of PortfolioAnalytics is to create the portfolio specification object. The portfolio specification holds portfolio level data, constraints and objectives. The only required argument to portfolio.spec() is assets. assets can be the number of assets, a named vector of seed weights, or a character vector of the asset names. The category_labels argument is used for labeling assets by a category such as sector, industry, region, asset class, or currency. The weight_seq argument allows you to specify a seed sequence of weights that are used by the random portfolios algorithms. Common practice is to pass in the column names of the returns object for the assets argument.

This exercise is part of the course

Intermediate Portfolio Analysis in R

View Course

Exercise instructions

  • Assign the column names of the asset_returns object to a variable called asset_names.
  • Create a portfolio specification object and pass in asset_names for the assets argument. Assign the portfolio specification to a variable named port_spec.
  • Get the class of the portfolio specification object.
  • Print the portfolio specification object.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Get the column names of the returns data


# Create a portfolio specification object using asset_names


# Get the class of the portfolio specification object


# Print the portfolio specification object
Edit and Run Code