Skip to main content

getfactormodels

Python PyPI - Version PyPI - Status GitHub License

A CLI and Python library to download multi-factor asset pricing models.

Quick start

Install

Models

  • The 3-factor, 5-factor, and 6-factor models of Fama & French [1] [3] [4]
  • Mark Carhart's 4-factor model [2]
  • Pastor and Stambaugh's liquidity factors [5]
  • Mispricing factors of Stambaugh and Yuan[6]
  • The $q$-factor model of Hou, Mo, Xue and Zhang[7]
  • The augmented $q^5$-factor model of Hou, Mo, Xue and Zhang[8]
  • Intermediary Capital Ratio (ICR) of He, Kelly & Manela[9]
  • The DHS behavioural factors of Daniel, Hirshleifer & Sun[10]
  • The HML $^{DEVIL}$ factor of Asness & Frazzini[11]
  • Betting Against beta, A. Frazzini, L. Pedersen (2014) [12]
  • Quality Minus Junk, Asness, Frazzini & Pedersen (2017)[13]
  • The 6-factor model of Barillas and Shanken[14]

Thanks to: Kenneth French, Robert Stambaugh, Lin Sun, Zhiguo He, AQR Capital Management (AQR.com) and Hou, Xue and Zhang (global-q.org), for their research and for the datasets they provide.

Quick start

PyPI - Status

[!IMPORTANT] getfactormodels is pre-alpha (until version 0.1.0), don't rely on it for anything.

But a huge thanks to anyone who has tried it!

Install

Install getfactormodels via PyPI.

pip install getfactormodels

Usage

Examples of CLI usage:

Specify a model, and an optional frequency (default: m), and date range:

getfactormodels --model ff3 --frequency m --start 2010-01-01 --end 2020
  • see: --list-models

Download the Fama-French 5 Factor model for emerging markets, save to file:

getfactormodels -m ff5 -f m -s 2010-01 -e 2020 --region emerging --output 'ff5_emerging.csv'
  • Use --list-regions to see all available geographic regions and aliases.

Download a Global-Q anomaly testing portfolio (weekly, deciles for roe_6, ta)

getfactormodels --anomaly roe_6 ta --sort decile -f w -o '~/file.md'
  • see: --list-anomalies
  • -o / --output automatically detects format from extensions (.csv, .parquet, .feather).

Access JKP Global Factor data for a region:

getfactormodels -j age -r can --drop-nulls

Attach a JKP Global Factor to a Betting Against Beta model for Australia (since both have regional data available):

getfactormodels -m bab -r aus -j age

Combine the Liquidity, DHS Behavioural Factor models (of the same frequency), drop the NaNs and view the source data URLs:

getfactormodels -m liq dhs -f m -e 1999-12-31 --drop-nulls --url

Download the augmnented q5 model, and quintiles for a Global Q Anomaly testing portfolio:

getfactormodels -m q -f m -p abr_1 -n 5 -o `model.ipc`

Download a 2x3 size/OP sort (--sort/-n) from Kenneth French's data library:

getfactormodels -p size op --sort 2x3

Download a 5x5 sort on Inv and Book-to-Market using the --bivariate flag (defaults to 5x5 for inv/op)

getfactormodels -p 'inv, bm' -b

Download Fama-French industry data:

getfactormodels -p industry 38 --drop-nulls 'GOVT'
#or 
getfactormodels -I 38 --drop-null 'GOVT'

Drop columns:

getfactormodels -m ff3 -d SMB,RF 

Download Fama-French Breakpoint data:

# E/P
getfactormodels --bp ep 

#prior rets
getfactormodels --breakpoints prior 

Python Examples

from getfactormodels import model, portfolio

# Load Fama-French 3-factor monthly model
ff3 = model("ff3", frequency="m", start_date="2010-01-01")
ff3.load()


# Export to CSV
a.to_file("abr_1_data.parquet")

Model classes

from getfactormodels import FamaFrenchFactors

# Initialize model instance
m = FamaFrenchFactors(
    model="3", frequency="m", region="developed", start_date="2020-01-01"
)
m.end_date = "2020"

# Download the data
m = m.load()

# Access/download the Arrow Table:
table = m.data

# As a dataframe:
df = m.to_polars()  # Helper method, see also `.to_pandas()`
from getfactormodels import Qfactors, BABFactors

# Q Factors have a "classic" boolean, when true, returns the classic 4 factor model.
q = QFactors(classic=True, frequency='w').load()

# Extract the Japan Betting Against Beta daily 'BAB' factor:
bab_jpn_df = BABFactors(frequency='d', region='JPN', 
                        start='2000-02-20', end '2010').load().extract("BAB").to_polars()

Example:

getfactormodels -m qmj -f d --output qmj.ipc
View output
Data saved to: qmj.ipc

