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.2.tar.gz (42.1 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.2-py3-none-any.whl (43.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: qwed_finance-1.1.2.tar.gz
  • Upload date:
  • Size: 42.1 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.2.tar.gz
Algorithm Hash digest
SHA256 2452163c6283ab127eab3d6363652ba2cc93398c1131a90f72484aecc85897ca
MD5 ac67d5c356b8f7a512a0c2e49fa9aca9
BLAKE2b-256 62bebb8c1f2d78452edd43c07f952de615c6870030c2ec0e43e199c1b6fc39b6

See more details on using hashes here.

Provenance

The following attestation bundles were made for qwed_finance-1.1.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: qwed_finance-1.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a94ffceedf69ee1dd3156ffbe9faf9b6869dbfb9070782c85f58aff04d1d9622
MD5 25c5e7992a1b0a41aef1b395a82f7c10
BLAKE2b-256 cf1ad642c630aebc038919d7ee81a06626d88bd5e8cb908f1ddfbb189ff42615

See more details on using hashes here.

Provenance

The following attestation bundles were made for qwed_finance-1.1.2-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