def UpAndOutCallPrototype(Spot): #look at times look_at_times = list(np.linspace(start=0, stop=Expiry, num=12)) #generate a path market_params = {'spot':Spot, 'rate':rate, 'vol':Vol} path_generator = GeneratorGBM(market_params) path_generator.generator.set_seed(seed=0) path_generator.sim_setup(look_at_times) sum = 0. Knockout = 108. for i in range(0,num_paths): path = path_generator.do_one_path() # plt.plot(look_at_times,path) # plt.show() #Evaluate the payoff for path #Check if knocks out above barrier if any(map(lambda(x): x >= Knockout,path)): this_payoff = 0 else: #Calc payoff po = VanillaCall(Strike=Strike) this_payoff = po.po(path[-1]) #Get last element of path sum += this_payoff
def AsianPrototype(Spot): #look at times look_at_times = list(np.linspace(start=0, stop=Expiry, num=12)) #generate a path market_params = {'spot':Spot, 'rate':rate, 'vol':Vol} path_generator = GeneratorGBM(market_params) path_generator.sim_setup(look_at_times) sum = 0. for i in range(0,num_paths): path = path_generator.do_one_path() #plt.plot(look_at_times,path) #plt.show() #Evaluate the payoff for path #Average of price - K average_price = np.mean(path) #Calc payoff po = VanillaCall(Strike=Strike) this_payoff = po.po(average_price) sum += this_payoff #Average and discount price = math.exp(-rate*Expiry)*sum/num_paths return price