date            Mkt-RF           QMJ           SMB           HML           UMD    RF_AQR
1957-07-01    0.001784     -0.001566     -0.002166      0.001984      0.000651    0.0001
1957-07-02    0.008514     -0.000484     -0.005030     -0.004436      0.002705    0.0001
1957-07-03    0.007938      0.000869     -0.001245     -0.003676      0.002294    0.0001
1957-07-05    0.007755      0.001975     -0.000769     -0.002781     -0.001137    0.0001
  [...]
2025-10-28    0.001157      0.004138     -0.003897     -0.006681      0.011682    0.0002
2025-10-29   -0.002034     -0.003446     -0.007738     -0.002619      0.015875    0.0002
2025-10-30   -0.010841      0.009058     -0.000406      0.005180     -0.006211    0.0002
2025-10-31    0.003867     -0.006546      0.000620      0.001108      0.000869    0.0002

[17574 rows x 7 columns, 905.3 kb]

Python usage

  • getfactormodels uses PyArrow internally and supports the Dataframe Interchange Protocol, allowing for zero-copy data sharing with most modern Python data tools.

Create a model instance:

from getfactormodels import QFactors

m = getfactormodels.QFactors(frequency="m")
  • DuckDB can query a table without conversion
import duckdb

duckdb.sql("SELECT date, ROE, IA FROM m.data LIMIT 7").show()
  • Polars has first-class support for Arrow:
import polars as pl

df = pl.from_arrow(m.data)
  • Pandas/NumPy
# Pandas DataFrame
df = m.to_pandas()

# or NumPy Array (via Pandas)
array = m.to_pandas().to_numpy()
  • Libraries like Ibis, Modin or Vaex can use the dataframe interchange protocol directly:
df = vaex.from_arrow_table(m.data)
print(df.mean(vdf.ROE))

(back to top)

Availability

This table shows each model's start date, available frequencies, and the latest datapoint if not current. The id column contains the shortest identifier for each model. These should all work in python and the CLI.

id Factor Model Start D W M Q Y End
3 Fama-French 3 1926-07-01 ✓ ✓ ✓ ✓ -
4 Carhart 4 1926-11-03 ✓ ✓ ✓ -
5 Fama-French 5 1963-07-01 ✓ ✓ ✓ -
6 Fama-French 6 1963-07-01 ✓ ✓ ✓ -
icr ICR 1970-01-31
Daily: 1999-05-03
✓ ✓ ✓ 2025-06-27
dhs DHS 1972-07-03 ✓ ✓ 2024-12-31
mis Mispricing 1963-01-02 ✓ ✓ 2016-12-30
liq Liquidity 1962-08-31 ✓ 2025-12-31
q
q4
$q^5$-factors
$q$-factors
1967-01-03 ✓ ✓ ✓ $\checkmark$ ✓ 2024-12-31
hmld HML $^{DEVIL}$ 1926-07-01 ✓ ✓ 2025-10-31
qmj Quality Minus Junk 1957-07-01 ✓ ✓ 2025-10-31
bab Betting Against beta 1930-12-01 ✓ ✓ 2025-10-31
bs Barillas-Shanken 6 1967-01-03 ✓ ✓ 2024-12-31
ch3 Size and Value in China (CH-3) 2000-01-04 ✓ ✓ 2026-08-31
ch4 Size and Value in China (CH-4) 2000-01-04 ✓ ✓ 2026-08-31
  • Fama-French: data up until until end of prior month.
  • Fama-French: most international/emerging factors (accessed with the region param) begin between 1985-1990.
  • AQR models: non-US data begins around 1990 (accessed with the country param).
  • Size and Value in China models are only available for China. region= must be ch, china or None (--region ch)
  • getfactormodels has two conditional CAPM (CCAPM) models: a High-Income/Affluent CCAPM (annual, 1927-2022) from Campbell & Korniotis (2013)[15], and an implementation of the Premium-Labor CCAPM (m, q, y; data from 1959-04-30) from Jagganathan & Wang (1996)[16]

References

