Deterministic verification middleware for banking and financial AI
Project description
QWED-Finance ๐ฆ
Deterministic verification middleware for banking and financial AI.
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 |
๐ก What QWED-Finance Is (and Isn't)
โ QWED-Finance IS:
- Verification middleware that checks LLM-generated financial outputs
- Deterministic โ uses symbolic math (SymPy) and formal proofs (Z3)
- Open source โ integrate into any fintech workflow, no vendor lock-in
- A safety layer โ catches calculation errors before they cause real losses
โ QWED-Finance is NOT:
A trading platformโ use Bloomberg or Refinitiv for thatA market data providerโ use AlphaSense or FactSet for thatAn analytics dashboardโ use Koyfin or Morningstar for thatA replacement for risk modelsโ we just verify their outputs
Think of QWED-Finance as the "unit test" for AI-generated financial calculations.
Bloomberg provides data. AlphaSense analyzes. QWED verifies the math.
๐ How We're Different from Financial AI Platforms
| Aspect | Bloomberg / Refinitiv / AlphaSense | QWED-Finance |
|---|---|---|
| Approach | Probabilistic AI analytics | Deterministic symbolic verification |
| Output | "NPV is approximately $180.42" | VERIFIED: NPV = $180.42 โ (with proof) |
| Accuracy | ~95% (estimation, approximation) | 100% mathematical certainty |
| Tech | ML models, LLMs | SymPy + Z3 SMT Solver |
| Model | $20k+/year enterprise SaaS | Free (Apache 2.0 License) |
| Data | Proprietary market data | Your data, verified locally |
Use Together (Best Practice)
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
โ Bloomberg โ โโโบ โ QWED-Finance โ โโโบ โ Verified โ
โ (AI outputs) โ โ (verifies) โ โ Output โ
โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ
๐ก๏ธ The Six 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, ...}
4. Message Guard (ISO 20022 / SWIFT)
Validate LLM-generated banking messages conform to industry standards.
from qwed_finance import MessageGuard, MessageType
guard = MessageGuard()
# Verify ISO 20022 pacs.008 message
result = guard.verify_iso20022_xml(
xml_string=llm_generated_xml,
msg_type=MessageType.PACS_008
)
# result.valid = True/False with detailed errors
# Verify IBAN checksum
iban_result = guard.verify_iban(
iban="DE89370400440532013000",
llm_says_valid=True
)
# Uses MOD 97 checksum - 100% deterministic
Supports:
- ISO 20022: pacs.008, pacs.002, camt.053, camt.054, pain.001
- SWIFT MT: MT103, MT202, MT940, MT950
- BIC/IBAN validation with MOD 97 checksum
5. Query Guard (SQL Safety)
Prevent LLM-generated SQL from mutating data or accessing restricted tables.
from qwed_finance import QueryGuard
guard = QueryGuard(allowed_tables={"accounts", "transactions"})
# Verify query is read-only
result = guard.verify_readonly_safety(
sql_query="SELECT * FROM accounts WHERE balance > 10000"
)
# result.safe = True โ
# Block mutation attempts
result = guard.verify_readonly_safety(
sql_query="DROP TABLE accounts;" # LLM hallucinated this
)
# result.safe = False, result.risk_level = CRITICAL โ
Prevents:
- DELETE, UPDATE, INSERT, DROP statements
- Unauthorized table access
- PII column exposure (SSN, passwords)
- SQL injection patterns
6. Cross Guard (Multi-Layer Verification)
Combine multiple guards for comprehensive verification.
from qwed_finance import CrossGuard
guard = CrossGuard()
# SWIFT message + Sanctions check
result = guard.verify_swift_with_sanctions(
mt_string=llm_mt103_message,
sanctions_list=["SANCTIONED CORP", "BLOCKED ENTITY"]
)
# Validates MT format AND scans for sanctioned entities
# SQL + PII protection
result = guard.verify_query_with_pii_protection(
sql_query="SELECT * FROM customers",
allowed_tables=["customers", "orders"],
pii_columns=["ssn", "password", "credit_card"]
)
7. Bond Guard (NEW in v2.0) ๐
Yield and duration calculations for fixed income verification.
from qwed_finance import BondGuard
guard = BondGuard()
# Verify YTM calculation
result = guard.verify_ytm(
face_value=1000,
coupon_rate=0.05, # 5% annual coupon
price=950, # Trading at discount
years_to_maturity=10,
llm_ytm="5.73%" # LLM's answer
)
# Uses Newton-Raphson solver - 100% deterministic
# Verify Duration
result = guard.verify_duration(
face_value=1000,
coupon_rate=0.05,
ytm=0.06,
years_to_maturity=10,
llm_duration="7.8 years"
)
# Verify Convexity
result = guard.verify_convexity(
face_value=1000,
coupon_rate=0.05,
ytm=0.06,
years_to_maturity=10,
llm_convexity="68.5"
)
Supports:
- Yield to Maturity (YTM) - Newton-Raphson solver
- Macaulay Duration
- Modified Duration
- Convexity
- Accrued Interest
- Dirty Price
8. FX Guard (NEW in v2.0) ๐
Foreign exchange rate verification using Interest Rate Parity.
from qwed_finance import FXGuard
guard = FXGuard()
# Verify Forward Rate (Interest Rate Parity)
result = guard.verify_forward_rate(
spot_rate=1.10, # EUR/USD spot
domestic_rate=0.05, # USD rate
foreign_rate=0.02, # EUR rate
days=90, # 90-day forward
llm_forward="1.1081" # LLM's answer
)
# Formula: F = S ร (1 + rd ร T) / (1 + rf ร T)
# Verify Cross Rate Triangulation
result = guard.verify_cross_rate(
rate_a_b=1.10, # EUR/USD
rate_b_c=150.0, # USD/JPY
llm_rate_a_c="165.00", # EUR/JPY
pair_a="EUR", pair_b="USD", pair_c="JPY"
)
# Verify NDF Settlement
result = guard.verify_ndf_settlement(
notional=1000000,
contract_rate=1.10,
fixing_rate=1.12,
llm_settlement="$17,857.14"
)
Supports:
- Forward Rate (IRP)
- Cross Rate Triangulation
- Swap Points
- NDF Settlement
- Currency Conversion
- Triangular Arbitrage Detection
9. Risk Guard (NEW in v2.0) ๐
Portfolio risk metrics verification - VaR, Beta, Sharpe.
from qwed_finance import RiskGuard
guard = RiskGuard()
# Verify VaR (Parametric)
result = guard.verify_var(
portfolio_value=1000000,
daily_volatility=0.02, # 2% daily vol
confidence_level=0.95, # 95% confidence
holding_period_days=1,
llm_var="$32,900" # LLM's answer
)
# Formula: VaR = P ร ฯ ร z ร โt
# Verify Sharpe Ratio
result = guard.verify_sharpe_ratio(
portfolio_return=0.12, # 12% annual return
risk_free_rate=0.03, # 3% risk-free
portfolio_volatility=0.15,
llm_sharpe="0.60"
)
# Verify Beta
result = guard.verify_beta(
asset_returns=[0.02, -0.01, 0.03, 0.01, -0.02],
market_returns=[0.01, -0.005, 0.02, 0.005, -0.01],
llm_beta="1.45"
)
# Verify Maximum Drawdown
result = guard.verify_max_drawdown(
portfolio_values=[100, 110, 105, 95, 100, 98],
llm_max_dd="-13.64%"
)
Supports:
- Value at Risk (Parametric VaR)
- Portfolio Beta
- Sharpe Ratio
- Sortino Ratio
- Maximum Drawdown
- Expected Shortfall (CVaR)
- Information Ratio
๐ Quick Start
Installation
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!
๐ Security & Privacy
Your financial data never leaves your machine.
| Concern | QWED-Finance Approach |
|---|---|
| Data Transmission | โ No API calls, no cloud processing |
| Storage | โ Nothing stored, pure computation |
| Dependencies | โ Local-only (SymPy, Z3, SQLGlot) |
| Audit Trail | โ Cryptographic receipts, fully reproducible |
Perfect for:
- Banks with strict data residency requirements
- Transactions containing PII (SSN, account numbers)
- SOC 2 / PCI-DSS compliant environments
- Air-gapped trading systems
โ FAQ
Is QWED-Finance free?
Yes! QWED-Finance is open source under the Apache 2.0 license. Use it in commercial fintech products, modify it, distribute it - no restrictions.
Does it handle floating-point precision issues?
Yes! QWED-Finance uses SymPy for symbolic mathematics, avoiding the classic 0.1 + 0.2 = 0.30000000000000004 problem. All monetary calculations are exact.
Can it verify Black-Scholes calculations?
Yes! The DerivativesGuard includes full Black-Scholes implementation with Greeks (delta, gamma, theta, vega, rho). All calculations use symbolic math for precision.
Does it support ISO 20022?
Yes! MessageGuard validates ISO 20022 XML messages (pacs.008, camt.053, pain.001) and legacy SWIFT MT formats (MT103, MT202, MT940).
Can I use it to prevent SQL injection in AI agents?
Yes! QueryGuard uses SQLGlot for AST-based analysis. It can block mutations, restrict table access, and prevent PII column exposure - all deterministically.
How fast is verification?
Typically <5ms for simple calculations, <50ms for complex derivatives pricing. The symbolic engine is highly optimized.
๐บ๏ธ Roadmap
โ Released (v1.0.0)
- FinanceVerifier: NPV, IRR, FV, PV calculations
- ComplianceGuard: KYC/AML verification (Z3)
- CalendarGuard: Day count conventions
- DerivativesGuard: Black-Scholes, Greeks
- MessageGuard: ISO 20022, SWIFT MT, IBAN/BIC
- QueryGuard: SQL safety, PII protection
- CrossGuard: Multi-layer verification
- Verification Receipts with audit trail
- TypeScript/npm SDK (@qwed-ai/finance)
๐ง In Progress
- Bond pricing verification (yield to maturity)
- FX forward rate calculations
- More regulatory frameworks (MiFID II, Basel III)
๐ฎ Planned
- Portfolio risk verification (VaR, CVaR)
- Credit risk models (PD, LGD, EAD)
- Real-time market data validation
- Integration with OpenBB Terminal
- VS Code extension for trading desk
๐ฆ 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
- Create
.github/workflows/qwed-verify.ymlin 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
- 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()
- 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
๐ Add "Verified by QWED" Badge
Show that your project uses QWED verification! Copy this to your README:
[](https://github.com/QWED-AI/qwed-finance)
Preview:
๐ License
Apache 2.0 - See LICENSE
๐ค Contributing
Contributions welcome! Please read CONTRIBUTING.md first.
Built with โค๏ธ by QWED-AI
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file qwed_finance-2.0.1.tar.gz.
File metadata
- Download URL: qwed_finance-2.0.1.tar.gz
- Upload date:
- Size: 58.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9569d569b2ad6233eea44ea055ffe875e274ac7fb46901c86444ff83b17ace2c
|
|
| MD5 |
3a4170917d8b6ee9c7f14da04b39f6e4
|
|
| BLAKE2b-256 |
c6aff7642c1ebdb2383c7f8c4c85a64db04c91146b37c94f03c489965ea20782
|
Provenance
The following attestation bundles were made for qwed_finance-2.0.1.tar.gz:
Publisher:
publish.yml on QWED-AI/qwed-finance
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qwed_finance-2.0.1.tar.gz -
Subject digest:
9569d569b2ad6233eea44ea055ffe875e274ac7fb46901c86444ff83b17ace2c - Sigstore transparency entry: 868684904
- Sigstore integration time:
-
Permalink:
QWED-AI/qwed-finance@3ce0654b1cc4623edfe4247928c6901ddf96cc2c -
Branch / Tag:
refs/tags/v2.0.1 - Owner: https://github.com/QWED-AI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3ce0654b1cc4623edfe4247928c6901ddf96cc2c -
Trigger Event:
release
-
Statement type:
File details
Details for the file qwed_finance-2.0.1-py3-none-any.whl.
File metadata
- Download URL: qwed_finance-2.0.1-py3-none-any.whl
- Upload date:
- Size: 58.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb9b1acedb10052854fc483748fe7aa2ee89fb964280e37e90330ba14ab823e5
|
|
| MD5 |
81f835fbe8a0d703f2d278fe04a859ca
|
|
| BLAKE2b-256 |
a8f8190d7fbb5aaf1b1191600484d1a30818ce8f8053b77a9371a0afbc04a20a
|
Provenance
The following attestation bundles were made for qwed_finance-2.0.1-py3-none-any.whl:
Publisher:
publish.yml on QWED-AI/qwed-finance
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qwed_finance-2.0.1-py3-none-any.whl -
Subject digest:
cb9b1acedb10052854fc483748fe7aa2ee89fb964280e37e90330ba14ab823e5 - Sigstore transparency entry: 868684906
- Sigstore integration time:
-
Permalink:
QWED-AI/qwed-finance@3ce0654b1cc4623edfe4247928c6901ddf96cc2c -
Branch / Tag:
refs/tags/v2.0.1 - Owner: https://github.com/QWED-AI
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3ce0654b1cc4623edfe4247928c6901ddf96cc2c -
Trigger Event:
release
-
Statement type: