Skip to main content

Deterministic verification middleware for banking and financial AI

Project description

QWED-Finance ๐Ÿฆ

Deterministic verification middleware for banking and financial AI.

License Python 3.10+

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

๐Ÿ“„ 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-0.1.0.tar.gz (40.7 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-0.1.0-py3-none-any.whl (43.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for qwed_finance-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bc4e16772f49df75f2949dfcfc71fd29c6b100fbb55d941b934905d194109fa4
MD5 4cb1ac3df3a64a237050ec164812f24b
BLAKE2b-256 5a414da1975a4ce12c2812607f5bd7ab6398e34a120bfd256cc0863432fcfbe0

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: qwed_finance-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 43.0 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-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 87a5d26970fb74f90b389997a9b32bbb43343906b10959755ebb6960710a2c19
MD5 e5cdc6834ca1d0364711c06953a6a766
BLAKE2b-256 618f82ab787e4c0db4dae2da475ea177397d458fb6e27df7613c9a5deb9e698c

See more details on using hashes here.

Provenance

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