Publications:

  1. E. F. Fama and K. R. French, ‘Common risk factors in the returns on stocks and bonds’, Journal of Financial Economics, vol. 33, no. 1, pp. 3–56, 1993. PDF
  2. M. Carhart, ‘On Persistence in Mutual Fund Performance’, Journal of Finance, vol. 52, no. 1, pp. 57–82, 1997. PDF
  3. E. F. Fama and K. R. French, ‘A five-factor asset pricing model’, Journal of Financial Economics, vol. 116, no. 1, pp. 1–22, 2015. PDF
  4. E. F. Fama and K. R. French, ‘Choosing factors’, Journal of Financial Economics, vol. 128, no. 2, pp. 234–252, 2018. PDF
  5. L. Pastor and R. Stambaugh, ‘Liquidity Risk and Expected Stock Returns’, Journal of Political Economy, vol. 111, no. 3, pp. 642–685, 2003. PDF
  6. R. F. Stambaugh and Y. Yuan, ‘Mispricing Factors’, The Review of Financial Studies, vol. 30, no. 4, pp. 1270–1315, 12 2016. PDF
  7. K. Hou, H. Mo, C. Xue, and L. Zhang, ‘Which Factors?’, National Bureau of Economic Research, Inc, 2014. PDF
  8. K. Hou, H. Mo, C. Xue, and L. Zhang, ‘An Augmented q-Factor Model with Expected Growth*’, Review of Finance, vol. 25, no. 1, pp. 1–41, 02 2020. PDF
  9. Z. He, B. Kelly, and A. Manela, ‘Intermediary asset pricing: New evidence from many asset classes’, Journal of Financial Economics, vol. 126, no. 1, pp. 1–35, 2017. PDF
  10. K. Daniel, D. Hirshleifer, and L. Sun, ‘Short- and Long-Horizon Behavioral Factors’, Review of Financial Studies, vol. 33, no. 4, pp. 1673–1736, 2020. PDF
  11. C. Asness and A. Frazzini, ‘The Devil in HML’s Details’, The Journal of Portfolio Management, vol. 39, pp. 49–68, 2013. PDF
  12. A. Frazzini and L. H. Pedersen, “Betting Against Beta,” Journal of Financial Economics, vol. 111, no. 1, pp. 1–25, Jan. 2014. EconPapersPDF (working paper)
  13. C. S. Asness, A. Frazzini, and L. H. Pedersen, “Quality Minus Junk,” Review of Accounting Studies, vol. 24, no. 1, pp. 34–112, Nov. 2019. EconPapers PDF
  14. F. Barillas and J. Shanken, ‘Comparing Asset Pricing Models’, Journal of Finance, vol. 73, no. 2, pp. 715–754, 2018. PDF
  15. S. D. Campbell and G. M. Korniotis, "The Human Capital That Matters: Expected Returns and the Income of Affluent Households," Finance and Economics Discussion Series, BiblioGov, 2013. Web
  16. R. Jagannathan and Z. Wang, ‘The Conditional CAPM and the Cross-Section of Expected Returns’, The Journal of Finance, vol. 51, no. 1, pp. 3–53, Mar. 1996.

Data sources:

  • K. French, "Data Library," Tuck School of Business at Dartmouth. Link
  • R. Stambaugh, "Liquidity" and "Mispricing" factor datasets, Wharton School, University of Pennsylvania. Link
  • Z. He, "Intermediary Capital Ratio and Risk Factor" dataset, zhiguohe.net. Link
  • K. Hou, G. Xue, R. Zhang, "The Hou-Xue-Zhang q-factors data library," at global-q.org. Link
  • AQR Capital Management's Data Sets.
  • Lin Sun, DHS Behavioural factors Link

(back to top)

License

GitHub License

Known issues

  • AQR Models (HML Devil, Betting Against Beta, Quality Minus Junk) download slowly, particulary daily datasets. Need to implement a progress bar.
Todo
  • Documentation
  • Example notebook
  • Error handling
  • README
  • Refactor of FF models
  • metadata - copyright, license, bibtex/citations

Metadata

Release files for getfactormodels 0.0.35

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for getfactormodels 0.0.35
File Size Uploaded Provenance Actions
getfactormodels-0.0.35.tar.gz 96.6 kB Without provenance Details for getfactormodels-0.0.35.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for getfactormodels 0.0.35
File Interpreter ABI Platform Actions
getfactormodels-0.0.35-py3-none-any.whl Python 3 none any Details for getfactormodels-0.0.35-py3-none-any.whl

Total release size: 215.0 kB

Release files / getfactormodels-0.0.35.tar.gz

Download URL getfactormodels-0.0.35.tar.gz
Size 96.6 kB
Tags Source
SHA-256 checksum
How to use checksums
28eadf96ee30981b0b8d1f255524c61eb7dfc18db8ea489c88603b34c84c4122
BLAKE2b-256 checksum
How to use checksums
6fb5f1f60915479ae3f6406767e073e73ea2ba20e3bb64c9cc5b252072900c87
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.5.1 CPython/3.13.5 Linux/6.6.87.2-microsoft-standard-WSL2

Release files / getfactormodels-0.0.35-py3-none-any.whl

Download URL getfactormodels-0.0.35-py3-none-any.whl
Size 118.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a747caa834772c8362d35a3dc5d9bc8cd05e2c444718c3442c093f46e4cf5af7
BLAKE2b-256 checksum
How to use checksums
fb98aaf835ab5b1c7e7ea31bb6efb8d51e710e5332c8c94f1e3e35a862f6f0c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.5.1 CPython/3.13.5 Linux/6.6.87.2-microsoft-standard-WSL2

Security for getfactormodels 0.0.35

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.35 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page