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
def test_PutCallPayOffs(self): vc_higher = VanillaCall(self.StrikeHigher) vc_lower= VanillaCall(self.StrikeLower) vp_higher = VanillaPut(self.StrikeHigher) vp_lower= VanillaPut(self.StrikeLower) vo_callhigher = VanillaOption(Expiry=1, PayOff=vc_higher) vo_calllower= VanillaOption(Expiry=1, PayOff=vc_lower) vo_puthigher = VanillaOption(Expiry=1, PayOff=vp_higher) vo_putlower= VanillaOption(Expiry=1, PayOff=vp_lower) self.assertAlmostEqual(vo_callhigher.pay_off(self.Spot),0.) self.assertAlmostEqual(vo_calllower.pay_off(self.Spot),10.) self.assertAlmostEqual(vo_puthigher.pay_off(self.Spot),10.) self.assertAlmostEqual(vo_putlower.pay_off(self.Spot),0.)
if __name__ == '__main__': from PayOffs import VanillaCall, VanillaPut from VanillaOptions import VanillaOption from Gatherer import MeanGatherer, ConvergenceTable from PathGenerators import GeneratorGBM, Antithetic, NormalGenerator from AnalyticFunctions import BSAnalyticFormulas #Option params Strike = 110. Expiry = 1. vc1 = VanillaCall(Strike) vp1 = VanillaPut(Strike) vo_call = VanillaOption(Expiry, PayOff=vc1) vo_put = VanillaOption(Expiry, PayOff=vp1) #Model/Market parameters Spot = 100. rate = 0.05 Vol = 0.2 dividend = 0.0 #not included in pricing yet #Model parameters times = [1.] num_paths = 50000 market_params = {'spot': Spot, 'rate': rate, 'vol': Vol}