Python for Finance: Analyze Big Financial Data

(Elle) #1
dt  =   T   /   M
df = np.exp(-r * dt)
# simulation of index levels
S = np.zeros((M + 1 , I))
S[ 0 ] = S0
sn = gen_sn(M, I)
for t in range( 1 , M + 1 ):
S[t] = S[t - 1 ] * np.exp((r - 0.5 * sigma ** 2 ) * dt
+ sigma * np.sqrt(dt) * sn[t])
# case-based calculation of payoff
if option == ‘call’:
h = np.maximum(S - K, 0 )
else:
h = np.maximum(K - S, 0 )
# LSM algorithm
V = np.copy(h)
for t in range(M - 1 , 0 , - 1 ):
reg = np.polyfit(S[t], V[t + 1 ] * df, 7 )
C = np.polyval(reg, S[t])
V[t] = np.where(C > h[t], V[t + 1 ] * df, h[t])
# MCS estimator
C0 = df * 1 / I * np.sum(V[ 1 ])
return C0
In [ 65 ]: gbm_mcs_amer(110., option=‘call’)
Out[65]: 7.7789332794493156
In [ 66 ]: gbm_mcs_amer(110., option=‘put’)
Out[66]: 13.614023206242445

The European value of an option represents a lower bound to the American option’s value.


The difference is generally called the early exercise premium. In what follows, we


compare European and American option values for the same range of strikes as before to


estimate the option premium. This time we take puts:


[ 40 ]

In  [ 67 ]: euro_res    =   []
amer_res = []
k_list = np.arange(80., 120.1, 5.)
for K in k_list:
euro_res.append(gbm_mcs_dyna(K, ‘put’))
amer_res.append(gbm_mcs_amer(K, ‘put’))
euro_res = np.array(euro_res)
amer_res = np.array(amer_res)

Figure 10-17 shows that for the range of strikes chosen the premium can rise to up to 10%:


In  [ 68 ]: fig,    (ax1,   ax2)    =   plt.subplots( 2 ,    1 ,    sharex=True,    figsize=( 8 ,    6 ))
ax1.plot(k_list, euro_res, ‘b’, label=‘European put’)
ax1.plot(k_list, amer_res, ‘ro’, label=‘American put’)
ax1.set_ylabel(‘call option value’)
ax1.grid(True)
ax1.legend(loc= 0 )
wi = 1.0
ax2.bar(k_list - wi / 2 , (amer_res - euro_res) / euro_res * 100 , wi)
ax2.set_xlabel(‘strike’)
ax2.set_ylabel(‘early exercise premium in %’)
ax2.set_xlim(left= 75 , right= 125 )
ax2.grid(True)
Free download pdf