# Linear Asset Pricing Models¶

class LinearFactorModel(portfolios, factors, *, risk_free=False, sigma=None)[source]

Linear factor model estimator

Parameters
• portfolios (array-like) – Test portfolio returns (nobs by nportfolio)

• factors (array-like) – Priced factor returns (nobs by nfactor)

• risk_free (bool, optional) – Flag indicating whether the risk-free rate should be estimated from returns along other risk premia. If False, the returns are assumed to be excess returns using the correct risk-free rate.

• sigma (array-like, optional) – Positive definite residual covariance (nportfolio by nportfolio)

Notes

Implements a 2-step estimator of risk premia, factor loadings and model tests.

The first stage model estimated is

$r_{it} = c_i + f_t \beta_i + \epsilon_{it}$

where $$r_{it}$$ is the return on test portfolio i and $$f_t$$ are the traded factor returns. The parameters $$c_i$$ are required to allow non-traded to be tested, but are not economically interesting. These are not reported.

The second stage model uses the estimated factor loadings from the first and is

$\bar{r}_i = \lambda_0 + \hat{\beta}_i^\prime \lambda + \eta_i$

where $$\bar{r}_i$$ is the average excess return to portfolio i and $$\lambda_0$$ is only included if estimating the risk-free rate. GLS is used in the second stage if sigma is provided.

The model is tested using the estimated values $$\hat{\alpha}_i=\hat{\eta}_i$$.

fit(cov_type='robust', debiased=True, **cov_config)[source]

Estimate model parameters

Parameters
• cov_type (str, optional) – Name of covariance estimator

• debiased (bool, optional) – Flag indicating whether to debias the covariance estimator using a degree of freedom adjustment

• **cov_config – Additional covariance-specific options. See Notes.

Returns

results – Results class with parameter estimates, covariance and test statistics

Return type

LinearFactorModelResults

Notes

The kernel covariance estimator takes the optional arguments kernel, one of ‘bartlett’, ‘parzen’ or ‘qs’ (quadratic spectral) and bandwidth (a positive integer).

classmethod from_formula(formula, data, *, portfolios=None, risk_free=False, sigma=None)[source]
Parameters
• formula (str) – Patsy formula modified for the syntax described in the notes

• data (DataFrame) – DataFrame containing the variables used in the formula

• portfolios (array-like, optional) – Portfolios to be used in the model. If provided, must use formula syntax containing only factors.

• risk_free (bool, optional) – Flag indicating whether the risk-free rate should be estimated from returns along other risk premia. If False, the returns are assumed to be excess returns using the correct risk-free rate.

• sigma (array-like, optional) – Positive definite residual covariance (nportfolio by nportfolio)

Returns

model – Model instance

Return type

LinearFactorModel

Notes

The formula can be used in one of two ways. The first specified only the factors and uses the data provided in portfolios as the test portfolios. The second specified the portfolio using + to separate the test portfolios and ~ to separate the test portfolios from the factors.

Examples

>>> from linearmodels.datasets import french
>>> from linearmodels.asset_pricing import LinearFactorModel
>>> formula = 'S1M1 + S1M5 + S3M3 + S5M1 + S5M5 ~ MktRF + SMB + HML'
>>> mod = LinearFactorModel.from_formula(formula, data)


Using only factors

>>> portfolios = data[['S1M1', 'S1M5', 'S3M1', 'S3M5', 'S5M1', 'S5M5']]
>>> formula = 'MktRF + SMB + HML'
>>> mod = LinearFactorModel.from_formula(formula, data, portfolios=portfolios)


## GMM Estimation of Linear Factor Models¶

class LinearFactorModelGMM(factors, portfolios, *, risk_free=False)[source]

GMM estimator of Linear factor models

Parameters
• portfolios (array-like) – Test portfolio returns (nobs by nportfolio)

• factors (array-like) – Priced factors values (nobs by nfactor)

• risk_free (bool, optional) – Flag indicating whether the risk-free rate should be estimated from returns along other risk premia. If False, the returns are assumed to be excess returns using the correct risk-free rate.

Notes

Implements a GMM estimator of risk premia, factor loadings and model tests.

The moments are

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

and

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

where $$r_{it}$$ is the return on test portfolio i and $$f_t$$ are the factor returns.

The model is tested using the optimized objective function using the usual GMM J statistic.

fit(center=True, use_cue=False, steps=2, disp=10, max_iter=1000, cov_type='robust', debiased=True, **cov_config)[source]

Estimate model parameters

Parameters
• center (bool, optional) – Flag indicating to center the moment conditions before computing the weighting matrix.

• use_cue (bool, optional) – Flag indicating to use continuously updating estimator

