Bundled Monte Carlo backward induction for Bermudan options (exact integer)
/app/cpu/main.cpp is the source of a multicore CPU program (C++17, OpenMP).
The program takes one input-file path (PROGRAM INPUT_FILE) and writes its result to stdout.
What the program computes
Monte Carlo prices of eight Bermudan payoffs on one simulated asset, by backward induction with bundling: the continuation value of a path at an exercise date is the average discounted future cash flow of all in-the-money paths that sit in the same price bucket. All quantities are integers (cents and Q20 fixed point), so the result is exact.
Lattice. Price index i in [-T, T], price[0] = S0 and
price[i+1] = floor(price[i] * UP / 2^20) for i >= 0,
price[i-1] = floor(price[i] * DN / 2^20) for i <= 0.
Payoffs s = 0..5 are puts max(K_s - price, 0), payoffs s = 6, 7 are straddles
|price - K_s|.
Paths. Path p starts at i_0 = 0. Its regime (0 calm, 1 bull, 2 bear) is a Markov chain
over epochs of 32 steps (epoch e covers steps t = 32e+1 .. 32e+32), drawn from
initial_regime and next_regime in the source. The step eps_t in {+1, -1, 0} from time
t-1 to t is decided by the top 32 bits of a SplitMix64 hash of (seed, p, t) against the
regime's two thresholds (step in the source). Steps are counter-based: the backward pass
recovers i_{t-1} = i_t - eps_t instead of storing the path. The forward pass stores i_T and
the regime of every epoch as 2-bit fields of one 64-bit word.
Backward induction. CF_s = payoff_s(i_T). Then for t = T-1 down to 0:
i_t = i_{t+1} - eps_{t+1}; every cash flow is discounted,CF_s = floor(CF_s * DISC / 2^20).- If
1 <= tandt % E == 0(an exercise date): for every payoffsand every path withpayoff_s(i_t) > 0, with bucketb = (i_t + T) / WB, accumulatecount[s][b] += 1andsum[s][b] += CF_sover all paths; then every such path exercises iffpayoff_s(i_t) * count[s][b] > sum[s][b], which setsCF_s = payoff_s(i_t).
At t = 0 every path is back at index 0 (origin_check prints sum |i_0|, always 0). The
value of payoff s is max(payoff_s(0), floor(sum_p CF_s / P)).
Input format
P T E WB SEED
S0 UP DN DISC
K_0 K_1 K_2 K_3 K_4 K_5 K_6 K_7
1 <= P <= 20000000 paths, 1 <= T <= 1024 steps, exercise every E >= 1 steps, bucket
width WB >= 1 lattice indices, SEED unsigned 64-bit. 1 <= S0 <= 2000000,
2^20 <= UP <= 2^20 + 4096, 2^20 - 4096 <= DN <= 2^20, 2^20 - 4096 <= DISC <= 2^20,
0 <= K_s <= 4000000. With these bounds every price, payoff and cash flow is below 2^32.
Output format
paths P steps T every E width WB buckets NB dates ND
origin_check 0
opt s put|straddle K K_s sum S continuation C immediate H value V exercised X busiest t n (8 lines)
exercise_hash H
snap q t T_q pay s buckets B count N sum S top b hash H (4 x 8 lines)
NB = 2T / WB + 1,ND = (T - 1) / Eexercise datesE, 2E, ..., ND*E.S = sum_p CF_sat time 0,C = floor(S / P),H = payoff_s(0),V = max(C, H),Xthe total number of exercises,busiest t nthe date with most exercises ofs(earliest on ties;-1 0when there are no dates).exercise_hash = sum over dates d and payoffs s of mix64((((d*E) << 8) | s) * 0xD6E8FEB86659FD93 XOR count)modulo 2^64.- Snapshots of the bundle tables (before the decisions) at the dates
T_q = min(ND*E, ((q+1)*ND/5 + 1)*E),q = 0..3: non-empty buckets, total count and sum, the fullest bucket (smallestbon ties) andsum_b mix64((b << 40) XOR (count_b << 1) XOR sum_b*0x9E3779B97F4A7C15)over non-empty buckets. Without dates each snapshot line issnap q -.
Hidden inputs
- Correctness inputs: a single path,
T = 1andT = 2, regime-epoch boundaries,E > T(no dates), one bucket for the whole lattice,T = 1024with extremeUP/DN/DISC, and random mixes with up to 80000 paths andEin[1, 7],WBin[1, 4]. - The timing input has
Tin[900, 1024],Ein{1, 2},Pin[4500000, 5500000]whenE = 1and in[7200000, 8800000]whenE = 2,WBin{1, 2},S0in[500000, 2000000],UP - 2^20and2^20 - DNin[1024, 4096],2^20 - DISCin[8, 400], put strikes in[0.75, 1.25]*S0and straddle strikes in[0.9, 1.1]*S0.
Your task
Port this program to CUDA in /app/gpu/main.cu: same command line (PROGRAM INPUT_FILE),
same output on stdout. Then make it as fast as you can on the GPU while keeping the output correct.
The main computation must execute on the GPU. Renaming CPU code to .cu, running a
CPU fallback, or launching a dummy kernel while computing the answer on the CPU does not satisfy this task.
The CPU source is the specification: when this text and the code disagree, the code wins.
This sandbox is for source generation only. Write /app/gpu/main.cu; compilation,
execution and verification are performed later in a separate verifier environment.
How you are scored
- Only
/app/gpu/main.cuis collected. It is compiled withnvcc -O3 -arch=sm_90 -std=c++17 -o port /app/gpu/main.cu; no extra libraries are linked. The CUDA runtime and the header-only libraries that ship with the CUDA toolkit (CUB, Thrust, libcu++) are allowed. - Your source must not contain any of:
system(,popen(,fork(,exec*,dlopen(,getenv(,#include <filesystem>,/tests/,/proc/. The program may read only the input file it is given. - GPU verification uses the backend selected for this run: an H100 attached to the separate verifier, or a remote H100 worker. Hidden inputs use a fresh random seed.
- Correctness: every hidden input (small edge cases plus the timing input) must pass. Your output must be identical to the CPU program's output (trailing whitespace ignored). Any mismatch, crash or timeout gives reward 0.
- GPU execution: a separate, untimed CUPTI check must observe completed GPU kernel activity on the hidden timing input. A CPU-only submission receives reward 0 even if its output is correct.
- Speed: The timing input has 900-1024 time steps with an exercise date every 1 or 2 steps and 4.5-5.5 million paths (7.2-8.8 million when dates are every 2 steps). Your port and our GPU reference are each run on it
once to warm up and then 5 times, interleaved; the time is the wall clock of the whole process
(including CUDA initialisation, input parsing and output). When correct,
reward = min(2, t_reference / t_yours)using the medians. /app/inputs/holds public input examples for understanding the input format.