
Formulas and Mathematical Detail
================================

There are :math:`N` test portfolios, :math:`r_{t}` (:math:`p` by 1)
which are usually assumed to be excess returns (zero-investment
portfolios) and :math:`K` factors, :math:`f_{t}` (:math:`k` by 1). For
return series there are :math:`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 :math:`i` is

.. math:: r_{it}=\alpha_{i}+\beta_{i}f_{t}+\epsilon_{it}.

Inference is based on the sandwich covariance estimator

.. math:: \hat{\Sigma}=\left(T-df\right)^{-1}G^{-1}SG^{-1}.

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

.. math:: \hat{G}=I_{N}\otimes\Sigma_{f_{c}}

and

.. math:: \Sigma_{f_{c}}=T^{-1}\sum_{t=1}^{T}f_{c,t}f_{c,t}^{\prime}

Define the stacked vector of scores (or moment conditions)

.. math:: g_{t}=\left[f_{c}\otimes\hat{\epsilon}_{t}\right].

If the heteroskedasticity robust estimator is used,

.. math:: \hat{S}=T^{-1}\sum_{t=1}^{T}g_{t}g_{t}^{\prime}.

If the HAC estimator is used,

.. math::

   \begin{aligned}
   \hat{S} & =T^{-1}\left\{ \hat{\Gamma}_{0}+\sum_{i=1}^{bw}K\left(\frac{i}{bw}\right)\left(\hat{\Gamma}_{i}+\hat{\Gamma}_{i}^{\prime}\right)\right\} \\
   \hat{\Gamma}_{j} & =\sum_{t=j+1}^{T}g_{t}g_{t-j}^{\prime}\end{aligned}

where :math:`K\left(\frac{i}{bw}\right)` is a kernel weighting function
and :math:`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

.. math:: J=\hat{\alpha}^{\prime}\hat{\Sigma}_{\alpha}^{-1}\hat{\alpha}^{\prime}\sim\chi_{N}^{2}

where :math:`\hat{\Sigma}_{\alpha}` consists of rows and
columns\ :math:`1,(k+1)+1,2(k+1)+1,\ldots` of :math:`\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 :math:`\alpha_{i}`,

.. math:: r_{it}^{e}=c_{i}+\beta_{i}f_{t}+\epsilon_{it}.

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

.. math:: \bar{r}_{i}^{e}=\left[1_{N}\,\hat{\beta}\right]\lambda+\eta_{i}.

Note that the residual from this
regression\ :math:`\hat{\eta}_{i}=\hat{\alpha}_{i}`, the excess
compensation test portfolio :math:`i` is generating. If the risk free
rate is assumed to be 0, then the column of 1s is not included and
:math:`\lambda` is :math:`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 :math:`\hat{\alpha}`. The moment conditions corresponding to the
FOC of these three steps are

.. math::

   g_{t}=\left[\begin{array}{c}
   f_{c,t}\otimes\epsilon_{t}\\
   \left[1_{N}\,\beta\right]^{\prime}\left(r_{t}-\left[1_{N}\,\beta\right]\lambda\right)\\
   r_{t}-\left[1_{N}\,\beta\right]\lambda-\alpha
   \end{array}\right]

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

.. math:: \hat{\Sigma}=\left(T-df\right)^{-1}G^{-1}S\left(G^{-1}\right)^{\prime}

where the Jacobian :math:`G` is estimated by

.. math::

   \hat{G}=-\left[\begin{array}{ccc}
   I_{N}\otimes\Sigma_{f_{c}} & 0 & 0\\
   G_{21} & \left[1_{N}\,\hat{\beta}\right]^{\prime}\left[1_{N}\,\hat{\beta}\right] & 0\\
   I_{N}\otimes\left[0\ \hat{\lambda}\right] & \left[1_{N}\,\hat{\beta}\right] & I_{N}
   \end{array}\right]

The block :math:`G_{21}`\ is

.. math:: G_{21}=\left[G_{21,1}\ G_{21,2}\:\ldots\ G_{21,N}\right]

.. math:: G_{21,i}=\left[0_{\left(K+1\right)\times1}\;\left(\left[1\;\hat{\beta}_{i}\right]^{\prime}\lambda^{\prime}-\left[0_{K}\;\bar{u}_{i}I_{K}\right]^{\prime}\right)\right]

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

.. math:: G_{21,i}=\left[0_{K\times1}\;\left(\hat{\beta}_{i}^{\prime}\lambda^{\prime}-\;\bar{u}_{i}I_{K}\right)\right]

:math:`S` is an estimator of the covariance of the moment conditions,
:math:`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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. math::

   \left[\begin{array}{c}
   f_{c,t}\otimes\epsilon_{t}\\
   \beta_{c}^{\prime}\Sigma^{-1}\left(r_{t}-\beta_{c}\lambda\right)\\
   r_{t}-\beta_{c}\lambda-\alpha
   \end{array}\right]

The Jacobian is than

.. math::

   \hat{G}=-\left[\begin{array}{ccc}
   I_{N}\otimes\Sigma_{f_{c}} & 0 & 0\\
   G_{12} & \hat{\beta}_{c}^{\prime}\Sigma^{-1}\hat{\beta}_{c} & 0\\
   I_{N}\otimes\left[0\ \tilde{\lambda}\right] & \hat{\beta}_{c} & I_{N}
   \end{array}\right]

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

.. math:: G_{21}=\left[G_{21,1}\ G_{21,2}\:\ldots\ G_{21,N}\right]

.. math:: G_{21,i}=\left[0_{\left(K+1\right)}\;\tilde{\beta}_{c,i}^{\prime}\tilde{\lambda}^{\prime}-\left[0_{K}\;\bar{u}_{i}I_{K}\right]^{\prime}\right]

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

:math:`S` is an estimator of the covariance of the moment conditions,
:math:`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 :math:`J` statistic from
traded factor model except that it has a difference distribution.

.. math:: J=\hat{\alpha}^{\prime}\hat{\Sigma}_{\alpha}^{-1}\hat{\alpha}^{\prime}\sim\chi_{N-K}^{2}

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

GMM Estimation of Linear Factor Models
--------------------------------------

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

.. math::

   \left[\begin{array}{c}
   \epsilon_{t}\otimes f_{c,t}\\
   f_{t}-\mu
   \end{array}\right]

where

.. math:: \epsilon_{t}=r_{t}-\left[1_{N}\;\beta\right]\lambda-\beta\left(f_{t}-\mu\right)

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

.. math:: E\left[r_{it}\right]=\lambda_{0}+\sum_{i=1}^{k}\beta_{i}\lambda_{i}

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

.. math::

   \hat{G}=T^{-1}\sum_{t=1}^{T}-\left[\begin{array}{ccc}
   I_{N}\otimes\left(f_{t}-\mu+\tilde{\lambda}\right)f_{c,t} & \left[\begin{array}{c}
   f_{c,t}\left[1\!\hat{\beta}_{1}\right]\\
   \vdots\\
   f_{c,t}\left[1\!\hat{\beta}_{N}\right]
   \end{array}\right] & \left[\begin{array}{c}
   -f_{c,t}\hat{\beta}_{1}\\
   \vdots\\
   -f_{c,t}\hat{\beta}_{N}
   \end{array}\right]\\
   0 & 0 & I_{K}
   \end{array}\right]

:math:`S` is an estimator of the covariance of the moment conditions,
:math:`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,

.. math:: \hat{\Sigma}=\left(\hat{G}\hat{^{\prime}S}^{-1}\hat{G}\right)^{-1}.