• steps (int, optional) – Number of steps to use when estimating parameters. 2 corresponds to the standard efficient GMM estimator. Higher values will iterate until convergence or up to the number of steps given

• disp (int, optional) – Number of iterations between printed update. 0 or negative values suppresses output

• max_iter (int, positive, optional) – Maximum number of iterations when minimizing objective

• cov_type (str, optional) – Name of covariance estimator

• debiased (bool, optional) – Flag indicating whether to debias the covariance estimator using a degree of freedom adjustment

• **cov_config – Additional covariance-specific options. See Notes.

Returns

results – Results class with parameter estimates, covariance and test statistics

Return type

GMMFactorModelResults

Notes

The kernel covariance estimator takes the optional arguments kernel, one of ‘bartlett’, ‘parzen’ or ‘qs’ (quadratic spectral) and bandwidth (a positive integer).

classmethod from_formula(formula, data, *, portfolios=None, risk_free=False)[source]
Parameters
• formula (str) – Patsy formula modified for the syntax described in the notes

• data (DataFrame) – DataFrame containing the variables used in the formula

• portfolios (array-like, optional) – Portfolios to be used in the model. If provided, must use formula syntax containing only factors.

• risk_free (bool, optional) – Flag indicating whether the risk-free rate should be estimated from returns along other risk premia. If False, the returns are assumed to be excess returns using the correct risk-free rate.

Returns

model – Model instance

Return type

LinearFactorModelGMM

Notes

The formula can be used in one of two ways. The first specified only the factors and uses the data provided in portfolios as the test portfolios. The second specified the portfolio using + to separate the test portfolios and ~ to separate the test portfolios from the factors.

Examples

>>> from linearmodels.datasets import french
>>> from linearmodels.asset_pricing import LinearFactorModel
>>> formula = 'S1M1 + S1M5 + S3M3 + S5M1 + S5M5 ~ MktRF + SMB + HML'
>>> mod = LinearFactorModel.from_formula(formula, data)


Using only factors

>>> portfolios = data[['S1M1', 'S1M5', 'S3M1', 'S3M5', 'S5M1', 'S5M5']]
>>> formula = 'MktRF + SMB + HML'
>>> mod = LinearFactorModel.from_formula(formula, data, portfolios=portfolios)


## Linear Factor Models (Traded Factors)¶

class TradedFactorModel(portfolios, factors)[source]

Linear factor models estimator applicable to traded factors

Parameters
• portfolios (array-like) – Test portfolio returns (nobs by nportfolio)

• factors (array-like) – Priced factor returns (nobs by nfactor)

Notes

Implements both time-series estimators of risk premia, factor loadings and zero-alpha tests.

The model estimated is

$r_{it}^e = \alpha_i + f_t \beta_i + \epsilon_{it}$

where $$r_{it}^e$$ is the excess return on test portfolio i and $$f_t$$ are the traded factor returns. The model is directly tested using the estimated values $$\hat{\alpha}_i$$. Risk premia, $$\lambda_i$$ are estimated using the sample averages of the factors, which must be excess returns on traded portfolios.

fit(cov_type='robust', debiased=True, **cov_config)[source]

Estimate model parameters

Parameters
• cov_type (str, optional) – Name of covariance estimator

• debiased (bool, optional) – Flag indicating whether to debias the covariance estimator using a degree of freedom adjustment

• **cov_config (dict) – Additional covariance-specific options. See Notes.

Returns

results – Results class with parameter estimates, covariance and test statistics

Return type

LinearFactorModelResults

Notes

Supported covariance estimators are:

• ‘robust’ - Heteroskedasticity-robust covariance estimator

• ‘kernel’ - Heteroskedasticity and Autocorrelation consistent (HAC) covariance estimator

The kernel covariance estimator takes the optional arguments kernel, one of ‘bartlett’, ‘parzen’ or ‘qs’ (quadratic spectral) and bandwidth (a positive integer).

classmethod from_formula(formula, data, *, portfolios=None)[source]
Parameters
• formula (str) – Patsy formula modified for the syntax described in the notes

• data (DataFrame) – DataFrame containing the variables used in the formula

• portfolios (array-like, optional) – Portfolios to be used in the model

Returns

model – Model instance

Return type

Notes

The formula can be used in one of two ways. The first specified only the factors and uses the data provided in portfolios as the test portfolios. The second specified the portfolio using + to separate the test portfolios and ~ to separate the test portfolios from the factors.

Examples

>>> from linearmodels.datasets import french

>>> portfolios = data[['S1M1', 'S1M5', 'S3M1', 'S3M5', 'S5M1', 'S5M5']]