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
Exercise instructions
- Assign the column names of the
asset_returns
object to a variable calledasset_names
. - Create a portfolio specification object and pass in
asset_names
for theassets
argument. Assign the portfolio specification to a variable namedport_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