Skip to main content

FinEngine-Py

PyPI Version Python Versions License: MIT Strict Typing Code style: ruff

Deterministic Financial Math, Credit Risk Modeling, and Quantitative Primitives for Python.

A computational research initiative by the Centre for Fintech & Strategic Business Research (CFSBR).


🌟 Overview & Philosophy

FinEngine-Py brings audited actuarial math, integer-scaled sub-unit arithmetic (Poisha / Cents), strict type hints, and Pandas DataFrame integration to Python quants, data scientists, and fintech developers.

  • Zero-Dependency Math Core: The finengine.math module is 100% pure Python with zero third-party dependencies.
  • Float-Drift Elimination: Protects accounting ledgers against IEEE-754 floating-point drift using integer sub-unit scaling.
  • Terminal Zero Reconciliation Rule: Guarantees that the final loan amortization installment strictly liquidates to exactly 0.00.
  • Cross-Platform Parity: Models prototyped in Python yield 100% identical mathematical output to the FinEngine TypeScript/JavaScript engine.
  • Alternative Credit Risk AI: Lightweight pre-calibrated scoring models for Microfinance, MFS (bKash/Nagad), and SME nano-loans.

🚀 Installation

# Minimal installation (Zero dependencies, pure math)
pip install finengine

# With Pandas & NumPy DataFrame support
pip install "finengine[analysis]"

# With Scikit-Learn AI & Risk modeling support
pip install "finengine[all]"

💡 Code Recipes & Examples

1. Deterministic Loan Amortization (36-Month EMI)

from finengine import amortize, format_money

# Compute a 36-month loan amortization for BDT 5,00,000 at 13.5% p.a.
plan = amortize(principal=500000, annual_rate=13.5, months=36)

print(f"Monthly Payment: {format_money(plan.monthly_payment, 'BDT')}")
# → Monthly Payment: BDT 16,967.64

print(f"Total Interest:  {format_money(plan.total_interest, 'BDT')}")
# → Total Interest:  BDT 1,10,835.20

print(f"Final Balance:   {plan.schedule[-1].remaining_balance}")
# → Final Balance:   0.0 (Guaranteed Terminal Zero Closure)

2. Tabular Pandas DataFrame Schedule Analysis

import pandas as pd
from finengine import amortize, to_dataframe

plan = amortize(principal=500000, annual_rate=13.5, months=36)

# Direct conversion into structured Pandas DataFrame
df = to_dataframe(plan)
print(df.head())
#    month   payment  principal_paid  interest  remaining_balance
# 0      1  16967.64        11342.64   5625.00          488657.36
# 1      2  16967.64        11470.25   5497.39          477187.11
# 2      3  16967.64        11599.29   5368.35          465587.82

# Export to spreadsheet format
df.to_csv("sme_amortization_schedule.csv", index=False)

3. Non-Periodic Cash Flow XIRR Solver

from datetime import date
from finengine import xirr, CashFlow

cashflows = [
    CashFlow(amount=-100000, date=date(2026, 1, 1)),   # Initial investment
    CashFlow(amount=25000,  date=date(2026, 4, 1)),   # Q1 Dividend
    CashFlow(amount=30000,  date=date(2026, 8, 15)),  # Q2 Distribution
    CashFlow(amount=65000,  date=date(2026, 12, 31)), # Year-end liquidation
]

rate = xirr(cashflows)
print(f"Annualized Internal Rate of Return (XIRR): {rate * 100:.2f}%")
# → Annualized Internal Rate of Return (XIRR): 24.83%

4. Alternative Credit Risk & MFS Nano-Loan Scoring

from finengine.ai import MFSProfile, assess_credit_risk

profile = MFSProfile(
    monthly_inflows=75000.0,
    monthly_outflows=35000.0,
    avg_balance=18000.0,
    transaction_frequency=40,
    utility_bill_consistency=1.0,
    account_age_months=24,
    past_defaults=0,
)

assessment = assess_credit_risk(profile=profile, requested_amount=50000)

print(f"Credit Score:      {assessment.score} / 850")
print(f"Default Risk (PD): {assessment.default_probability * 100:.2f}%")
print(f"Risk Tier:         {assessment.risk_tier}")
print(f"Recommended Limit: BDT {assessment.recommended_credit_limit:,.2f}")

📊 API Reference

Function / Class Signature Return Type Description
amortize() (principal, annual_rate, months, round_to_integer=False) AmortizationPlan Computes full reducing-balance EMI schedule with Terminal Zero guarantee.
monthly_payment() (principal, annual_rate, months, round_to_integer=False) float Returns exact monthly installment amount.
xirr() (cashflows, guess=0.1, max_iter=100) float Solves annualized internal rate of return for irregular non-periodic cashflows.
create_money() (amount, currency='BDT') Money Creates monetary instance with integer sub-unit scaling.
format_money() (amount, currency='BDT', locale='en-BD') str Formats currency strings with South Asian (Lakh/Crore) or Western notation.
to_dataframe() (schedule_or_plan) pandas.DataFrame Converts plan or schedule rows into a structured DataFrame.
batch_amortize() (portfolio) pandas.DataFrame Computes multi-loan portfolio schedules.
simulate_loan() (principal, annual_rate, months, prepayments=None, default_month=None) dict Simulates prepayment acceleration or borrower default stress scenarios.
assess_credit_risk() (inflows=None, profile=None, requested_amount=0.0) CreditAssessment Evaluates borrower credit risk, score, and safe exposure limit.

🛠️ Development & Testing

# Clone repository
git clone https://github.com/gmrafi/FinEngine-Py.git
cd FinEngine-Py

# Install in editable mode with development dependencies
pip install -e ".[dev,all]"

# Run test suite
pytest -v tests/

# Type check with mypy
mypy src/

# Lint with ruff
ruff check src/ tests/

📄 License

Distributed under the MIT License.

Copyright (c) 2026 CFSBR Computational Team & Md Golam Mubasshir Rafi.

Release files for finengine 0.1.0

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

Source distribution (sdist)

Source distribution for finengine 0.1.0
File Size Uploaded
finengine-0.1.0.tar.gz 17.4 kB Details

Built distribution (wheel)

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

Total release size: 36.5 kB

Release files / finengine-0.1.0.tar.gz

Download URL finengine-0.1.0.tar.gz
Size 17.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c8a1004468b164e66a31b14bb0cba98fc4560f9f1fd86b94e2c4bd4cf30f71f1
BLAKE2b-256 checksum
How to use checksums
e50e0052fb0d764e2950065a14a0018122666edcaab52a5b59bd05c16582783c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 17, 2026.

Transparency log

Release files / finengine-0.1.0-py3-none-any.whl

Download URL finengine-0.1.0-py3-none-any.whl
Size 19.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
415e083fc3b887a8b6d359a4dc86f0476aa85a1987c9defd837e73e4cffb2ac8
BLAKE2b-256 checksum
How to use checksums
e81f6963d4b5628df966df28bcedcb33f33c3ec7a0d72b19a536e3d99c0253b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 17, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.1

2 release files

This release

0.1.0 This release

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