Options Pricing Engine
Hard ● Live C++ Rust Java PythonThe Problem
Price 500,000 European options contracts using the Black-Scholes model. For each contract, compute the theoretical price and the five key Greeks (delta, gamma, vega, theta, rho).
Handle numerical stability for extreme market conditions, optimize for speed, and ensure precision to 6 decimal places.
Evaluation Criteria
Correctness (70%)
All Greeks and prices must be computed correctly using the Black-Scholes model. Output tolerance: 0.0001 per value.
Performance (30%)
Wall-clock time on the 500K option dataset. Memory usage (peak RSS).
Input Format
- First line
N= number of options to price.- Each row
S,K,T,r,sigma,typewhere type isC(call) orP(put).- S, K
- underlying spot price and strike, both as floats.
- T
- time to expiry in years (e.g.,
0.5573for ~6 months). - r
- risk-free rate (annualized, e.g.,
0.025). - sigma
- annualized volatility (e.g.,
0.40).
Output Format & Sample
Sample input (first 8 lines, full file linked below):
10 145.91401976868258,118.19098374774204,0.5573083435545473,0.025624751670417594,0.4682356070820062,C 138.57387686735595,112.62080113909408,0.19645352732456897,0.026286262537351772,0.40100936452499014,C 157.40294193836053,170.07859918986685,0.8448444437137009,0.04144463323986976,0.23909535411533137,C 163.8211050694651,141.51911031297107,0.8510026523254701,0.02945099391701493,0.2076568810537944,P 65.33154147797731,62.19372766246351,0.7243689671644106,0.03407690057352798,0.23226043361100654,C 159.45976800407269,161.77053722751145,1.9465003703189474,0.036497406404584744,0.37602031563661353,P 136.6028217885143,147.78085782268082,0.1011905234747678,0.02595287929560828,0.2446939818010536,C ... (more)
Expected output for that sample (first 8 lines):
36.495247 0.793449 0.005596 31.088347 -15.091332 44.183451 27.783064 0.900546 0.007097 10.736097 -13.507498 19.057783 10.919573 0.466838 0.011493 57.518481 -10.731879 52.855270 2.912576 -0.160955 0.007783 36.913577 -3.641387 -24.917638 7.629057 0.681789 0.027625 19.837684 -4.438250 26.738818 27.876982 -0.355579 0.004453 82.872937 -4.917736 -164.630319 0.961265 0.174172 0.024170 11.167668 -14.095087 2.310290 24.721737 0.497928 0.004943 62.271897 -23.678292 49.097100 ... (more)
↓ download full sample input | ↓ download expected output
Test your solution locally:
./your_solution < input.txt | diff - output.txt
Common Pitfalls
- Per option, output: price, delta, gamma, vega, theta, rho. In that order, on one line, comma-separated, ~6 decimal places.
- Vega and rho conventions vary. The reference uses per-1-vol-point and per-1-rate-point (so divide raw partials by 100 if you derived them from d(price)/d(sigma)).
- Theta is per year, not per day. Multiply by -1/365 if you want a per-calendar-day number; the grader expects the raw per-year partial.
- Use
erffor the normal CDF. Don't roll your own approximation; precision on tail strikes matters for the accuracy check. - Tolerance is 0.0001. Make sure your
erfimplementation is double precision, not float.
Performance Tier Thresholds (applied by the grader)
| Language | Gold | Silver | Bronze | Tier 4 |
|---|---|---|---|---|
| C++ | <400ms | <1500ms | <8000ms | else PASS |
| Rust | <400ms | <1500ms | <8000ms | else PASS |
| Java | <800ms | <3000ms | <15000ms | else PASS |
| Python | <4000ms | <12000ms | <50000ms | else PASS |
Submission Rules
- Single-file solutions only. All code must be in one file.
- Your program must read from stdin and write to stdout.
- Java class must be named Solution.
- No network access, no filesystem access beyond stdin/stdout.
- Time limit: 120 seconds. Memory limit: 2 GB.