1) The document contains Python code to price an American call option using a trinomial tree method.
2) It sets up stock price trees using geometric Brownian motion, calculates payoff trees at expiration, and works backwards through the trees to calculate profit at each node and price the American option.
3) The key outputs are the profit tree and American call option price printed at the end.
1. #by Tianqi
from math import sqrt
from random import gauss
from numpy import ones, random,exp,average,maximum, zeros, array
S=100
K=105
r=0.001
v=0.1
T=0.5
steps=1000
dt=T/steps
u=exp(v*(dt**0.5))
d=1/u
a = exp((r-q)*dt )
p=(a-d)/(u-d)
pricetree=zeros((steps,steps))
pricetree[0,0]=S
for i in range(1,steps):
pricetree[i,i]=pricetree[i-1,i-1]*d
pricetree[0:i,i]=pricetree[0:i,i-1]*u
#print(pricetree)
payofftree=zeros((steps,steps))
for j in range(steps,-1,-1):
payofftree[0:j,j-1]=maximum(pricetree[0:j,j-1]-K,0)
profittree=zeros((steps-1,steps-1))
#print(payofftree)
for x in range(steps-2,-1,-1):
for y in range(0,x+1):
#print(y)
#print(x)
profittree[y,x]=max(payofftree[y,x],(payofftree[y,x+1]*p+payofftree[y+1,x+1]*(
1-p))*exp(-r*dt))
payofftree[y,x]=max(profittree[y,x],payofftree[y,x])
print("AM call Price is")
print(profittree[0,0])