Skip to main content

Deterministic verification middleware for banking and financial AI

Project description

QWED-Finance ๐Ÿฆ

Deterministic verification middleware for banking and financial AI.

Verified by QWED PyPI License Python 3.10+ npm

Part of the QWED Ecosystem - Verification Infrastructure for AI


๐ŸŽฏ What is QWED-Finance?

QWED-Finance is a middleware layer that applies QWED's deterministic verification to banking and financial calculations. It ensures AI-generated financial outputs are mathematically correct before they reach production.

Key Features

Feature Description
NPV/IRR Verification Validate net present value and internal rate of return calculations
Loan Amortization Verify payment schedules and interest calculations
Compound Interest Check compound interest formulas with precision
Currency Safety Prevent floating-point errors in money calculations
ISO 20022 Schemas Built-in support for banking message standards

๐Ÿ›ก๏ธ The Three Guards

1. Compliance Guard (Z3-Powered)

KYC/AML regulatory verification with formal boolean logic proofs.

from qwed_finance import ComplianceGuard

guard = ComplianceGuard()

# Verify AML flagging decision
result = guard.verify_aml_flag(
    amount=15000,        # Over $10k threshold
    country_code="US",
    llm_flagged=True     # LLM flagged it
)
# result.compliant = True โœ…

Supports:

  • AML/CTR threshold checks (BSA/FinCEN)
  • KYC completion verification
  • Transaction limit enforcement
  • OFAC sanctions screening

2. Calendar Guard (Day Count Conventions)

Deterministic day counting for interest accrual - no date hallucinations.

from qwed_finance import CalendarGuard, DayCountConvention
from datetime import date

guard = CalendarGuard()

# Verify 30/360 day count
result = guard.verify_day_count(
    start_date=date(2026, 1, 1),
    end_date=date(2026, 7, 1),
    llm_days=180,
    convention=DayCountConvention.THIRTY_360
)
# result.verified = True โœ…

Supports:

  • 30/360 (Corporate bonds)
  • Actual/360 (T-Bills)
  • Actual/365 (UK gilts)
  • Business day verification

3. Derivatives Guard (Black-Scholes)

Options pricing and margin verification using pure calculus.

from qwed_finance import DerivativesGuard, OptionType

guard = DerivativesGuard()

# Verify Black-Scholes call price
result = guard.verify_black_scholes(
    spot_price=100,
    strike_price=105,
    time_to_expiry=0.25,   # 3 months
    risk_free_rate=0.05,
    volatility=0.20,
    option_type=OptionType.CALL,
    llm_price="$3.50"
)
# result.greeks = {"delta": 0.4502, "gamma": 0.0389, ...}

---

## ๐Ÿš€ Quick Start

### Installation

