A shout option is a standard European option except that the option buyer can shout to the option seller before maturity date to set the minimum payoff as Sτ-X, where Sτ is the stock price at time τ when the buyer shouts and X is the exercise price. The level of the strike could be set at a specific relation to the spot price, such as 3% or 5% above (or below). The Python codes are given here:
def shoutCall(s,x,T,r,sigma,shout,n=100): from math import exp,sqrt import numpy as np deltaT = T /n u = exp(sigma * sqrt(deltaT)) d = 1.0 / u a = exp(r * deltaT) p = (a - d) / (u - d) v =[[0.0 for j in np.arange(i + 1)] for i in np.arange(n + 1)] for j in np.arange(n+1): v[n][j] = max(s * u**j * d**(n - j) - x, 0.0) for i in np.arange(n-1, -1, -1): for j in np.arange(i + 1): v1=exp(-r*deltaT)*(p*v[i+1][j+1]+(1.0-p)*v[i+1][j]) v2=max(v[i][j]-shout,0) # shout v[i][j]=max(v1,v2) return...