What you will learn
- Unit and invariant checks
- Golden datasets
- Numerical tolerance
- Independent result reconciliation
Unit and invariant checks
Unit checks test a bounded calculation; invariants test properties that should hold across many cases. For accounting, examples include quantity reconciliation and gross-minus-costs equalling net result under the stated convention.
Golden datasets
A golden dataset is a small, independently understood set of inputs and expected outputs. It should include losses, partial fills and invalid cases rather than mirror only the current implementation's happy path.
Numerical tolerance
Numerical tolerance should reflect units and the calculation, not merely be loosened until tests pass. Explain why a difference is acceptable and keep accounting rounding distinct from floating-point approximation.
Independent result reconciliation
Independent reconciliation compares the system with a separate calculation or authoritative record. Two outputs from the same flawed function are not independent confirmation. Investigate differences before publishing the result.
Worked example
A test calculates its expected P&L by calling the same function it is testing. It passes even when the function reverses short direction. The expected result must come from an independent calculation.
Try it yourself
Create three meaningful test cases for the P&L function: a winning short, a zero-size position and an invalid multiplier.
Show the worked solution
Use known arithmetic for the short, expect zero gross P&L for zero quantity under the allowed contract, and require an explicit error for an invalid multiplier. These cases test behavior rather than restating the implementation.
Apply this to your course project
Deliver a small tested pipeline from raw observations to a research report.
Keep the calculation inputs, assumptions and decisions with your work. Practical exercises are self-reviewed; the scored knowledge checks assess the questions shown, not an independent certification of practical competence.