```bash
pip install qwed-finance

Usage

from qwed_finance import FinanceVerifier

verifier = FinanceVerifier()

# Verify NPV calculation
result = verifier.verify_npv(
    cashflows=[-1000, 300, 400, 400, 300],
    rate=0.10,
    llm_output="$180.42"
)

if result.verified:
    print(f"โœ… Correct: {result.computed_value}")
else:
    print(f"โŒ Wrong: LLM said {result.llm_value}, actual is {result.computed_value}")

๐Ÿ“Š Supported Verifications

1. Time Value of Money

# Net Present Value
verifier.verify_npv(cashflows, rate, llm_output)

# Internal Rate of Return
verifier.verify_irr(cashflows, llm_output)

# Future Value
verifier.verify_fv(principal, rate, periods, llm_output)

# Present Value
verifier.verify_pv(future_value, rate, periods, llm_output)

2. Loan Calculations

# Monthly Payment
verifier.verify_monthly_payment(principal, annual_rate, months, llm_output)

# Amortization Schedule
verifier.verify_amortization_schedule(principal, rate, months, llm_schedule)

# Total Interest Paid
verifier.verify_total_interest(principal, rate, months, llm_output)

3. Interest Calculations

# Compound Interest
verifier.verify_compound_interest(
    principal=10000,
    rate=0.05,
    periods=10,
    compounding="annual",  # "monthly", "quarterly", "daily"
    llm_output="$16,288.95"
)

# Simple Interest
verifier.verify_simple_interest(principal, rate, time, llm_output)

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚              YOUR APPLICATION                    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                      โ”‚
                      โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚              QWED-FINANCE                        โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”               โ”‚
โ”‚  โ”‚   Finance   โ”‚  โ”‚   Banking   โ”‚               โ”‚
โ”‚  โ”‚  Verifier   โ”‚  โ”‚   Schemas   โ”‚               โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜               โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                      โ”‚
                      โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚           QWED-VERIFICATION (Core)               โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”         โ”‚
โ”‚  โ”‚  Math   โ”‚  โ”‚  Logic  โ”‚  โ”‚ Schema  โ”‚         โ”‚
โ”‚  โ”‚ (SymPy) โ”‚  โ”‚  (Z3)   โ”‚  โ”‚ (JSON)  โ”‚         โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜         โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ”’ Why Deterministic?

Financial calculations must be exact. AI hallucinations in banking can cause:

  • ๐Ÿ’ธ Wrong loan payments
  • ๐Ÿ“‰ Incorrect investment projections
  • โš–๏ธ Regulatory violations
  • ๐Ÿฆ Customer trust issues

QWED-Finance uses SymPy (symbolic math) instead of floating-point arithmetic, ensuring:

# Floating-point problem
>>> 0.1 + 0.2
0.30000000000000004

# QWED-Finance (SymPy)
>>> verifier.add_money("$0.10", "$0.20")
"$0.30"  # Exact!

๐Ÿ“ฆ Related Packages

Package Description
qwed-verification Core verification engine
qwed-ucp E-commerce verification
qwed-mcp Claude Desktop integration

๐Ÿค– GitHub Action for CI/CD

Automatically verify your banking AI agents in your CI/CD pipeline!

Quick Setup

  1. Create .github/workflows/qwed-verify.yml in your repo:
name: QWED Finance Verification

on: [push, pull_request]

jobs:
  verify:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - uses: QWED-AI/qwed-finance@v1.1.1
        with:
          test-script: tests/verify_agent.py
  1. Create your verification script tests/verify_agent.py:
from qwed_finance import ComplianceGuard, OpenResponsesIntegration

def test_aml_compliance():
    guard = ComplianceGuard()
    result = guard.verify_aml_flag(
        amount=15000,
        country_code="US",
        llm_flagged=True
    )
    assert result.compliant, f"AML check failed!"
    print("โœ… Verification passed!")

if __name__ == "__main__":
    test_aml_compliance()
  1. Commit and push - the action runs automatically! ๐Ÿš€

Action Inputs

Input Required Default Description
test-script โœ… - Path to your Python test script
python-version โŒ 3.11 Python version to use
fail-on-violation โŒ true Fail workflow on verification failure

Blocking Merges

To block PRs that fail verification, add this to your branch protection rules:

  • Settings โ†’ Branches โ†’ Add Rule
  • Check "Require status checks to pass"
  • Select "verify" job

๐Ÿ“„ License

Apache 2.0 - See LICENSE


๐Ÿค Contributing

Contributions welcome! Please read CONTRIBUTING.md first.


Built with โค๏ธ by QWED-AI

Twitter

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

qwed_finance-1.1.3.tar.gz (42.0 kB view details)

Uploaded Source

Built Distribution

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

qwed_finance-1.1.3-py3-none-any.whl (43.7 kB view details)

Uploaded Python 3

File details

Details for the file qwed_finance-1.1.3.tar.gz.

File metadata

  • Download URL: qwed_finance-1.1.3.tar.gz
  • Upload date:
  • Size: 42.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for qwed_finance-1.1.3.tar.gz
Algorithm Hash digest
SHA256 0e85721f3db6091118c3ea6402644436bcf9c8af32a5a38e315d82eb23053ac0
MD5 246f351c958b7110d7327e7db71a87a6
BLAKE2b-256 95caf3600c1fa06d7dc60a0a80bf1b5f8b880360e92b470a0dc51fa36497239a

See more details on using hashes here.

Provenance

The following attestation bundles were made for qwed_finance-1.1.3.tar.gz:

Publisher: publish.yml on QWED-AI/qwed-finance

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file qwed_finance-1.1.3-py3-none-any.whl.

File metadata

  • Download URL: qwed_finance-1.1.3-py3-none-any.whl
  • Upload date:
  • Size: 43.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for qwed_finance-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4f7b69528da8ddc5be5cf4ea7886bde23a1dd33bc90b94a39633c67df82d3877
MD5 ffda5e8b4a4d5ebd7c23017bcb943702
BLAKE2b-256 8ff912cb4cf95b53f38f5210fec4216f5ba4b0a4b0251f89f4d4d0ee5a5a1e0e

See more details on using hashes here.

Provenance

The following attestation bundles were made for qwed_finance-1.1.3-py3-none-any.whl:

Publisher: publish.yml on QWED-AI/qwed-finance

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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