# Create a 3 by 3 covariance matrix to play with the accuracy of # first order approximations. C = matrix( c(3., 1., 1., 1., 3., 1., 1., 1., 3.), nrow = 3, ncol = 3) mu = c( 2., 1., 0.) w = c( .5, .5, 0.) sigsq_P = w %*% ( C %*% w ) cat("portfolio variance is", sigsq_P, "\n") mu_P = mu %*% w cat("portfolio expected return is", mu_P, "\n") dw = c(.01, 0., -.01) dsig_pred = w %*% ( C %*% dw ) dsig_true = (w+dw) %*% ( C %*% (w+dw) ) - sigsq_P cat("predicted change in variance is ", dsig_pred, ", actual change is ", dsig_true, "\n")