Skip to main content

credkit

An experimental 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(300000.0),
    annual_rate=InterestRate(0.065),
    term=30,
    origination_date=date(2024, 1, 1),
)

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

# Generate amortization schedule
schedule = loan.generate_schedule()  # 360 cash flows

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

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

# Build a portfolio of loans
from credkit.portfolio import Portfolio

loans = [
    Loan.mortgage(Money(300000), InterestRate(0.065), origination_date=date(2024, 1, 1)),
    Loan.mortgage(Money(250000), InterestRate(0.0625), origination_date=date(2024, 3, 1)),
]
portfolio = Portfolio.from_loans(loans, name="Q1 2024 Originations")

# Portfolio metrics
wac = portfolio.weighted_average_coupon()  # ~6.39%
pool_npv = portfolio.present_value(market_curve)

See cookbook 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

Portfolio (credkit.portfolio)

  • Portfolio: Aggregate multiple loans into pools with weighted metrics
  • Positions: Track ownership with position IDs and partial ownership factors
  • Weighted averages: WAC (coupon), WAM (maturity), WALA (age), pool factor
  • Valuation: Portfolio-level NPV, YTM, WAL, duration, and convexity

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: 225 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

  • Cookbook: Comprehensive code examples for all modules
  • Examples: End-to-end workflow scripts

Requirements

  • Python 3.13+
  • pyxirr - fast financial calculations (XIRR/IRR)

Development

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

# Run tests
uv run pytest tests/ -v  # All 225 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

Release files for credkit 0.5.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for credkit 0.5.2
File Size Uploaded
credkit-0.5.2.tar.gz 53.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for credkit 0.5.2
File Interpreter ABI Platform
credkit-0.5.2-py3-none-any.whl Python 3 none any Details

Total release size: 123.1 kB

Release files / credkit-0.5.2.tar.gz

Download URL credkit-0.5.2.tar.gz
Size 53.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a065c71db97e4e41d00b73daa93b729c21d88b775aa30b4e7f03d86ab370e660
BLAKE2b-256 checksum
How to use checksums
4875e93e699988da15d960140c7dda4ca47f03a23151cbe05e9603bb063faad2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / credkit-0.5.2-py3-none-any.whl

Download URL credkit-0.5.2-py3-none-any.whl
Size 69.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
db9818314731f3ae6ef5f10347f3ad743fc290b980fd5a5ef3cc5c5247a116fa
BLAKE2b-256 checksum
How to use checksums
f1a36b831a9d21c4affa723b866c540258e8731a215b81bafdcdf4439e0322a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.5.2 This release

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page