Code: Select all
' Generate bivariate mean zero normals
' Dick Startz
' April 2015
subroutine bivariateNormals(series e1,series e2,scalar sigma1,scalar sigma2,scalar rho)
' return series e1 and e2 with standard deviations sigma1 and sigma2 and correlation rho
' e1 and e2 must be defined as series in workfile. The other parameters are scalars.
if abs(rho)>1 then
seterr "correlation must be between -1 and 1"
e1 = sigma1*nrnd
e2 = sigma2*(rho*e1/sigma1 + @sqrt(1-rho^2)*nrnd)