Notes / Put–call parity as a unit test
Put–call parity as a unit test
Using a no-arbitrage identity to catch bugs in an option pricer.
The identity
For European call and put options on the same non-dividend-paying asset, with the same strike and expiry, put–call parity states:
Here C and P are the call and put prices, S is the spot price, K is the strike, r is the continuously compounded risk-free rate and T is the time to expiry. Assume frictionless trading and that borrowing and lending use that rate. The discounted strike uses the same time and rate conventions as the pricer.
Why this is not a model result
Compare a call plus cash that will pay the strike at expiry with a put plus the underlying asset. At expiry, either portfolio pays the greater of the asset price and the strike. Since their pay-offs match in every state, no arbitrage requires their prices to match today. Rearranging gives parity.
There is no volatility assumption in that argument. This is a replication identity under the stated contract and market assumptions, not a special property of Black–Scholes. Dividends or early exercise change the relationship; do not apply this version to those contracts unchanged.
Turning it into a unit test
Compute C and P from exactly the same inputs: spot, strike, expiry, rate, volatility and contract conventions. Compute the reference difference independently of the option-pricing branches, then compare it with the call price minus the put price.
Use an absolute tolerance plus a relative tolerance multiplied by a price scale. A sensible scale is the largest magnitude among the two option prices, spot and the discounted strike. Scaling only by the reference difference is fragile when that difference is near zero. Choose tolerances to reflect the numerical method and floating-point precision, and reject non-finite prices before comparing them.
Repeat the test across the input domain, including near expiry and away from the strike. For approximate methods, allow for their documented approximation error rather than hiding failures with an arbitrarily loose tolerance.
What failures tell us
A failure can expose a sign error in a put branch or in the subtraction, incorrect discounting, or different inputs reaching the two pricing paths. Check time units, rate conventions and contract flags as well as the formula itself. The test gives a reproducible inconsistency to investigate, not a diagnosis on its own.
What the test cannot prove
An identical additive error in both legs cancels in their difference, so both prices can be wrong while parity still passes. Shared input mistakes can also survive if the reference calculation repeats them. Keep this test alongside independent reference cases and boundary checks. Passing parity establishes consistency with one identity; it does not establish that the pricer is correct.