Skip to main content

Loan Analyzer

A lightweight, SQL-powered engine for validating loan data and computing analytical metrics using DuckDB. It is designed to transform raw CSV loan data into auditable, time-series financial states.

Project Structure

The project follows the src layout for better packaging and isolation:

loan_analyzer/
├── src/
│   └── loan_analyzer/
│       ├── loan_system/       # Core Python logic
│       ├── sql/               # SQL transformations (CTEs, etc.)
│       └── tests/             # SQL-based validation tests
├── docs/                      # Documentation
├── pyproject.toml             # Build configuration
└── README.md

Installation

You can install the package directly from GitHub:

pip install git+https://github.com/zakiahmed1234/loan_analyzer.git

Core API Reference

The API is modularized into specialized classes within the loan_analyzer package.

1. DataLoader

Handles data ingestion from CSVs into an in-memory DuckDB instance.

__init__(directory_path, connection=None)

  • directory_path: Directory containing the required CSV files.
  • connection: (Optional) An existing DuckDB connection. If omitted, a new in-memory connection is created.
  • Behavior: Automatically loads all .csv files in the directory as tables.
from loan_analyzer import DataLoader
loader = DataLoader("./data/my_loan_batch")

2. DataValidation

Runs a suite of SQL-based invariant tests to ensure data integrity.

__init__(loader: DataLoader)

Initializes with a populated DataLoader.

validate_all()

Runs all tests in src/loan_analyzer/tests/data_validation/.

  • Returns: A pandas DataFrame containing the results (check name, pass/fail, details).
from loan_analyzer import DataValidation
validator = DataValidation(loader)
report = validator.validate_all()
print(report)

3. LoanCalculation

The execution engine for financial business logic.

__init__(validator: DataValidation)

Initializes the runner with a DataValidation instance. It ensures validation has been run before executing calculations.

run_loan_state()

Executes the Recursive Balance Engine. This calculates monthly snapshots for every loan, tracking interest accrual, payments, and principal amortization.

from loan_analyzer import LoanCalculation
calculator = LoanCalculation(validator)
calculator.run_loan_state()

run_delinquency()

Calculates the Delinquency Waterfall (DPD and status classification).

calculator.run_delinquency()

4. LoanAudit

The Forensic Audit Tool. Provides a line-item reconciliation of a loan's principal change.

audit_loan(loan_id, as_of_date)

Returns a detailed text report reconciling Opening - Closing == Amortization + Write-offs.

from loan_analyzer import LoanAudit
auditor = LoanAudit(calculator)
print(auditor.audit_loan("L-001", "2024-05-15"))

Advanced Usage Example

from loan_analyzer import DataLoader, DataValidation, LoanCalculation, LoanAudit

# 1. Setup Data Environment (Auto-loads CSVs)
loader = DataLoader("FakeData/1/")

# 2. Perform Health Check
validator = DataValidation(loader)
report = validator.validate_all()
if not report.passed.all():
    print("Data issues found!")
    print(report[report.passed == False])

# 3. Generate Financial Models
calculator = LoanCalculation(validator)
calculator.run_all() # Runs both state and delinquency

# 4. Forensic Investigation
auditor = LoanAudit(calculator)
print(auditor.audit_loan("3c60c443-a997-4a9c-8948-33fd5301208e", "2023-12-01"))

SQL Resources

The core logic is modularized in src/loan_analyzer/sql/. You can find the recursive CTEs for balance tracking and the cumulative window functions for delinquency there.

License

MIT

Metadata

Release files for loan-analyzer 0.1.1

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

Source distribution (sdist)

Source distribution for loan-analyzer 0.1.1
File Size Uploaded Provenance Actions
loan_analyzer-0.1.1.tar.gz 12.2 kB Without provenance Details for loan_analyzer-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for loan-analyzer 0.1.1
File Interpreter ABI Platform Actions
loan_analyzer-0.1.1-py3-none-any.whl Python 3 none any Details for loan_analyzer-0.1.1-py3-none-any.whl

Total release size: 28.0 kB

Release files / loan_analyzer-0.1.1.tar.gz

Download URL loan_analyzer-0.1.1.tar.gz
Size 12.2 kB
Tags Source
SHA-256 checksum
How to use checksums
da4506f4bd2253b658beaf5094a631823b7f8265c37520ce8fc0febbe5e76880
BLAKE2b-256 checksum
How to use checksums
dc55fc8552b6bc2339dc377dd64244a8e202d55e4c2723ef4855bb55b0865dcc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Release files / loan_analyzer-0.1.1-py3-none-any.whl

Download URL loan_analyzer-0.1.1-py3-none-any.whl
Size 15.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9437c98d613df51308ae3abc7ddd9ed319038bca9315b17999e9959d938debf7
BLAKE2b-256 checksum
How to use checksums
80a2e37fffa1ce584efbbcfd019be750d41117cd4abdfad10ab301ba79abe830
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Security for loan-analyzer 0.1.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

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