A stock follows geometric Brownian motion under the risk-neutral measure with constant risk-free rate r, constant dividend yield q, and a volatility that is piecewise constant in time: over the m consecutive time segments the volatility takes values sigma_1, ..., sigma_m, with segment j lasting dt_j years. The option maturity is the total time T = dt_1 + ... + dt_m.
Price a continuously monitored knock-out barrier call with strike K and barrier B:
type is up, the option is up-and-out: it pays max(S_T - K, 0) at maturity unless the stock's price rises to B or above at any time in [0, T], in which case it pays nothing;type is down, the option is down-and-out: it pays max(S_T - K, 0) at maturity unless the stock's price falls to B or below at any time in [0, T], in which case it pays nothing.The spot S_0 never starts on the wrong side of the barrier. Output the option's present value.
The first line contains type (the string up or down), then S_0, K, B, r, q, and the integer m.
Each of the next m lines contains a segment duration dt_j and its volatility sigma_j.
All real inputs have at most 6 digits after the decimal point.
One real number: the present value of the option, with relative error at most 1e-4.
1 <= m <= 20
0.01 <= S_0, K, B <= 1000
0 <= r, q <= 0.2
0.01 <= sigma_j <= 1.0
0.01 <= dt_j, and T <= 10
This is a standard problem: a submission scores full points if it produces the correct output for every test case, and zero otherwise.
Numeric answers are accepted if they are within a relative tolerance of 0.0001 of the expected value.
up 100 100 130 0.03 0.0 2 0.5 0.2 0.5 0.3
2.057109152271259
down 100 100 85 0.02 0.01 1 1.0 0.25
9.148343651974292