A modified algorithm can pass tests and produce the same amounts as the old one while still carrying an old error or violating a new rounding rule. So the question is not only whether the program runs without failures. You need to establish what exactly it must conform to, and gather evidence for the formula, the numerical arithmetic, and the implementation separately.
Verification checks an implementation against the requirements, but it does not establish the truth of the requirements themselves. This distinction underlies the NIST approach to verification and validation. A formal proof likewise pertains to the chosen model: by itself it does not confirm the correctness of the input data, the production configuration, the compiler, or the execution of the code.
1. Fix the calculation specification
Before comparing versions, agree on a document from which the expected result can be determined independently. It must include:
- Purpose of the calculation: what is being accrued or estimated and for what period.
- Inputs and units: currency, the scale of monetary values, the rate, the period, and the permissibility of negative values and missing values.
- Formula and domain: including the conditions under which the calculation is impossible or must terminate with an error.
- Rounding: precision of intermediate computations, rounding points and modes, and the scale of the final amount.
- Constraints and properties of the result: for example, the permitted range, monotonicity under agreed conditions, and boundary-handling rules.
- Acceptance criteria: when exact agreement is required, when a deviation is tolerable, and who approves exceptions.
The specification must be confirmed by the owner of the calculation, with relevant specialists involved. Contractual, accounting, and regulatory rules depend on the task and the jurisdiction: no universal monetary scale or error threshold can be set for all calculations.
2. Prove the properties of the formula on the model
Separate preconditions from postconditions. Preconditions define the admissible inputs; postconditions describe the result and the required properties. Then check dimensions, boundaries, division by zero, and transformations of the formula. If the new version changes only the method of computation, prove the equivalence of the transformations over the entire admissible domain, not just on examples.
Illustrative interest accrual example
Suppose the following training specification for simple interest has been agreed:
P- a non-negative amount in monetary units;r- a non-negative annual rate expressed as a fraction of one;d- an integer number of days from0to360inclusive;- before final rounding,
I = P * r * d / 360; - the result is rounded to
0.01of a monetary unit: at exactly half a step - upward; - invalid inputs are rejected; no intermediate rounding is applied.
This is an example, not an interest rule for a specific contract. Under these preconditions I >= 0; with P = 0, r = 0, or d = 0 the result is zero. With the other inputs fixed, increasing any of P, r, or d does not decrease the exact value of I; the chosen final rounding preserves this property.
If the new formula uses, for example, (P * r / 360) * d, it is equivalent to the original in exact arithmetic. But with finite precision or intermediate rounding, this reordering of operations does not necessarily yield the same amount. Algebraic equivalence is not enough to conclude that the programs are equivalent.
An example of a rounding proof
For this example, an independent reference can be built on exact rational numbers. Let the exact amount in hundredths of a unit be 100 * I = N / D, where N is a non-negative integer and D is a positive integer. Find integers q and rem such that N = q * D + rem and 0 <= rem < D.
The result in hundredths equals q + 1 if 2 * rem >= D, and q otherwise. Indeed, the fractional part equals rem / D: the first condition means it is not less than half. Hence the rule implements the specified rounding for every admissible input of the model. With exact intermediate computations, the absolute difference between the rounded and the exact value does not exceed 0.005 of a monetary unit.
This proof does not show that a particular piece of code converts inputs into N and D correctly, avoids type overflows, or runs with the required configuration. These assumptions must be checked separately. If the specification admits negative amounts, a rule for them must be defined and proved separately.
3. Check the numerical arithmetic
Choose the data representation to suit the specification and show where precision is lost. Decimal arithmetic represents many decimal values exactly and is useful where strict equalities matter. Still, finite precision and intermediate operations can trigger rounding; the Python Decimal documentation recommends, for diagnostic purposes, repeating the computation with higher precision and different rounding modes.
To check the implementation, determine:
- How inputs are converted to the numeric type: whether precision is already lost when the data is read.
- What the precision and range of intermediate values are, and whether overflow or invalid operations are possible.
- Exactly where rounding happens and whether its mode matches the requirements.
- How the error of intermediate operations propagates to the total, and whether the chosen method is robust against significant losses of precision.
- Whether the rule survives transmission, storage, and re-reading of the result.
Repeating the computation with higher precision or a different mode helps reveal the sensitivity of the calculation, but by itself it proves nothing about correctness. The properties of a particular tool, such as Python Decimal, do not replace the applicable accounting, contractual, or regulatory rules.
4. Check the implementation with independent examples
Expected results must follow from the specification or an independent reference, not be computed by the same code under test. For the training example above, a control set might look like this:
P |
r |
d |
Expected result | What is checked |
|---|---|---|---|---|
1000 |
0.05 |
30 |
4.17 |
Fractional result: 1000 * 0.05 * 30 / 360 = 4.1666... |
1000 |
0.05 |
360 |
50.00 |
Upper period boundary |
1000 |
0.05 |
0 |
0.00 |
Zero period |
1 |
0.018 |
100 |
0.01 |
Exactly half a step: I = 0.005 |
1000 |
0.05 |
-1 |
Input error | Negative period outside the example's domain |
Extend the table with cases on both sides of rounding boundaries, maximum admissible values, incorrect formats, and checks of all significant branches. Include reproducible cases of previously fixed defects. The NIST developer verification guide describes automated checks, specification-based testing, boundary and structural tests, and the reuse of tests for former defects.
Property checks are useful across a range of inputs: under the conditions of the training example, increasing P with the other inputs fixed must not decrease the result. But testing a sample confirms behavior only on the checked cases. To extend the conclusion to all admissible inputs, you need a proof for the model and, separately, a justified link between the model and the implementation.
5. Compare the old and new versions
Run both implementations on the same inputs and record not only the amounts but also the code versions, parameters, rounding rules, and data. For each discrepancy, determine:
- whether it stems from an intentional change to the requirements;
- whether it is related to precision, the order of operations, or settings;
- which version conforms to the independent reference;
- whether it affects significant amounts or groups of operations.
Agreement between versions is useful as a regression signal, but it does not prove correctness: both implementations can inherit the same error. A discrepancy does not prove a defect in the new version either - it may be fixing the old calculation. Unexplained deviations cannot be automatically considered admissible: they are assessed against criteria agreed in advance.
6. Match the depth of review to the risk
For a significant calculation, commission an independent, competent reviewer to challenge the formula, the data, the assumptions, the reference, and the test results. The more serious the possible consequences of an error, the more important the independence of the review and the completeness of the evidence.
For complex quantitative models, additional useful measures include reviewing input data and assumptions, testing outside the sample or development period, comparing forecasts with actual outcomes, and monitoring deviations. Such checks characterize the model's behavior under the available conditions, but they do not replace a proof of conformance to the specification and do not yield a universal conclusion for all inputs.
For context, you may consult the SR 26-2 guidance on model risk management. Before use, verify the status and scope of the document against the primary source. In particular, check the conditions of applicability to banking organizations, the presence of binding mandates, and the conditions under which simple arithmetic calculations, deterministic rules, and software without underlying statistical, economic, or financial theory are excluded. The guidance must not be presented as a universal mandatory rule for any financial calculation.
7. Decide on deployment and preserve the evidence
Before launch, agree on acceptance criteria and on the actions to take if they are not met. Record the specification and implementation versions, the configuration, the input sets, the reference, the review results, the analysis of discrepancies, the known limitations, and the decision of the responsible person. Reproducibility matters: another reviewer must understand which data and settings produced the recorded result.
If necessary, start with a limited rollout, provide a way to stop or roll back to the previous version, and monitor for deviations. If the data, the environment, or the calculation rules change, assess which evidence and tests need updating.
Pre-acceptance checklist:
- [ ] The specification and its assumptions are confirmed by the owner of the calculation.
- [ ] The formula, domain, and key properties are verified; the limits of the mathematical proof are disclosed.
- [ ] The number representation, precision, and rounding points are justified.
- [ ] Independent control results and tests are reproducible.
- [ ] Discrepancies between versions are explained relative to the specification or the reference.
- [ ] The limitations of the review and the deployment decision are documented.
- [ ] Follow-up monitoring and actions on deviations are defined.