for i in range(60): if(history[i]>105): return 3 # If the stock at expiration is between $101 and $105 we return 1. if 105>=history[-1]>=101: return 1 # If the stock at expiration is over $105 we return 2. elif history[-1]>105: return 2 else: return 0 # Variables are initialized here. params=Storage() params.mu = 0.03/300 # avg daily return. params.sigma = 0.2/sqrt(300) # avg daily volatility. params.S = 100.0 # today's stock price. params.option=current_option params.T = 120 # time to expiration. params.r_free = 0.04/300 # avg daily risk free rate. params.dt = 1.0 # simulation step. # StockSimulator Object is initialized. s = StockSimulator(params) # Plotting is disabled for the purpose of this program. #plot(dict(data=[x for x in enumerate(r)])) # Simulating to get the price for different volatility values or absolute precision. # Run times for program are slightly faster when commented out. print s.simulate_many(absolute_precision = 0.00, relative_precision=0.02, max_iterations=10000) #print 'Price: $',sum(s.u)/len(s.u) # Simulating different values for relative precision.