Covariance matrix
In this lab you will learn to draw observations from bivariate normal distributions, and explore the resulting data to familiarize yourself with relationships between two random variables.
Let us assume that \(X\) and \(Y\) are bivariate normally distributed. Get started by defining a covariance matrix. Suppose that the standard deviations are \(\sigma_{X} = 0.10\) and \(\sigma_{Y} = 0.05\), and that the correlation is \(\rho_{XY} = 0.9\).
Matrices can be created with the matrix()
function. You should supply the
values as the first argument and specify the dimensions with the nrow
and
ncol
arguments. For example, matrix(c(-0.5, 0.5), nrow = 1, ncol = 2)
creates a matrix with one row and two columns. By default, the matrix is
filled column by column, but you can fill the matrix row by row by setting
byrow = TRUE
.
This exercise is part of the course
Intro to Computational Finance with R
Exercise instructions
- Compute the covariance between \(X\) and \(Y\) and assign it to
sig_xy
. - Construct the covariance matrix and assign it to
Sigma_xy
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Standard deviations and correlation
sig_x <- 0.10
sig_y <- 0.05
rho_xy <- 0.9
# Covariance between X and Y
sig_xy <-
# Covariance matrix
Sigma_xy <-