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())

Daily five-factor data:

ff5_daily = farms.get_ff5d("2025-01-01", "2025-12-31")
print(ff5_daily.head())

The daily five-factor result contains Mkt-RF, SMB, HML, RMW, CMA, and RF. Dates are optional; supplying only start_date retrieves observations from that date through the latest available observation:

ff5_daily = farms.get_ff5d(start_date="2025-01-01")

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.20.tar.gz (17.2 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.20-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: farms-0.1.20.tar.gz
  • Upload date:
  • Size: 17.2 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.20.tar.gz
Algorithm Hash digest
SHA256 925bdd0e1504e5db5270d3b0244019da4e97d5f79ca1157c5449a5ed1a10b9e0
MD5 31b03d7475fdf814a558b788ae85737b
BLAKE2b-256 6e545e8a2ab8d65929a1f9df7cb33b64433cecccbba945f82d8fe003ce399138

See more details on using hashes here.

File details

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

File metadata

  • Download URL: farms-0.1.20-py3-none-any.whl
  • Upload date:
  • Size: 13.5 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.20-py3-none-any.whl
Algorithm Hash digest
SHA256 72f5aa31468ce1906a550ee8440f7999699887f063dea7e9ad29727e9cd901bf
MD5 e90c718a89780722cf56799f04dab0fa
BLAKE2b-256 0678a979e046d6565e53c3504e6c775e4795e900e3695d65dde603c9bc5faee2

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.21

2 files

This release

0.1.20 This release

2 files

0.1.19

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