Task 4 of 4

Price an Option

The payoff. A European call option is the right to buy a stock at a fixed strike price K on a future date — worth max(S_T − K, 0) when the stock finishes at S_T, and its fair price today is the discounted expected payoff. Expectations are integrals, and you just learned to integrate by sampling.

Each thread simulates one possible market: under the standard log-normal model, a pre-drawn normal shock z gives S_T = S0 · e^(drift + volT · z). Your kernel turns 16,384 shocks into 16,384 payoffs; JavaScript averages and discounts. Stock at 100, strike 105, one year out — the Black–Scholes formula says the answer is ≈ 7.13. Your simulation should agree.

Goal: complete the payoff kernel — simulate this thread's final stock price and return the option payoff max(S_T − strike, 0).

Requirements

Hint 1 — why the max?

If the stock ends below the strike you simply don't exercise — the option expires worthless, payoff 0, never negative. Forgetting the max drags the average down by every losing path (the price comes out near −1.9 instead of ≈ 7.1).

Hint 2 — the kernel body

return Math.max(st - strike, 0);Math.max works inside kernels, and beats an if here.

Same idea elsewhere

This is production reality: quant desks run exactly this workload on CUDA and ROCm — millions of simulated paths per pricing call, one thread per path, then a reduction — because exotic options have no closed form at all. You now hold the whole recipe.

All tasks in Monte Carlo Methods

  1. Darts at a Quarter Circle
  2. Reduce 65,536 Hits to π
  3. Integrate the Un-integrable
  4. Price an Option

This page is an interactive exercise — the editor, the GPU runner and your saved progress need JavaScript. The text above is the full brief.