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:
accrualsbetabooktomarketdividendyieldearningspriceidiosyncraticvarianceinvestmentmomentumnetissuancesprofitabilityshorttermreversalsizevariance
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.01means 1%.-0.025means -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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
925bdd0e1504e5db5270d3b0244019da4e97d5f79ca1157c5449a5ed1a10b9e0
|
|
| MD5 |
31b03d7475fdf814a558b788ae85737b
|
|
| BLAKE2b-256 |
6e545e8a2ab8d65929a1f9df7cb33b64433cecccbba945f82d8fe003ce399138
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72f5aa31468ce1906a550ee8440f7999699887f063dea7e9ad29727e9cd901bf
|
|
| MD5 |
e90c718a89780722cf56799f04dab0fa
|
|
| BLAKE2b-256 |
0678a979e046d6565e53c3504e6c775e4795e900e3695d65dde603c9bc5faee2
|