Get startedGet started for free

Sample moment estimates

The default method for estimating portfolio moments is the sample method. The moments are calculated in optimize.portfolio() by evaluating the function passed to the momentFUN argument. The default for momentFUN is set.portfolio.moments() which defaults to calculating the sample moments. The moments are then used as inputs to the objective functions. The moments that must be estimated depend on the objectives. For example, an objective to minimize portfolio standard deviation requires only an estimate of the second moment. Compare that to the objective to maximize Sharpe Ratio which requires the first and second moments to be estimated. Sample estimates of the moments have disadvantages including estimation error and the curse of dimensionality. There is an increased risk of estimation error as the dimension of assets and parameters to estimate increase.

This exercise is part of the course

Intermediate Portfolio Analysis in R

View Course

Exercise instructions

  • Add a return objective with "mean" as the objective name.
  • Calculate the sample moments using set.portfolio.moments. Assign to a variable named moments.
  • Check if the first moment is equal to the sample estimate of mean returns.
  • Add a risk objective with "StdDev" as the objective name.
  • Calculate the sample moments using set.portfolio.moments. Assign to a variable named moments.
  • Check if the second moment is equal to the sample estimate of the variance-covariance matrix.

Hands-on interactive exercise

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

# Add a return objective with "mean" as the objective name
port_spec <- add.objective(portfolio = port_spec, type = ___, name = ___)

# Calculate the sample moments
moments <- set.portfolio.moments(R = ___, portfolio = ___)

# Check if moments$mu is equal to the sample estimate of mean returns
moments$mu == colMeans(asset_returns)

# Add a risk objective with "StdDev" as the objective name
port_spec <- add.objective(portfolio = port_spec, type = ___, name = ___)

# Calculate the sample moments using set.portfolio.moments. Assign to a variable named moments.
moments <- set.portfolio.moments(R = ___, portfolio = ___)

# Check if moments$sigma is equal to the sample estimate of the variance-covariance matrix
moments$sigma == cov(asset_returns)
Edit and Run Code