You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
###Monte Carlo valuation of European call options with NumPy (log version)# mcs_full_vector_numpy.py# import mathfrom numpy import *from time import time# star import for shorter coderandom.seed(20000)t0 = time()# ParametersS0 = 100.; K = 105.; T = 1.0; r = 0.05; sigma = 0.2M = 50; dt = T / M; I = 250000# Simulating I paths with M time stepsS = S0 * exp(cumsum((r - 0.5 * sigma ** 2) * dt + sigma * math.sqrt(dt) * random.standard_normal((M + 1, I)), axis=0))# sum instead of cumsum would also do# if only the final values are of interestS[0] = S0# Calculating the Monte Carlo estimatorC0 = math.exp(-r * T) * sum(maximum(S[-1] - K, 0)) / I# Results outputtnp2 = time() - t0print ('European Option Value %7.3f' % C0)print ('Duration in Seconds %7.3f' % tnp2)import matplotlib.pyplot as pltplt.grid(True)plt.xlabel('time step')plt.ylabel('index level')plt.plot(S[:, :10])