In [11]:
import numpy as np
import timeit
from option_models import normal
from option_models import bsm
In [2]:
### only run this when you changed the class definition
import imp
imp.reload(normal)
imp.reload(bsm)
Out[2]:
In [6]:
n_vec = 10000
strike = np.random.rand(n_vec)*200
spot = 100
texp = 1
vol = np.random.rand(n_vec)*10
In [ ]:
In [7]:
start_time = timeit.default_timer()
price_vec = normal.price(strike, spot, texp, vol)
elapsed = timeit.default_timer() - start_time
print(elapsed)
In [9]:
price_loop = np.zeros(strike.size)
start_time = timeit.default_timer()
for ind in range(strike.size):
price_loop[ind] = normal.price(strike[ind], spot, texp, vol[ind])
elapsed = timeit.default_timer() - start_time
print(elapsed)
In [10]:
price_vec - price_loop
Out[10]:
In [ ]:
In [ ]:
In [ ]: