コード例 #1
0
def MCUpAndOutPrice():
    
    barrier = 108.
    payoff = VanillaCall(Strike=Strike)
    
    #look at times
    look_at_times = list(np.linspace(start=0, stop=Expiry, num=12))
    
    option_parameters = {'payoff': payoff, 
                         'look_at_times':look_at_times,
                         'Expiry':Expiry,
                         'Barrier': barrier}
    
    ao = UpAndOutCall(option_parameters)
    
    market_params = {'spot':Spot, 'rate':rate, 'vol':Vol}
    path_generator = GeneratorGBM(market_params)
    path_generator.generator.set_seed(seed=0)
    
    gatherer = SDGatherer()
    pricer_parameters = {'path_generator':path_generator,
                         'num_paths': num_paths,
                         'gatherer': gatherer}
     
    pd_pricer = PathDependentMCPricer(pricer_parameters)
    
    price = pd_pricer.do_trade(ao)
    
    print "MC UpAndOut opt price ", price
コード例 #2
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)
コード例 #3
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)
コード例 #4
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)
コード例 #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
def plotUpAndOut():
    
    
    Spots = np.linspace(start=50., stop=120, num=100)
    Spots = list(Spots)
    
    barrier = 108.
    payoff = VanillaCall(Strike=Strike)
    
    #look at times
    look_at_times = list(np.linspace(start=0, stop=Expiry, num=12))
    
    option_parameters = {'payoff': payoff, 
                         'look_at_times':look_at_times,
                         'Expiry':Expiry,
                         'Barrier': barrier}
    
    ao = UpAndOutCall(option_parameters)
    
    prices = []
    for Spot in Spots:
        market_params = {'spot':Spot, 'rate':rate, 'vol':Vol}
        path_generator = GeneratorGBM(market_params)
        path_generator.generator.set_seed(seed=0)
        
        gatherer = SDGatherer()
        pricer_parameters = {'path_generator':path_generator,
                             'num_paths': num_paths,
                             'gatherer': gatherer}
         
        pd_pricer = PathDependentMCPricer(pricer_parameters)
    
        price = pd_pricer.do_trade(ao)
    
        prices += [price]
    
    plt.plot(Spots, prices)
    plt.show()
コード例 #7
0
def MCAsianPrice():
    
    
    payoff = VanillaCall(Strike=Strike)
    
    #look at times
    look_at_times = list(np.linspace(start=0, stop=Expiry, num=12))
    
    option_parameters = {'payoff': payoff, 'look_at_times':look_at_times,'Expiry':Expiry}
    ao = AsianArithmeticOption(option_parameters)
    
    market_params = {'spot':Spot, 'rate':rate, 'vol':Vol}
    path_generator = GeneratorGBM(market_params)
    
    gatherer = SDGatherer()
    pricer_parameters = {'path_generator':path_generator,
                         'num_paths': num_paths,
                         'gatherer': gatherer}
     
    pd_pricer = PathDependentMCPricer(pricer_parameters)
    
    price = pd_pricer.do_trade(ao)
    
    print "MC Asian opt price ", price