Skip to content

Asset pricing

Tests of factor models: GRS and Fama-MacBeth

Whether factors price a set of test assets: the Gibbons-Ross-Shanken F test that every alpha is zero, and Fama-MacBeth two-pass regressions with Fama-MacBeth and Shanken-corrected standard errors.

Model id
asset_pricing.factor_model_tests, version 1
Domain
Asset pricing
Evidence
standard
Cost class
light: A short numerical method; a hosted run may take up to 10 seconds.

Formula

rit=αi+βi′ft+eitr_{it} = \alpha_i + \beta_i' f_t + e_{it}W=T−N−LNα^′Σ^−1α^1+fˉ′Ω^−1fˉ∼F(N,T−N−L)W = \frac{T - N - L}{N} \frac{\hat\alpha' \hat\Sigma^{-1} \hat\alpha}{1 + \bar f' \hat\Omega^{-1} \bar f} \sim F(N, T - N - L)rt=γ0t+B^γt+ηtr_t = \gamma_{0t} + \hat B \gamma_t + \eta_tγ^=1T∑tγ^t,s(γ^)=sd(γ^t)T\hat\gamma = \frac{1}{T}\sum_t \hat\gamma_t, \quad s(\hat\gamma) = \frac{\mathrm{sd}(\hat\gamma_t)}{\sqrt{T}}V^S=1T[(1+γ^′Σ^f−1γ^) AΣ^A′+Σ^f∗]\hat V_S = \tfrac{1}{T}\left[(1 + \hat\gamma'\hat\Sigma_f^{-1}\hat\gamma)\, A \hat\Sigma A' + \hat\Sigma_f^*\right]A=(X′X)−1X′A = (X'X)^{-1}X'

Where

ritr_{it}
Excess return of test asset i in period t returns
αi\alpha_i
Asset i's alpha: the average excess return its betas leave unexplained alphas
βi\beta_i
Asset i's betas on the factors betas
ftf_t
The factors' returns in period t factors
eite_{it}
Asset i's residual in period t
WW
The GRS statistic statistic
TT
Number of periods observations
NN
Number of test assets numerator_degrees_of_freedom
LL
Number of factors
Σ^\hat\Sigma
Estimated covariance matrix of the residuals
fˉ\bar f
The factors' average returns
Ω^\hat\Omega
Estimated covariance matrix of the factors
γ0t\gamma_{0t}
The cross-sectional constant in period t: the zero-beta excess return intercept
B^\hat B
The assets' estimated betas, one row for each asset betas
γt\gamma_t
The factors' premia in period t's cross-sectional regression
γ^\hat\gamma
The factors' average premia over the periods premia
s(γ^)s(\hat\gamma)
Fama-MacBeth standard errors of the premia premium_standard_errors
ηt\eta_t
The cross-sectional residuals in period t
V^S\hat V_S
Covariance of the premia with Shanken's correction; its diagonal gives the corrected standard errors shanken_standard_errors
Σ^f\hat\Sigma_f
Estimated covariance matrix of the factors, in the correction
XX
The matrix of betas, with a column of ones when a constant is included

Each symbol's field is named beside it; the inputs and outputs, with their units and bounds, are under Variables, and the citations give each formula's source.

Variables

Rates, returns and yields are decimals: 0.05 is five percent. Bounds in brackets include their end; in parentheses they exclude it.

Inputs

The Gibbons-Ross-Shanken test that every alpha is zero (grs): 4 inputs
Inputs of the calculation grs
NameDescription
Returnsreturnsreturn (array) (array) · length min 3, max 2520; each length min 1, max 100; each [-10, 10]The test assets' returns, as rows: one per period, one value per asset; excess returns when risk_free is left out
Factorsfactorsreturn (array) (array) · length min 3, max 2520; each length min 1, max 10; each [-10, 10]The factors' returns, as rows: one per period, one value per factor. Each is the excess return of a traded portfolio
Risk freerisk_freereturn (array) · each [-10, 10]The risk-free return each period, subtracted from every asset's return; leave it out when returns are already excess returns
CalculationcalculationtextThe Gibbons-Ross-Shanken test that every alpha is zero
Fama-MacBeth two-pass regressions of returns on betas (fama_macbeth): 5 inputs
Inputs of the calculation fama_macbeth
NameDescription
Returnsreturnsreturn (array) (array) · length min 3, max 2520; each length min 1, max 100; each [-10, 10]The test assets' returns, as rows: one per period, one value per asset; excess returns when risk_free is left out
Factorsfactorsreturn (array) (array) · length min 3, max 2520; each length min 1, max 10; each [-10, 10]The factors' returns, as rows: one per period, one value per factor. Each is the excess return of a traded portfolio
Risk freerisk_freereturn (array) · each [-10, 10]The risk-free return each period, subtracted from every asset's return; leave it out when returns are already excess returns
CalculationcalculationtextFama-MacBeth two-pass regressions of returns on betas
InterceptinterceptflagInclude a constant in each cross-sectional regression: the zero-beta excess return; without it the constant is held at zero

