ComenzarEmpieza gratis

Matrix-based calculation of portfolio mean and variance

When \(w\) is the column-matrix of portfolio weights, \(\mu\) the column-matrix of expected returns, and \(\Sigma\) the return covariance matrix. Then the portfolio expected return is \(w'\mu\), and the portfolio variance is \(w'\Sigma w\). Remember that the portfolio's volatility is the square root of its variance.

You will practice matrix multiplication in R using the %*% function, instead of the standard *. In addition, you will transpose the matrices by using the standard function t(). Remember that transposing a matrix is simply changing the rows of the matrix to the columns.

The weights, vector of means, and the covariance matrix are pre-loaded in your workspace as weights, vmeans, and sigma, respectively.

Este ejercicio forma parte del curso

Introduction to Portfolio Analysis in R

Ver curso

Instrucciones del ejercicio

  • Convert weights to a matrix called w using as.matrix().
  • Convert the vector of means (vmeans) to a matrix called mu using as.matrix().
  • Calculate portfolio mean monthly return. Remember the function t() transposes a vector.
  • Calculate the portfolio volatility.

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

# Create a weight matrix w


# Create a matrix of returns


# Calculate portfolio mean monthly returns


# Calculate portfolio volatility
sqrt(t(___) %*% ___ %*% ___)
Editar y ejecutar código