Skip to main content

A student-led Python package for financial mathematics and quantitative finance education

Project description

PyPI - Version PyPI - Python Version GitHub Stars Documentation

finm logo

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=True to 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.data module 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

Modified BSD 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

finm-0.1.3.tar.gz (46.3 kB view details)

Uploaded Source

Built Distribution

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

finm-0.1.3-py3-none-any.whl (63.2 kB view details)

Uploaded Python 3

File details

Details for the file finm-0.1.3.tar.gz.

File metadata

  • Download URL: finm-0.1.3.tar.gz
  • Upload date:
  • Size: 46.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for finm-0.1.3.tar.gz
Algorithm Hash digest
SHA256 46473993a87eab2e952b43bf3b0ba5ee3b8ba19cbbda0e254b2762885e8680e6
MD5 bfd6011b84213124fb3003b2917f0a0b
BLAKE2b-256 2fd9e2d9c6f9bf03e8e3a204aa20c874b8af69c4fa9811e66cb6373f00817ce9

See more details on using hashes here.

File details

Details for the file finm-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: finm-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 63.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for finm-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f51ec5c14f0e2b218815ce590fcf87b13933a778486076603103ef2a5f71c3a9
MD5 b0690caecb47a4e845e2fd1fa88bbd5d
BLAKE2b-256 9d365b2087df1ce911ca8f07a0494dffb8228f7447da38b98943303a6d94754f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page