Outputs

The Gibbons-Ross-Shanken test that every alpha is zero (grs): 9 outputs
Outputs of the calculation grs
NameDescription
CalculationcalculationtextThe Gibbons-Ross-Shanken test that every alpha is zero
Statisticstatisticratio · [0, 1e+12]The GRS F statistic
P valuep_valueprobability · [0, 1]The chance of a statistic at least this large if every alpha is zero
Numerator degrees of freedomnumerator_degrees_of_freedomcount · [1, 100]N, the test assets
Denominator degrees of freedomdenominator_degrees_of_freedomcount · [1, 2520]T - N - L
Alphasalphasreturn (array) · length max 100; each [-1e+09, 1e+09]Each asset's alpha per period
Mean absolute alphamean_absolute_alphareturn · [0, 1e+09]The average absolute alpha per period
Factor sharpe ratiofactor_sharpe_ratioratio · [0, 1e+06]The highest Sharpe ratio per period of a portfolio of the factors, sqrt(f' Omega^-1 f)
Observationsobservationscount · [3, 2520]T, the periods
Fama-MacBeth two-pass regressions of returns on betas (fama_macbeth): 12 outputs
Outputs of the calculation fama_macbeth
NameDescription
CalculationcalculationtextFama-MacBeth two-pass regressions of returns on betas
Premiapremiareturn (array) · length max 10; each [-1e+09, 1e+09]Each factor's average premium per period, in order
Premium standard errorspremium_standard_errorsreturn (array) · length max 10; each [0, 1e+09]Fama-MacBeth standard errors of the premia
Premium t statisticspremium_t_statisticsratio (array) · length max 10; each [-1e+09, 1e+09]The premia over their standard errors
Shanken standard errorsshanken_standard_errorsreturn (array) · length max 10; each [0, 1e+09]The standard errors with Shanken's errors-in-variables correction
Shanken t statisticsshanken_t_statisticsratio (array) · length max 10; each [-1e+09, 1e+09]The premia over the corrected errors
Interceptinterceptreturn · [-1e+09, 1e+09]The average cross-sectional constant per period: the zero-beta excess return; None without one
Intercept standard errorintercept_standard_errorreturn · [0, 1e+09]Its Fama-MacBeth standard error; None without a constant
Intercept t statisticintercept_t_statisticratio · [-1e+09, 1e+09]The constant over its error; None without one, or when the cross-sections fit exactly
Shanken intercept standard errorshanken_intercept_standard_errorreturn · [0, 1e+09]The constant's error with Shanken's correction; None without one
Betasbetasratio (array) (array) · length max 100; each length min 1, max 10; each [-1e+09, 1e+09]Each asset's time-series betas on the factors, as rows
Observationsobservationscount · [3, 2520]T, the periods

Calculator

Run the model on your own inputs, starting from its example. Rates are decimals: 0.05 is five percent. The run goes to the pyeconomics API on this site: your values travel only in the request, and nothing is stored.

Live data runs on your own computer only

This model reads Twenty-five size and book-to-market portfolios, monthly, Fama-French three factors, monthly and Risk-free return, monthly. Their source, Ken French Data Library, lets pyeconomics read the data on your own computer but not serve them from this website.

Here, enter your own values, or bring them as a file with "Use my own data". To run this page with every profile's live data, install the local app and start it: pip install "pyeconomics[app]" then pyeconomics serve.

Loading the calculator…

Worked example

Ten periods of three test assets on two factors.

Example grs_three_assets. Inputs:

{
  "calculation": "grs",
  "factors": [
    [0.018, 0.004],
    [-0.02, -0.006],
    [0.03, 0.011],
    [0.006, -0.002],
    [-0.025, 0.003],
    [0.012, 0.007],
    [0.022, -0.005],
    [-0.006, 0.001],
    [0.009, 0.002],
    [0.016, -0.004]
  ],
  "returns": [
    [0.021, 0.014, 0.009],
    [-0.013, -0.008, -0.017],
    [0.034, 0.027, 0.031],
    [0.008, 0.011, 0.002],
    [-0.022, -0.015, -0.026],
    [0.015, 0.012, 0.019],
    [0.027, 0.018, 0.024],
    [-0.004, 0.001, -0.009],
    [0.012, 0.009, 0.016],
    [0.019, 0.013, 0.011]
  ],
  "risk_free": null
}

Outputs:

{
  "alphas": [
    0.003626951897350706,
    0.003958339049657105,
    -0.00017271353267661488
  ],
  "calculation": "grs",
  "denominator_degrees_of_freedom": 5,
  "factor_sharpe_ratio": 0.3770794846595339,
  "mean_absolute_alpha": 0.002586001493228142,
  "numerator_degrees_of_freedom": 3,
  "observations": 10,
  "p_value": 0.003875249956778339,
  "statistic": 18.5100765311955
}

Assumptions

  • The factors are excess returns of traded portfolios, for GRS; the time-series betas are constant over the sample and estimated over the same periods as the cross-sections.
  • GRS is exact under normal errors independent over time, with the residual and factor covariances at divisor T; Fama-MacBeth errors treat the periods' estimates as independent draws.
  • Profiles: default binds 120 months of the Ken French 25 portfolios on size and book-to-market as test assets, the three-factor file's Mkt-RF, SMB and HML, and the risk-free return; ff5 binds the five-factor file's Mkt-RF, SMB, HML, RMW and CMA instead.

Limitations

  • Residuals or factors collinear to working precision (an asset that is a combination of the factors, a factor that barely varies), or betas that barely vary across the assets, leave the test or the premia undefined: DomainError, as for a statistic beyond 1e12 or an estimate beyond 1e9.
  • GRS has power only against the alternatives its assets span, and with many assets and few periods its size depends on normality. Fama-MacBeth errors ignore autocorrelation in the premia.
  • The Ken French portfolios and factors are library-only: fetched at run time and never stored. A bound window ends at the library's latest month on or before the date.

Evidence

Status: standard. Textbook consensus, such as bond duration or the CAPM formula.

Every model declares one status: standard (textbook consensus), practitioner (a widely used convention), contested (under active debate), rejected (failed out of sample) or historical (a superseded methodology).

Syllabus

The 2027 CFA® Program's topic areas this model relates to, as factual tags. Each links to CFA Institute's page for its level; pyeconomics holds none of the curriculum's text.

Data

This model can read its data for you: each bound field names a data series, and the sources listed can fill it, in the order they are tried. This website reads only the sources whose terms let it serve their data (marked "hosted"); every source is available when you run pyeconomics on your own computer.

Profile: Default
FieldConceptRead asSources (licence class; hosted)
returnsTwenty-five size and book-to-market portfolios, monthlyportfolios.size_bm25.us.monthlythe last 120 observations on or before the date; real time: as published by the date
  • Ken French Data Library (library-only; not hosted)
factorscolumns Mkt-RF, SMB, HMLFama-French three factors, monthlyfactors.ff3.us.monthlythe last 120 observations on or before the date; real time: as published by the date
  • Ken French Data Library (library-only; not hosted)
risk_freeRisk-free return, monthlyfactors.risk_free.us.monthlythe last 120 observations on or before the date; real time: as published by the date
  • Ken French Data Library (library-only; not hosted)
Profile: Fama-French five factors (ff5)
FieldConceptRead asSources (licence class; hosted)
returnsTwenty-five size and book-to-market portfolios, monthlyportfolios.size_bm25.us.monthlythe last 120 observations on or before the date; real time: as published by the date
  • Ken French Data Library (library-only; not hosted)
factorscolumns Mkt-RF, SMB, HML, RMW, CMAFama-French five factors, monthlyfactors.ff5.us.monthlythe last 120 observations on or before the date; real time: as published by the date
  • Ken French Data Library (library-only; not hosted)
risk_freeRisk-free return, monthlyfactors.risk_free.us.monthlythe last 120 observations on or before the date; real time: as published by the date
  • Ken French Data Library (library-only; not hosted)

Citations

  1. Gibbons, M. R., Ross, S. A. and Shanken, J. (1989). A Test of the Efficiency of a Given Portfolio. Econometrica, 57(5), 1121-1152. doi:10.2307/1913625 (Eq. (5), p. 1124, for one portfolio; the statistic for L portfolios and its F(N, T - N - L) distribution, p. 1146)
  2. Fama, E. F. and MacBeth, J. D. (1973). Risk, Return, and Equilibrium: Empirical Tests. Journal of Political Economy, 81(3), 607-636. doi:10.1086/260061 (Eq. (10), p. 616, the monthly cross-sections; p. 619, the t statistic of their average)
  3. Shanken, J. (1992). On the Estimation of Beta-Pricing Models. The Review of Financial Studies, 5(1), 1-33. doi:10.1093/rfs/5.1.1 (Theorem 1 and the corrected Fama-MacBeth covariance, eq. (11), of the 1991 working paper (University of Rochester MR 91-06), pp. 15-18)
  4. Cochrane, J. H. (2005). Asset Pricing, revised edition, ch. 12: Regression-Based Tests of Linear Factor Models. Princeton University Press. https://www.johnhcochrane.com/s/Cochrane_asset_pricing_CH12_229-250.pdf (Eq. (12.6), p. 233, GRS with both covariances at divisor T; eq. (12.19), p. 240; the Fama-MacBeth variance, p. 246)
  5. Goyal, A. (2012). Empirical cross-sectional asset pricing: a survey. Financial Markets and Portfolio Management, 26(1), 3-38. doi:10.1007/s11408-011-0177-7 (Eq. (32), p. 13, the Fama-MacBeth variance; eq. (33), p. 14, Shanken's corrected form)
  6. French, K. R. Data Library: the Fama/French factors and the 25 portfolios formed on size and book-to-market, monthly. Tuck School of Business, Dartmouth College. https://mba.tuck.dartmouth.edu/pages/faculty/ken.french/data_library.html (Fama/French 3 Factors, 5 Factors (2x3) and 25 Portfolios Formed on Size and Book-to-Market (5 x 5))

Changelog

  • Version 1: First version.

Use it elsewhere

Documentation
The model's reference page
REST API
GET or POST /v1/models/asset_pricing.factor_model_tests/run
MCP tool
run_model with the model's id, asset_pricing.factor_model_tests. Connect an assistant
Command line
pyeconomics models run asset_pricing.factor_model_tests --help

The worked example, from Python and from the command line:

Python
import pyeconomics

inputs = {
    "calculation": "grs",
    "factors": [
        [0.018, 0.004],
        [-0.02, -0.006],
        [0.03, 0.011],
        [0.006, -0.002],
        [-0.025, 0.003],
        [0.012, 0.007],
        [0.022, -0.005],
        [-0.006, 0.001],
        [0.009, 0.002],
        [0.016, -0.004],
    ],
    "returns": [
        [0.021, 0.014, 0.009],
        [-0.013, -0.008, -0.017],
        [0.034, 0.027, 0.031],
        [0.008, 0.011, 0.002],
        [-0.022, -0.015, -0.026],
        [0.015, 0.012, 0.019],
        [0.027, 0.018, 0.024],
        [-0.004, 0.001, -0.009],
        [0.012, 0.009, 0.016],
        [0.019, 0.013, 0.011],
    ],
    "risk_free": None,
}
result = pyeconomics.run("asset_pricing.factor_model_tests", inputs)
print(result.to_json())
Command line
pyeconomics models run asset_pricing.factor_model_tests --inputs - <<'JSON'
{
  "calculation": "grs",
  "factors": [
    [0.018, 0.004],
    [-0.02, -0.006],
    [0.03, 0.011],
    [0.006, -0.002],
    [-0.025, 0.003],
    [0.012, 0.007],
    [0.022, -0.005],
    [-0.006, 0.001],
    [0.009, 0.002],
    [0.016, -0.004]
  ],
  "returns": [
    [0.021, 0.014, 0.009],
    [-0.013, -0.008, -0.017],
    [0.034, 0.027, 0.031],
    [0.008, 0.011, 0.002],
    [-0.022, -0.015, -0.026],
    [0.015, 0.012, 0.019],
    [0.027, 0.018, 0.024],
    [-0.004, 0.001, -0.009],
    [0.012, 0.009, 0.016],
    [0.019, 0.013, 0.011]
  ],
  "risk_free": null
}
JSON