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
예제 #3
0
 def setUp(self):
     #BS analytics
     self.Spot = 110.
     self.Strike = 110.
     self.rate = 0.05
     self.Vol = 0.2
     self.dividend = 0.
     self.Expiry = 1.
     
     #Setup analytic prices
     self.bs1 = af.BSAnalyticFormulas(self.Spot,
                                       self.Strike,
                                       self.rate,
                                       self.Vol,
                                       self.Expiry,
                                       self.dividend)
     
     
     #Setup MC pricer
     num_paths = 100000
     times = [self.Expiry]
     market_params = {'spot': self.Spot,
                      'rate': self.rate,
                       'vol': self.Vol}
 
     generator = GeneratorGBM(market_params)
     generator.sim_setup(times)
     gatherer = MeanGatherer()
     
     self.van_mc = VanillaMCPricer(spot=self.Spot, 
                                   rate=self.rate, 
                                   Vol=self.Vol, 
                                   generator=generator, 
                                   gatherer=gatherer, 
                                   num_paths=num_paths, 
                                   dividend=0)
예제 #4
0
    def test_UpAndOut_pricer(self):
        """
        test that path dependent pricer works for up and out option
        with discrete barrier data
        """

        num_paths = 500000

        #Construct option
        barrier = 108.
        payoff = VanillaCall(Strike=self.Strike)

        #look at times
        look_at_times = list(np.linspace(start=0, stop=self.Expiry, num=12))

        option_parameters = {
            'payoff': payoff,
            'look_at_times': look_at_times,
            'Expiry': self.Expiry,
            'Barrier': barrier
        }

        ao = UpAndOutCall(option_parameters)

        #Construct market parameters for path generation
        market_params = {'spot': self.Spot, 'rate': self.rate, 'vol': self.Vol}
        path_generator = GeneratorGBM(market_params)

        #Construct Pricer parameters
        #Note includes path generator
        gatherer = SDGatherer()
        pricer_parameters = {
            'path_generator': path_generator,
            'num_paths': num_paths,
            'gatherer': gatherer
        }

        #Contruct pricer
        pd_pricer = PathDependentMCPricer(pricer_parameters)

        #Do trade
        price = pd_pricer.do_trade(ao)

        print "MC up and out call price ", price
        self.assertAlmostEqual(first=0.2096, second=price,
                               places=2)  #, msg, delta)
예제 #5
0
    def test_AsianArithmetic_pricer(self):
        """
        test that asian arithmetic option pricer works
        """

        num_paths = 500000

        payoff = VanillaCall(Strike=self.Strike)

        #look at times
        look_at_times = list(np.linspace(start=0, stop=self.Expiry, num=12))

        #Contruct Option
        option_parameters = {
            'payoff': payoff,
            'look_at_times': look_at_times,
            'Expiry': self.Expiry
        }

        ao = AsianArithmeticOption(option_parameters)

        #Construct market parameters for path generation
        market_params = {'spot': self.Spot, 'rate': self.rate, 'vol': self.Vol}
        path_generator = GeneratorGBM(market_params)

        #Construct Pricer parameters
        #Note includes path generator
        gatherer = SDGatherer()
        pricer_parameters = {
            'path_generator': path_generator,
            'num_paths': num_paths,
            'gatherer': gatherer
        }

        #Contruct pricer
        pd_pricer = PathDependentMCPricer(pricer_parameters)

        #Do trade
        price = pd_pricer.do_trade(ao)

        print "MC Asian opt price ", price
        self.assertAlmostEqual(first=2.015, second=price,
                               places=2)  #, msg, delta)
예제 #6
0
    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}

    generator = GeneratorGBM(market_params)
    generator.sim_setup(times)
    gatherer = MeanGatherer()

    #Do sim
    mc_pricer = VanillaMCPricer(Spot, rate, Vol, generator, gatherer,
                                num_paths, dividend)
    mc_pricer.do_trade(vo_put)
    price_put = mc_pricer.price
    mc_pricer.do_trade(vo_call)
    price_call = mc_pricer.price

    #Compare to Analytic Pricer

    bsan = BSAnalyticFormulas(Spot, Strike, rate, Vol, Expiry, dividend)
    print "MC price Put: ", price_put
예제 #7
0
 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}
 
 generator = GeneratorGBM(market_params)
 generator.sim_setup(times)
 gatherer = MeanGatherer()
 
 #Do sim
 mc_pricer = VanillaMCPricer(Spot, rate, Vol, generator, gatherer, num_paths, dividend)
 mc_pricer.do_trade(vo_put)
 price_put = mc_pricer.price
 mc_pricer.do_trade(vo_call)
 price_call = mc_pricer.price
 
 #Compare to Analytic Pricer
 
 bsan = BSAnalyticFormulas(Spot, Strike, rate, Vol, Expiry, dividend)
 print "MC price Put: ", price_put
 print "Analytic Put price: ", bsan.PutPrice()