*! version 1.0.0 03may2013

Title

varrets -- Calculates the expected variance-covariance matrix of a series of financial returns.

Syntax

varrets varlist [if] [in]
[,options]

weightvar(varname) if this option is specified, then the variable varname will be used as the specific weights for each observations, which
will be used to compute the expected returns of the variables specified in varlist.

leweight(#) indicates the lamda value to be used to calculate weights for all observations according to the exponentially
weighted moving average (EWMA) method. The values for lamda must be greater than 0 and less than 1. (1-lamda) will be the initial weight for the
more recent observation, while the lamda value will be exponentially assigned to all other observations. The weights will decay
exponentially for old observations, so the most recent observations will have more weight for the calculation of the expected return.
See Alexander(2008) for details of the EWMA method. If the options weightvar(varname) and leweight(#) are not used, then equal weights will be used for each observation.

casewise specifies casewise deletion of observations. The var-cov matrix is
to be computed for the sample that is not missing for any of the variables in varlist.
If casewise is not specified, then all variances are computed independently, and the covariances are computed by pair of returns, so all possible return data is used.
If casewise is specified, then only observations with no missing values in all returns are be used to calculate the variance-covariance matrix.
The default is to use all the nonmissing values for each variable.

Description

varrets calculates the expected variance-covariance matrix given a set of financial instrument or returns specified in
varlist. The varlist must be a list of continuously compounded returns of financial instruments.
Unlike the Stata correlate command with the cov option, this command can calculate pairwise covariances when the casewise option is omitted. When the casewise option
is used, then this command calculates the same variance-covariance matrix than the Stata correlate command with the cov option.
The expected variance-covariance matrix can be calculated assigning weights for each period/observation. With the leweight(#) option,
weights for each period are generated according to the EWMA method, and these weights are used to calculate the expected variance-covariance matrix.
If the weightvar(varname) is used, then the an existing variable is used to weight each period/observation and then estimate the
expected variance-covariance matrix.

Remarks

Check the "Also See" Menu for related commands.
The return variables must be continuously compounded returns, not simple returns.

Examples

Collect online monthly stock data (adjusted prices) from Yahoo Finance with the user command returnsyh. This command also calculates simple and continuous compounded returns:

. returnsyh AAPL MSFT GE, fm(1) fd(1) fy(2012) lm(12) ld(31) ly(2015) frequency(m) price(adjclose)

Calculates the expected variance-covariance matrix of 3 asset returns (continuously compounded):

. varrets r_AAPL r_MSFT r_GE

Calculates the expected variance-covariance matrix of 3 asset returns assigning exponential weights for each observation according to the Exponential Weighted Moving Average method with a lamda=0.94:

. varrets r_AAPL r_MSFT r_GE, leweight(0.94)

The weights for each observation according to the EWMA method were stored in the r(W) matrix. The weights are adjusted so that the sum of all weights must be equal to one.

. matrix list r(W)

Calculates the expected variance-covariance matrix of 3 asset returns using an existing variable to weight each observation:

. varrets r_AAPL r_MSFT r_GE, weightvar(vol_AAPL)

Stored results

varrets saves results in r() in the following scalars, matrices/vectors:

Scalars

r(N): number of observations used for computations

Matrices

r(cov): (n x n) matrix of expected variance-covariances of returns

r(W): (n x 1) vector of weights assigned to each observation. These weights were used to compute the variance-covariance matrix

References:

Alexander, Carol (2008): Moving Average Models for Volatility and Correlation, and Covariance Matrices. Handbook of Finance. III:5:62.

Author

Carlos Alberto Dorantes, Tecnológico de Monterrey, Querétaro Campus, Querétaro, México.
Email: cdorante@itesm.mx