def test_point_case3(self):
     self.option_property['strike'] = 0.00001
     self.option_property['type'] = 'call'
     self.params['instrument'] = instruments.vanilla_european(
         self.option_property)
     call_price = utils.call(self.method, self.params)
     self.option_property['type'] = 'put'
     self.params['instrument'] = instruments.vanilla_european(
         self.option_property)
     put_price = utils.call(self.method, self.params)
     df_r = math.exp(-self.params['r'] * 0.9993155373)
     df_q = math.exp(-self.params['q'] * 0.9993155373)
     d1 = (math.log(self.params['spot'] / self.option_property['strike']) +
           0.9993155373 *
           (self.params['r'] +
            (self.params['vol']**2.) * 0.5)) / (self.params['vol'] *
                                                math.sqrt(0.9993155373))
     d2 = d1 - self.params['vol'] * math.sqrt(0.9993155373)
     self.assertAlmostEqual(
         self.params['spot'] * df_q * norm.cdf(d1) -
         self.option_property['strike'] * df_r * norm.cdf(d2),
         call_price,
         places=10)
     self.assertAlmostEqual(
         self.option_property['strike'] * df_r * norm.cdf(-d2) -
         self.params['spot'] * df_q * norm.cdf(-d1),
         put_price,
         places=10)
Exemple #2
0
    def test_call_price_case2(self):
        self.params['spot'] = 95.
        self.option_property['direction'] = 'down_and_out'
        self.params['instrument'] = instruments.knock_out_continuous(
            self.option_property)
        black_out_price = utils.call('qlOptionCalcBlack', self.params)
        pde_out_price = utils.call('qlOptionCalcPDE', self.params)

        self.option_property['direction'] = 'down_and_in'
        self.params['instrument'] = instruments.knock_in_continuous(
            self.option_property)
        black_in_price = utils.call('qlOptionCalcBlack', self.params)
        pde_in_price = utils.call('qlOptionCalcPDE', self.params)

        self.params['instrument'] = instruments.vanilla_european(
            self.option_property)
        black_euro_price = utils.call('qlOptionCalcBlack', self.params)
        pde_euro_price = utils.call('qlOptionCalcPDE', self.params)

        rebate = self.option_property['rebate_amount']
        r = self.params['r']

        eps = self.params['spot'] * 1e-5
        self.assertAlmostEqual(pde_euro_price - pde_out_price +
                               rebate * exp(-r * 0.9993),
                               pde_in_price,
                               delta=eps)
 def test_limit_case4(self):
     self.option_property['strike'] = 1e-11
     self.option_property['type'] = 'put'
     self.params['instrument'] = instruments.vanilla_european(
         self.option_property)
     put_price = utils.call(self.method, self.params)
     self.assertAlmostEqual(put_price, 0., places=10)
Exemple #4
0
 def test_ex_case1(self):
     self.params['instrument'] = instruments.vanilla_european(
         self.option_property)
     self.params['vol'] = 0.0
     pde_price = utils.call(self.method, self.params)
     black_price = utils.call('qlOptionCalcBlack', self.params)
     eps = self.params['spot'] * 1e-4
     self.assertAlmostEqual(pde_price, black_price, delta=eps)
Exemple #5
0
    def test_call_price_case1(self):
        self.params['instrument'] = instruments.knock_in_continuous(self.option_property)
        self.params['spot'] = 90.
        price = utils.call(self.method, self.params)

        self.params['instrument'] = instruments.vanilla_european(self.option_property)
        vanilla_price = utils.call(self.method, self.params)
        self.assertAlmostEqual(vanilla_price, price, places=9)
Exemple #6
0
 def test_put_price_case3(self):
     self.option_property['type'] = 'put'
     self.params['instrument'] = instruments.vanilla_european(
         self.option_property)
     self.params['spot'] = 200.
     pde_price = utils.call(self.method, self.params)
     black_price = utils.call('qlOptionCalcBlack', self.params)
     eps = self.params['spot'] * 1e-5
     self.assertAlmostEqual(pde_price, black_price, delta=eps)
 def test_limit_case3(self):
     self.params['spot'] = 1e-11
     self.option_property['type'] = 'put'
     self.params['instrument'] = instruments.vanilla_european(
         self.option_property)
     put_price = utils.call(self.method, self.params)
     self.assertAlmostEqual(put_price,
                            self.option_property['strike'] *
                            math.exp(-0.9993155373 * self.params['r']),
                            places=10)
Exemple #8
0
 def test_exotic_case18(self):
     self.params['valDate'] = '2017-08-08T00:00:00'
     self.option_property['strike'] = 77.
     self.option_property['type'] = 'call'
     self.params['instrument'] = instruments.vanilla_european(
         self.option_property)
     call_price = utils.call(self.method, self.params)
     self.option_property['type'] = 'put'
     self.params['instrument'] = instruments.vanilla_european(
         self.option_property)
     put_price = utils.call(self.method, self.params)
     self.assertAlmostEqual(
         call_price,
         max(self.params['spot'] - self.option_property['strike'], 0.),
         places=10)
     self.assertAlmostEqual(
         put_price,
         max(self.option_property['strike'] - self.params['spot'], 0.),
         places=10)
