finm
A Python package for financial mathematics and quantitative finance education, created by students and educators at the University of Chicago Financial Mathematics program.
Installation
pip install finm
For all optional dependencies (CLI, data access):
pip install finm[all]
Data Access
Load financial data from multiple sources with a consistent interface. See the Data Module documentation for details.
import finm
# Fama-French factors (bundled data, no download needed)
factors = finm.load_fama_french_factors()
factors = finm.load_fama_french_factors(start="2020-01-01", end="2023-12-31")
# Pull fresh data from Ken French's Data Library
finm.pull_fama_french_factors(data_dir="./data", accept_license=True)
# Federal Reserve yield curve (GSW model)
finm.pull_fed_yield_curve(data_dir="./data", accept_license=True)
yields = finm.load_fed_yield_curve(data_dir="./data")
# He-Kelly-Manela intermediary capital factors
finm.pull_he_kelly_manela(data_dir="./data", accept_license=True)
hkm = finm.load_he_kelly_manela_factors_monthly(data_dir="./data")
# Open Source Bond Asset Pricing data
finm.pull_open_source_bond(data_dir="./data", accept_license=True)
treasury = finm.load_treasury_returns(data_dir="./data")
corporate = finm.load_corporate_bond_returns(data_dir="./data")
# WRDS data (requires authentication)
finm.pull_wrds_treasury(
data_dir="./data",
wrds_username="your_username",
start_date="2020-01-01",
end_date="2023-12-31"
)
Analytics
Calculate risk metrics and factor exposures.
import finm
# Load factors
factors = finm.load_fama_french_factors()
# Fama-French 3-factor exposures
exposures = finm.calculate_factor_exposures(stock_returns, factors)
print(f"Market Beta: {exposures['market_beta']:.3f}")
print(f"SMB Beta: {exposures['smb_beta']:.3f}")
print(f"HML Beta: {exposures['hml_beta']:.3f}")
print(f"Sharpe: {exposures['sharpe_ratio']:.3f}")
# Individual metrics
beta = finm.calculate_beta(stock_returns, market_returns)
sharpe = finm.calculate_sharpe_ratio(returns, risk_free_rate=0.02)
Fixed Income
Bond pricing, duration, and yield curve modeling.
import finm
# Bond pricing
price = finm.bond_price(
face_value=1000,
coupon_rate=0.05,
ytm=0.04,
periods=10,
frequency=2 # semiannual
)
# Duration and convexity
dur = finm.duration(1000, 0.05, 0.04, 10, frequency=2)
mod_dur = finm.modified_duration(1000, 0.05, 0.04, 10, frequency=2)
conv = finm.convexity(1000, 0.05, 0.04, 10, frequency=2)
# Yield to maturity
ytm = finm.yield_to_maturity(
price=1050,
face_value=1000,
coupon_rate=0.05,
periods=10,
frequency=2
)
# Time value of money
pv = finm.present_value(future_value=1000, rate=0.05, periods=3)
fv = finm.future_value(present_value=1000, rate=0.05, periods=3)
The package also includes an implementation of the Gurkaynak-Sack-Wright (2006) yield curve model. See the API documentation for spot, discount, fit, and related functions.
Command Line Interface
Manage data downloads from the terminal. See the CLI documentation for details.
# List available datasets
finm list
# Get info about a dataset
finm info fama_french
# Pull data (--accept-license flag required)
finm pull fama_french --data-dir=./data --accept-license
finm pull fed_yield_curve --data-dir=./data --accept-license
# Pull WRDS data (requires credentials)
finm pull wrds_treasury --wrds-username=myuser --start-date=2020-01-01 --end-date=2023-12-31 --accept-license
Documentation
Full documentation is available at jeremybejarano.com/finm.
Data Licensing
Citation Requirements
When using data from these sources in academic work, please cite appropriately:
| Data Source | Citation |
|---|---|
| Fama-French | Fama, E.F. and French, K.R. (1993). Common Risk Factors in the Returns on Stocks and Bonds. Journal of Financial Economics 33(1): 3-56. |
| Federal Reserve | Board of Governors of the Federal Reserve System. GSW Yield Curve Data. https://www.federalreserve.gov/ |
| He-Kelly-Manela | He, Z., Kelly, B., and Manela, A. (2017). Intermediary Asset Pricing: New Evidence from Many Asset Classes. Journal of Financial Economics 126(1): 1-35. |
| Open Source Bond | Dickerson, A., Robotti, C., and Rossetti, G. (2026). The Corporate Bond Factor Replication Crisis. Working Paper. |
| WRDS | Wharton Research Data Services. https://wrds-www.wharton.upenn.edu/ |
License Types
| Data Source | License | Terms URL |
|---|---|---|
| Fama-French | Copyright Fama & French | Ken French Data Library |
| Federal Reserve | Public Domain | Federal Reserve Disclaimer |
| He-Kelly-Manela | Academic Use | HKM Website |
| Open Source Bond | MIT License | GitHub Repository |
| WRDS | Subscription-based | WRDS Terms |
Fair Use
The data access functionality in this package is provided for:
- Educational purposes
- Academic research
- Personal, non-commercial analysis
For commercial use, please consult the original data provider's licensing terms.
License
Modified BSD License. See LICENSE for details.
Acknowledgments
Created and maintained by students and educators at the University of Chicago Financial Mathematics program.
Metadata
Release files for finm 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| finm-0.1.3.tar.gz | 46.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| finm-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 109.5 kB
Release files / finm-0.1.3.tar.gz
| Download URL | finm-0.1.3.tar.gz |
|---|---|
| Size | 46.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
46473993a87eab2e952b43bf3b0ba5ee3b8ba19cbbda0e254b2762885e8680e6
|
|
BLAKE2b-256 checksum How to use checksums |
2fd9e2d9c6f9bf03e8e3a204aa20c874b8af69c4fa9811e66cb6373f00817ce9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.28.1
|
Release files / finm-0.1.3-py3-none-any.whl
| Download URL | finm-0.1.3-py3-none-any.whl |
|---|---|
| Size | 63.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f51ec5c14f0e2b218815ce590fcf87b13933a778486076603103ef2a5f71c3a9
|
|
BLAKE2b-256 checksum How to use checksums |
9d365b2087df1ce911ca8f07a0494dffb8228f7447da38b98943303a6d94754f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.28.1
|
Security for finm 0.1.3
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.