The brief
A structured-products desk is selling a note that pays $1 million in three months if an index then stands above 4,400. The index is at 4,250 today. The payoff is all or nothing at the strike: a cash-or-nothing call, also called a digital.
The desk's pricing library has no formula for it yet. Price it by integrating against the model's density for the index at expiry, then check the price with a simulation.
In the pricing model the index level at expiry is
where is today's level, the continuous rate, the volatility and a standard normal number.
Your task
- Write
lognormal_density(x, S0, T, r, sigma): the density of atx, which is 0 for . RaiseValueErrorunlessS0,Tandsigmaare all positive. - Write
digital_by_integral(S0, K, T, r, sigma, payout): the price today,payouttimes times . Find the probability by integrating the density withquad. - Write
digital_by_simulation(S0, K, T, r, sigma, payout, n, seed): the pair(price, standard error)fromnsimulated levels. Draw the normals withnp.random.default_rng(seed).standard_normal(n). RaiseValueErrorifnis below 1.
digital_by_integral must stay accurate for a weekly digital deep in the money, and for a 10-year one at high volatility. With or there is no randomness: the price is the discounted payout if , and 0 otherwise. Raise ValueError if S0 or K is not positive, or if T or sigma is negative.
The data
SPOT, STRIKE, EXPIRY, RATE, VOL and PAYOUT hold the note's terms, with rates and volatility as annual decimals and the expiry in years.
Hint: The density
Case study 5.4.6 shows that is normal, with mean and standard deviation . Lesson 5.4.4 gives the lognormal density as , with .
Hint: Keeping quad on target
Over , quad can miss a narrow peak far from and return 0. Substitute (lesson 2.6.1): then and the integrand becomes . Then cut the infinite end, as case study 2.6.5 does, keeping within about 10 of the centre at both ends.
Hint: The simulation
Case study 5.4.6 simulates lognormal prices from standard normals. Case study 4.7.5 gives the standard error of a simulated share as ; scale it by the discounted payout, as the price is. The simulated price should land within 2 or 3 standard errors of the integral.