0.5967712907402317
Kerry Back
import numpy as np
S = 100 # stock price
K = 105 # strike
u = 0.05 # up return per period
r = 0.03 # interest rate per period
n = 4 # number of periods
d = 1/(1+u) - 1 # down return per period
p = (r-d) / (u-d) # risk-neutral prob
x = [S*(1+u)**(n-2*i) for i in range(n+1)]
v = np.maximum(0, K-np.array(x))
while len(v)>1:
v = (p*v[:-1]+(1-p)*v[1:]) / (1+r)
v[0]
0.5967712907402317
while len(v)>1:
v1 = (p*v[:-1]+(1-p)*v[1:]) / (1+r)
m = len(v1) - 1 # date number
x = [S*(1+u)**(m-2*i) for i in range(m+1)]
v2 = np.maximum(0, K-np.array(x))
v = np.maximum(v1, v2)
V[0]
5.0