예제 #1
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)
예제 #2
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)
예제 #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
    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