Options Pricing Engine

Hard ● Live C++ Rust Java Python

The 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,type where type is C (call) or P (put).
S, K
underlying spot price and strike, both as floats.
T
time to expiry in years (e.g., 0.5573 for ~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

Performance Tier Thresholds (applied by the grader)

LanguageGoldSilverBronzeTier 4
C++<400ms<1500ms<8000mselse PASS
Rust<400ms<1500ms<8000mselse PASS
Java<800ms<3000ms<15000mselse PASS
Python<4000ms<12000ms<50000mselse PASS

Submission Rules

Challenge Stats

Contracts: 500,000
Greeks per contract: 6
Gold Target: <400ms (C++/Rust)
Languages: 4

Starter Templates

↓ skeleton.cpp ↓ skeleton.rs ↓ Skeleton.java ↓ skeleton.py

Submit Your Solution

You can submit multiple times. Best result per language counts.

Resources

Leaderboard →