Skip to main content

An open credit modeling tool kit

Project description

credkit

An open toolbox for credit modeling in Python

Credkit provides elegant, type-safe primitives for building credit models that typically force teams to reach for Excel. From consumer loans to portfolio analytics, credkit offers domain-driven tools designed for precision and composability.

Built for consumer lending (mortgages, auto loans, personal loans) with cash flow modeling, amortization schedules, and present value calculations.

Currently focused on USD-denominated consumer loan products in the US market.

Installation

# Using uv (recommended)
uv add credkit

# Using pip
pip install credkit

Quick Start

from credkit import Loan, Money, InterestRate, FlatDiscountCurve
from datetime import date

# Create a 30-year mortgage
loan = Loan.mortgage(
    principal=Money.from_float(300000.0),
    annual_rate=InterestRate.from_percent(6.5),
    term_years=30,
    origination_date=date(2024, 1, 1),
)

# Calculate payment
payment = loan.calculate_payment()  # ~$1,896.20/month

# Generate amortization schedule
schedule = loan.generate_schedule()  # 720 cash flows (360 principal + 360 interest)

# Calculate total interest over life of loan
total_interest = loan.total_interest()

# Value the loan at market rate
market_curve = FlatDiscountCurve(
    InterestRate.from_percent(5.5),
    valuation_date=date(2024, 1, 1)
)
npv = schedule.present_value(market_curve)

See EXAMPLES.md for more comprehensive examples of all features.

Core Features

Temporal (credkit.temporal)

  • Day count conventions: ACT/365, ACT/360, ACT/ACT, 30/360, and more
  • Periods: Time spans with natural syntax ("30Y", "6M", "90D")
  • Payment frequencies: Annual, monthly, bi-weekly, etc.
  • Business day calendars: Holiday-aware date adjustments

Money (credkit.money)

  • Money: Currency-aware amounts with float64 precision
  • Interest rates: APR with multiple compounding conventions
  • Spreads: Basis point adjustments (e.g., "Prime + 250 bps")

Cash Flow (credkit.cashflow)

  • Cash flows: Individual payment representation with present value
  • Schedules: Collections with filtering, aggregation, and NPV
  • Discount curves: Flat and zero curves with interpolation

Loans (credkit.instruments)

  • Loan types: Mortgages, auto loans, personal loans
  • Amortization: Level payment, level principal, interest-only, bullet
  • Schedules: Generate complete payment schedules with principal/interest breakdown
  • Integration: Full end-to-end from loan creation to NPV calculation

Features

  • Immutable by default: All core types are frozen dataclasses
  • Float64 precision: Standard IEEE 754 double precision with appropriate rounding
  • Type safety: Full type hints with py.typed marker
  • Composable: Build complex models from simple primitives
  • Tested: 148 passing tests with comprehensive coverage

Numeric Precision

credkit uses IEEE 754 float64 for all financial calculations, providing:

  • 15-17 significant digits of precision (sufficient for consumer loan calculations)
  • Sub-penny accuracy for monetary amounts (empirically validated)
  • No intermediate rounding - full precision maintained through calculations
  • Currency-aware final rounding - Money.round() defaults to 2 decimal places for USD

Rounding Approach:

  • Intermediate calculations use full float64 precision
  • Final results rounded to currency decimal places (e.g., 2 for USD cents)
  • Amortization schedules adjust final payment to exact remaining balance
  • Tests use tolerance-based comparisons (typically 0.01 for money, 0.0001 for rates)

Documentation

  • EXAMPLES.md: Comprehensive code examples for all modules

Requirements

  • Python 3.13+
  • No runtime dependencies (uses only standard library)

Development

# Clone and setup
git clone https://github.com/jt-hill/credkit.git
cd credkit/core-classes
uv sync --dev

# Run tests
uv run pytest tests/ -v  # All 148 tests should pass

Contributing

Contributions welcome! This project follows:

  • Domain-driven design with immutable primitives
  • Comprehensive testing

License

Copyright (c) 2025 JT Hill

Licensed under the GNU Affero General Public License. See LICENSE for details

For commercial licensing options not covered by AGPL, contact the author

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

credkit-0.5.0.tar.gz (41.0 kB view details)

Uploaded Source

Built Distribution

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

credkit-0.5.0-py3-none-any.whl (55.4 kB view details)

Uploaded Python 3

File details

Details for the file credkit-0.5.0.tar.gz.

File metadata

  • Download URL: credkit-0.5.0.tar.gz
  • Upload date:
  • Size: 41.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.25 {"installer":{"name":"uv","version":"0.9.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for credkit-0.5.0.tar.gz
Algorithm Hash digest
SHA256 4d24157237c68f1e0a52f2a74f4799c37dad2c880cd5fafd588714cee0a0f2db
MD5 28d9860f8577575d63dcfaa8c1b030ec
BLAKE2b-256 fe17e86893d035f2921a990757b8f5e41ee75a497220757a1c08082e4b0a5ca6

See more details on using hashes here.

File details

Details for the file credkit-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: credkit-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 55.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.25 {"installer":{"name":"uv","version":"0.9.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for credkit-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 066517bffa6356e023ff7b594e6450136e20f167359592c7460a2b0b7ca5ee22
MD5 b9ce5207c2036c76d87e73cca8c1d74a
BLAKE2b-256 88c29adeb4100b19e974778a6e4b3b008eebc6ff5892b5cbc5a1c52fb5f02ed9

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