A student-led Python package for financial mathematics and quantitative finance education
Project description
finm
A Python package for financial mathematics and quantitative finance education, created by students and educators at the University of Chicago Financial Mathematics program.
[!CAUTION] This package is for learning purposes only. There are likely errors in the implementations, and this software should not be used for production trading systems, real financial decision-making, or commercial applications. Always verify calculations independently.
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.
[!IMPORTANT] License Acknowledgment Required: All data pull functions require
accept_license=Trueto confirm you understand that the data is subject to the original provider's licensing terms. See Data Licensing below.
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
[!WARNING] Third-Party Data Disclaimer: The
finm.datamodule provides convenient access to financial datasets from various third-party sources. The finm package maintainers are not responsible for the accuracy, completeness, or licensing of this data. Usage is subject to the original data provider's terms and conditions.
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
MIT License. See LICENSE for details.
Acknowledgments
Created and maintained by students and educators at the University of Chicago Financial Mathematics program.
Project details
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 finm-0.1.2.tar.gz.
File metadata
- Download URL: finm-0.1.2.tar.gz
- Upload date:
- Size: 45.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ce7765feb2d3f995f1802b0580a7f829f4b81fb20461980ba0fdb56214b33e8
|
|
| MD5 |
e2383161529e21dfc159e0c5547ac815
|
|
| BLAKE2b-256 |
b76763f15e3841be6351ce6f7fb0063afeed5d6d54db070691de46c00228bd88
|
File details
Details for the file finm-0.1.2-py3-none-any.whl.
File metadata
- Download URL: finm-0.1.2-py3-none-any.whl
- Upload date:
- Size: 62.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e223ad8a9cb29fe92d28759668f5c82b1386042c3dc076e507107351bdd02601
|
|
| MD5 |
0d7a70b6d9dbf3482dd28cec39ad4e7f
|
|
| BLAKE2b-256 |
d46be4ff5861f47ea6c0660f37d0371e16cb61de632a81059f7434c29d2ae3f9
|