Testing
Q1. How do you test numerical and pricing code?
Q1. How do you test numerical and pricing code?
- Analytical benchmarks: Compare against cases with closed-form solutions, such as Black-Scholes for European options.
- Property tests: Check relationships that must always hold, such as put-call parity, call prices falling and convex in strike, and a call delta between 0 and 1.
- Numeric tolerance: Never compare floats for equality. Use absolute or relative tolerances.
- Golden tests: Save verified outputs and confirm results do not change during refactoring.
- Randomness: Fix the seed for Monte Carlo and verify convergence statistically.
- Edge cases: Extreme volatility, near expiry, deep in and out of the money, zero rates.
Q2. What does determinism mean for a trading system, and how do you achieve it?
Q2. What does determinism mean for a trading system, and how do you achieve it?
- Wall-clock time: Inject a clock that can be driven by recorded timestamps instead of reading the system time directly.
- Randomness: Seed generators explicitly and record the seed.
- Iteration order: Do not depend on the order of unordered collections.
- Parallel reductions: Fix the order of floating-point accumulation when exact results matter.
- External state: Pass all inputs in explicitly (market data, configuration, positions) so a run can be reproduced from a recorded input set.
Q3. How do you make a trading component testable?
Q3. How do you make a trading component testable?
- Inject dependencies: Clock, market data source, order gateway and position store come in as interfaces, so tests can substitute fakes.
- Replay-based tests: Feed recorded market data and assert on the orders produced.
- Simulated venue: A simple exchange simulator that can reject, delay, partially fill and disconnect, so error paths are exercised and not just the happy path.
- Small pure functions: Keep pricing and sizing logic free of I/O so it is easy to test exhaustively.
- Failure injection: Test stale data, duplicated messages, out-of-order messages and sudden disconnects on purpose.
Data types and correctness
Q4. Float or Decimal for prices and money? How do you handle tick sizes?
Q4. Float or Decimal for prices and money? How do you handle tick sizes?
Q5. What goes wrong with time handling in trading code?
Q5. What goes wrong with time handling in trading code?
- Time zones and daylight saving: Store UTC internally and convert only at the edges.
- Trading calendars: Holidays, half days and auction periods differ per market, so use a maintained calendar rather than weekday logic.
- Clock differences: Exchange timestamps, vendor timestamps and local receive times can disagree. Record which clock each timestamp comes from.
- Precision: Millisecond, microsecond and nanosecond sources must not be mixed silently.
- Day boundaries: Define what “the same day” means for markets in different time zones.
Q6. Your rolling variance of returns sometimes comes out negative. What is wrong?
Q6. Your rolling variance of returns sometimes comes out negative. What is wrong?
- Use a numerically stable update such as Welford’s algorithm, which tracks the running mean and the sum of squared deviations from it.
- Center the data first (subtract a reference value) when using a one-pass formula.
- For rolling windows, recompute from scratch periodically or use a stable add-and-remove update, and clamp tiny negative values only after fixing the method.
Q7. How do you make an implied volatility solver robust?
Q7. How do you make an implied volatility solver robust?
- Check arbitrage bounds first: a price below intrinsic value or above the upper bound has no implied volatility. Return an explicit error rather than a number.
- Bracket the root: use a bracketing method (bisection or Brent) between a low and a high volatility, or fall back to it when a Newton step leaves the bracket.
- Good starting point: use an approximation for the initial guess to cut iterations.
- Tolerance on price, not only volatility: stop when the price error is within a tick-sized tolerance.
- Test the edges: near expiry, zero rates, very high volatility, and prices exactly at the bounds.
Review and maintainability
Q8. How would you review a pull request that changes a pricing function?
Q8. How would you review a pull request that changes a pricing function?
- Start with the purpose of the change and its blast radius: who calls this function.
- Check formulas, units, signs, boundary conditions, time zones and input validation.
- Check that tests cover the new behavior and compare outputs against the old version.
- Look at performance changes and memory, and whether configuration, passwords or keys were written into the code.
- Release plan: whether it needs a staged rollout or shadow mode, and whether it can be rolled back quickly.
Q9. What logging and metrics would you add to a live trading component?
Q9. What logging and metrics would you add to a live trading component?
- Structured logs with a correlation ID that follows an order or quote through every component, so one decision can be reconstructed end to end.
- Metrics: Latency percentiles, message rates, queue depths, rejection rates, stale-data counters and position breaks.
- Audit trail: An append-only record of orders, fills, parameter changes and operator actions.
- Alerts on symptoms that matter (no market data, rising rejects, position mismatch), not on every warning.
- Cost awareness: Logging on the hot path can itself add latency, so buffer it and write asynchronously.

