Why do financial figures go wrong?
- The wrong formula. Simple interest where the question meant compound, or a payment formula for the wrong term.
- The wrong convention. Monthly compounding instead of annual, or a 360-day year instead of 365.
- Inexact arithmetic. Ordinary floating-point numbers cannot hold most decimal fractions exactly, and small errors add up over many payments.
- A figure that changes on the way. Even when a tool computed it, the model copies the result into its answer, and a digit can change there.
"Hallucination" is the usual word for all of these. A check does not detect hallucinations in general text; it recomputes a figure and compares. Can LLMs do maths?
How do you check a financial figure?
- Ask for the inputs, not only the answerHave the model return the principal, rate, term, compounding and cash flows it used, as structured output, beside the figure it claims.
- Recompute outside the modelWork the figure out again from those inputs with exact decimal arithmetic, the compounding and day count the question asks for, and money rounded to the cent.
- Compare within a stated toleranceAccept the figure only when the two agree within a tolerance you can name, such as one cent.
- Act only on a matchHold anything else for the model to try again, or for a person, and keep the inputs, both figures and the result as the record.
An example
A model is asked for the value of 10,000 at 5% a year, compounded annually, after 10 years. Two answers, checked with QWED Finance 3.0.1:
| The model said | Recomputed | Difference | Result |
|---|---|---|---|
| $16,288.95 | $16,288.95 | 0 | verified: True |
| $16,470.09 | $16,288.95 | 181.14 | verified: False |
The second figure is what monthly compounding gives. It is a plausible number, and a reader would not notice; the recomputation does. To run it (pip install qwed-finance):
from qwed_finance import FinanceVerifierverifier = FinanceVerifier()# The question asked for annual compounding.for figure in ("$16,288.95", "$16,470.09"): result = verifier.verify_compound_interest( principal=10000, rate=0.05, periods=10, compounding="annual", llm_output=figure ) print(result.verified, result.computed_value, result.difference, result.formula_used)# True $16,288.95 None A = P(1 + r/1)^(1t)# False $16,288.95 181.14 A = P(1 + r/1)^(1t)What QWED Finance checks
Its FinanceVerifier recomputes five kinds of figure from the inputs you pass, in Python's Decimal rather than floating point, with money rounded half up to the cent, and accepts the model's figure within a fixed tolerance:
| Check | Recomputes | Accepted within |
|---|---|---|
verify_npv | Net present value of a series of cash flows | one cent |
verify_irr | Internal rate of return | 0.0001 by default |
verify_monthly_payment | The monthly payment on a loan | one cent |
verify_total_interest | Total interest paid over a loan | ten cents |
verify_compound_interest | A compounded amount, annual to daily | one cent |
The package also has guards for other figures and messages: bond yields and duration, FX rates by interest rate parity, risk metrics such as VaR, beta and Sharpe, day-count conventions, Black-Scholes prices, ISO 20022 and SWIFT payment messages, KYC and AML rules checked with Z3, and SQL. QWED Finance · Banking and payments
The package returns verified: True or False with the recomputed figure. Your application decides what happens next; QWED Finance does not hold or release anything by itself.
What it does not check
- Whether the inputs are right. The check recomputes from the principal, rate and terms it is given. If the model picked the wrong rate, the check confirms the arithmetic on the wrong rate.
- Which formula the question needed. You choose the check and the compounding. A figure that matches the wrong formula passes that formula.
- Anything inside the tolerance. A figure within a cent passes, as does a total within ten cents.
- The currency. The figure is read without its currency symbol, so €16,288.95 passes a check in dollars (qwed-finance#114, open).
- Its own open bugs. QWED Finance is a beta package with open bug reports, some of which change a result for some inputs. Read the list before relying on it for a case. Known open issues
- Regulation. It checks figures and messages. It is not a trading platform, a market data feed or a replacement for your risk models, and checks for MiFID II and Basel III are still in progress.
Everything QWED does not verify
Sources and further reading
- qwed-finance. The package’s source, README and open issues.
- QWED Finance documentation. The package’s own documentation.
- Python documentation: decimal. Decimal fixed point and floating point arithmetic, the kind money needs.
Written and reviewed by the QWED maintainers under the project's governance model. Found an error? Contact us.
