# Formulas and Mathematical Detail¶

There are \(N\) test portfolios, \(r_{t}\) (\(p\) by 1) which are usually assumed to be excess returns (zero-investment portfolios) and \(K\) factors, \(f_{t}\) (\(k\) by 1). For return series there are \(T\) observations.

## Linear Factor Model for Traded Factors¶

This model is a Seemingly Unrelated Regression (SUR). All models share the same regressors so that the model for test portfolio \(i\) is

Inference is based on the sandwich covariance estimator

Define \(f_{c,t}=\left[1\:f_{t}^{\prime}\right]^{\prime}\), then

and

Define the stacked vector of scores (or moment conditions)

If the heteroskedasticity robust estimator is used,

If the HAC estimator is used,

where \(K\left(\frac{i}{bw}\right)\) is a kernel weighting function and \(bw\) is the bandwidth. The reported risk premia are just the average returns on the factors, and the covariance of the risk premia estimates is based on the factor residuals after demeaning using either the simple estimator or the kernel estimator.

### The J statistic¶

The J statistic is implemented as

where \(\hat{\Sigma}_{\alpha}\) consists of rows and columns\(1,(k+1)+1,2(k+1)+1,\ldots\) of \(\hat{\Sigma}\).

## Linear Factor Model for Non-traded Factors¶

When factors are not traded, the SUR approach cannot be used since the expected value of the factor is not equal to its risk premium. One solution is to use a multi-step estimator. The first step regresses the test portfolio returns on the factors and a (throw-away) constant. This constant is included only to demean the factors to compute the correct factor loadings. The second stage then uses the estimated factor loadings and the average portfolio returns to estimate the risk premia. This second stage can be (optionally) improved by removing the effects of the demeaned factors from returns when computing risk premia.

The first stage regressions are virtually identical to the SUR regressions except the constant is no longer \(\alpha_{i}\),

The second stage regression then uses the estimated coefficients as regressors to estimate the risk premia,

Note that the residual from this regression\(\hat{\eta}_{i}=\hat{\alpha}_{i}\), the excess compensation test portfolio \(i\) is generating. If the risk free rate is assumed to be 0, then the column of 1s is not included and \(\lambda\) is \(K\) by 1.

Inference is conducted by treating this as a 3-step GMM problem where the first two steps were just described and the third estimated the model \(\hat{\alpha}\). The moment conditions corresponding to the FOC of these three steps are

where \(\epsilon_{it}=r_{it}^{e}-c_{i}-\beta_{i}f_{t}\) is \(N\) by 1 , \(\beta\) is \(N\) by \(K\), \(\lambda\) is \(K+1\) by 1 and\(\alpha\) is \(N\) by 1. Inference is based on

where the Jacobian \(G\) is estimated by

The block \(G_{21}\)is

When the risk free rate is 0, all terms of the form \([1_{N}\;\beta]\) become \(\beta\) and

\(S\) is an estimator of the covariance of the moment conditions, \(g_{t}\), and its form is identical to either the heteroskedasticity consistent estimator or the HAC estimator in the previous section.

### Improved Specification using GLS¶

The Jacobian is than

\(\beta_{c}=\left[1_{N}\,\beta\right]\). \(\tilde{\lambda}=\left[\lambda_{1},\ldots,\lambda_{K}\right]\) and so does not include the risk-free rate \(\lambda_{0}\) when included in the model. The final piece has the structure

where \(\tilde{\beta}_{c,i}\) is row \(i\) of \(\Sigma^{-1}\beta_{c}\), \(\bar{u}_{i}=T^{-1}\sum_{t=1}^{T}\tilde{u}_{it}\) and \(\tilde{u}_{it}\) is the element in position \(i\) of \(\tilde{u}_{t}=\Sigma^{-1}\left(r_{t}-\lambda_{0}-\beta\tilde{\lambda}\right)\). Each block has a 0 columns corresponding to \(c_{i}\).

\(S\) is an estimator of the covariance of the moment conditions, \(g_{t}\), and its form is identical to either the heteroskedasticity consistent estimator or the HAC estimator in the previous section.

### The J statistic¶

The J statistic is virtually identical to the \(J\) statistic from traded factor model except that it has a difference distribution.

The loss of degrees of freedom occurs since \(\hat{\alpha}=\hat{\eta}\) which are regression residuals from a regression of \(N\) average returns on \(K\) factor loadings. \(\hat{\Sigma}_{\alpha}\) is the bottom right \(K\times K\) block of \(\hat{\Sigma}\).

## GMM Estimation of Linear Factor Models¶

The GMM estimator solves a set of non-linear moment conditions of the form

where

is the vector of pricing errors. The factors can be traded or non-traded. This assumes that the model for expected returns is

so that the risk-free rate might not be zero. This form is sometimes used with excess returns if there is doubt about the risk-free rate used. The Jacobian is then

\(S\) is an estimator of the covariance of the moment conditions, \(g_{t}\), and its form is identical to either the heteroskedasticity consistent estimator or the HAC estimator in the previous section. The parameter covariance estimator uses the form appropriate for efficient GMM,

Sources used in writing the code include [Bryzgalova], [Cochrane] and [JagannathanEtAl].