Skip to content
Python for Quantitative Finance / Model and software design

Testing Numerical Code

A floating-point function that "looks about right" is not tested. Numerical code needs oracles: a closed form, a finite-difference bump, an algebraic invariant (put–call parity, probabilities that sum to one), and a stated tolerance. Seeds turn stochastic routines into replayable checks. This lesson builds that toolkit for the curve and Black–Scholes objects from object-oriented model design.
Learning objectives. By the end of this note you should be able to:
  • write a closed-form regression test with an absolute or relative tolerance;
  • check a first-order Greek by central finite differences;
  • encode put–call parity and a discrete probability simplex as asserts;
  • seed Monte Carlo so a test fails for logic bugs, not for fresh noise.

In this lesson

  1. Oracles beat vibes
  2. Invariants
  3. Finite-difference bumps
  4. Seeded randomness
  5. A minimal pytest-shaped layout
  6. Table of oracle types

Before you start

The full lesson, with worked examples and exercise solutions, is for members.

Read the full lesson

New to SelfMadeQuant.com? See membership options or browse the Python for Quantitative Finance syllabus.