Task 4 of 4
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.
max(S_T − strike, 0).s0 * Math.exp(drift + volT * z) (already wired)Math.max(st - strike, 0) — an option never goes negativeMath.exp(-RATE * T) in JavaScriptIf 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).
return Math.max(st - strike, 0); — Math.max works
inside kernels, and beats an if here.
This page is an interactive exercise — the editor, the GPU runner and your saved progress need JavaScript. The text above is the full brief.