Skip to main content

farms

Financial Analysis & Risk Management (farms) is a Python toolkit for teaching and research. It provides a simple interface for downloading Fama-French factors and portfolio returns from the Kenneth French Data Library.

Installation

farms requires Python 3.11 or newer.

python -m pip install farms

To work on a local checkout, install it in editable mode:

python -m pip install -e .

The data-loading functions require an internet connection when called.

Fama-French factors

Monthly three-factor data:

import farms

ff3 = farms.get_ff3("2000-01", "2025-12")
print(ff3.head())

The result contains Mkt-RF, SMB, HML, and RF.

Monthly five-factor data:

ff5 = farms.get_ff5("2000-01", "2025-12")
print(ff5.head())

The result contains Mkt-RF, SMB, HML, RMW, CMA, and RF.

Daily three-factor data:

ff3_daily = farms.get_ff3d("2025-01-01", "2025-12-31")
print(ff3_daily.head())

Monthly factor data use a pandas PeriodIndex. Daily factor data use a pandas DatetimeIndex.

Kenneth French decile portfolios

Display the available strategies:

farms.get_ken_french_deciles("list")

Supported strategies are:

  • accruals
  • beta
  • booktomarket
  • dividendyield
  • earningsprice
  • idiosyncraticvariance
  • investment
  • momentum
  • netissuances
  • profitability
  • shorttermreversal
  • size
  • variance

Load monthly value-weighted momentum deciles:

momentum = farms.get_ken_french_deciles(
    "momentum",
    start_date="2000-01",
    end_date="2025-12",
)
print(momentum.head())

Portfolio columns are named Dec 1 through Dec 10. By default, the result also contains the market excess return (mkt-rf) and risk-free rate (rf).

Add all three-factor columns:

momentum_ff3 = farms.get_ken_french_deciles(
    "momentum",
    start_date="2000-01",
    end_date="2025-12",
    factors="FF3",
)

This adds mkt-rf, smb, hml, and rf.

Add all five-factor columns:

momentum_ff5 = farms.get_ken_french_deciles(
    "momentum",
    start_date="2000-01",
    end_date="2025-12",
    factors="FF5",
)

This adds mkt-rf, smb, hml, rmw, cma, and rf.

Teaching details

Pass details=True to print a short explanation of the portfolio construction and the available date range. The function still returns the DataFrame.

momentum = farms.get_ken_french_deciles(
    "momentum",
    start_date="2000-01",
    end_date="2025-12",
    details=True,
)

Return units

All factor and portfolio returns are expressed as decimals:

  • 0.01 means 1%.
  • -0.025 means -2.5%.

This differs from the source files in the Kenneth French Data Library, which report returns in percent.

Running tests

Install pytest and run the suite from the repository root:

python -m pip install pytest
python -m pytest

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

farms-0.1.19.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

farms-0.1.19-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

Details for the file farms-0.1.19.tar.gz.

File metadata

  • Download URL: farms-0.1.19.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.5

File hashes

Hashes for farms-0.1.19.tar.gz
Algorithm Hash digest
SHA256 b6d212f9f6f9b7987b624cfe8099c53dcc714826a4655f2c86ea82cac69134a3
MD5 2a3fa6bec5fd995479303c41afd78d2d
BLAKE2b-256 923e2a3b267088c38bb7a573b4452cdff8023381ef68f72a25bfacc3c9686fc8

See more details on using hashes here.

File details

Details for the file farms-0.1.19-py3-none-any.whl.

File metadata

  • Download URL: farms-0.1.19-py3-none-any.whl
  • Upload date:
  • Size: 13.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.5

File hashes

Hashes for farms-0.1.19-py3-none-any.whl
Algorithm Hash digest
SHA256 cdd8da483ef85daf94855326fb43fd93f6983e0c7b7f178dc9fd1051f872fd98
MD5 11b92f167b58395a4937bf780c6d7a03
BLAKE2b-256 301c8cfd4ac1d4cb7af1de1fc7129af6e5828b5337b3c0b99b1adaa67b15c02b

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.21

2 files

0.1.20

2 files

This release

0.1.19 This release

2 files

0.1.18

2 files

0.1.17

2 files

0.1.16

2 files

0.1.15

2 files

0.1.14

2 files

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