Exemple #9
0
    def test_call_price_case1(self):
        self.params['q'] = 0
        self.params['instrument'] = instruments.vanilla_american(
            self.option_property)
        american_price = utils.call(self.method, self.params)

        self.params['instrument'] = instruments.vanilla_european(
            self.option_property)
        european_price = utils.call(self.method, self.params)

        self.assertAlmostEqual(american_price, european_price, places=15)
Exemple #10
0
    def test_down_limit_call(self):
        self.option_property['barrier'] = 0.01
        self.params['instrument'] = instruments.knock_out_continuous(
            self.option_property)
        tree_price = utils.call(self.method, self.params)

        self.params['instrument'] = instruments.vanilla_european(
            self.option_property)
        vanilla_price = utils.call(self.method, self.params)
        eps = self.params['spot'] * 1e-5
        self.assertAlmostEqual(tree_price, vanilla_price, delta=eps)
Exemple #11
0
    def test_barrier_lower_limit_case1(self):
        self.option_property['barrier'] = 0.01
        self.params['instrument'] = instruments.knock_out_continuous(
            self.option_property)
        knock_out_price = utils.call(self.method, self.params)

        self.params['instrument'] = instruments.vanilla_european(
            self.option_property)
        vanilla_price = utils.call(self.method, self.params)

        self.assertAlmostEqual(knock_out_price, vanilla_price, places=9)
Exemple #12
0
    def test_in_out_parity(self):
        self.option_property['rebate_amount'] = 0.
        self.params['instrument'] = instruments.knock_in_continuous(self.option_property)
        in_price = utils.call(self.method, self.params)

        self.option_property['direction'] = 'down_and_out'
        self.params['instrument'] = instruments.knock_out_continuous(self.option_property)
        out_price = utils.call(self.method, self.params)

        self.params['instrument'] = instruments.vanilla_european(self.option_property)
        vanilla_price = utils.call(self.method, self.params)
        self.assertAlmostEqual(out_price+in_price-vanilla_price, 0.0, places=9)
Exemple #13
0
    def test_barrier_upper_limit_case2(self):
        self.option_property['barrier'] = 1000.
        self.option_property['direction'] = 'up_and_out'
        self.option_property['type'] = 'put'
        self.params['instrument'] = instruments.knock_out_continuous(
            self.option_property)
        knock_out_price = utils.call(self.method, self.params)

        self.params['instrument'] = instruments.vanilla_european(
            self.option_property)
        vanilla_price = utils.call(self.method, self.params)

        self.assertAlmostEqual(knock_out_price, vanilla_price, places=9)
Exemple #14
0
 def test_exotic_case3(self):
     self.params['vol'] = 0.
     self.params['spot'] = 1.
     self.option_property['type'] = 'call'
     self.params['instrument'] = instruments.vanilla_european(
         self.option_property)
     call_price = utils.call(self.method, self.params)
     self.option_property['type'] = 'put'
     self.params['instrument'] = instruments.vanilla_european(
         self.option_property)
     put_price = utils.call(self.method, self.params)
     df_r = math.exp(-self.params['r'] * 0.9993155373)
     df_q = math.exp(-self.params['q'] * 0.9993155373)
     self.assertAlmostEqual(call_price,
                            max(
                                0, self.params['spot'] * df_q -
                                self.option_property['strike'] * df_r),
                            places=10)
     self.assertAlmostEqual(put_price,
                            max(
                                self.option_property['strike'] * df_r -
                                self.params['spot'] * df_q, 0),
                            places=10)
Exemple #15
0
 def test_exotic_case2(self):
     self.params['vol'] = 0.
     self.params['valDate'] = '2017-01-01T00:00:00'
     self.option_property['type'] = 'call'
     self.params['instrument'] = instruments.vanilla_european(
         self.option_property)
     call_price = utils.call(self.method, self.params)
     self.option_property['type'] = 'put'
     self.params['instrument'] = instruments.vanilla_european(
         self.option_property)
     put_price = utils.call(self.method, self.params)
     df_r = math.exp(-self.params['r'] * 219. / 365.25)
     df_q = math.exp(-self.params['q'] * 219. / 365.25)
     self.assertAlmostEqual(call_price,
                            max(
                                0, self.params['spot'] * df_q -
                                self.option_property['strike'] * df_r),
                            places=10)
     self.assertAlmostEqual(put_price,
                            max(
                                self.option_property['strike'] * df_r -
                                self.params['spot'] * df_q, 0),
                            places=10)
Exemple #16
0
    def test_parity(self):
        self.option_property['rebate_amount'] = 0
        self.params['instrument'] = instruments.knock_out_continuous(
            self.option_property)
        knock_out_price = utils.call(self.method, self.params)

        self.option_property['direction'] = 'down_and_in'
        self.params['instrument'] = instruments.knock_in_continuous(
            self.option_property)
        knock_in_price = utils.call(self.method, self.params)

        self.params['instrument'] = instruments.vanilla_european(
            self.option_property)
        vanilla_price = utils.call(self.method, self.params)
        self.assertAlmostEqual(knock_out_price + knock_in_price,
                               vanilla_price,
                               delta=0)