コード例 #1
0
ファイル: test_knock_out.py プロジェクト: zhanrendong/jkzx1
    def test_ex3_call(self):
        self.params['r'] = -10.
        self.params['instrument'] = instruments.knock_out_continuous(
            self.option_property)
        price = utils.call(self.method, self.params)

        self.assertAlmostEqual(21.11111111111111, price, places=15)
コード例 #2
0
ファイル: test_knock_out.py プロジェクト: zhanrendong/jkzx1
    def test_ex6_call(self):
        self.params['q'] = 10.
        self.params['instrument'] = instruments.knock_out_continuous(
            self.option_property)
        price = utils.call(self.method, self.params)

        self.assertAlmostEqual(19.98911500679125, price, places=15)
コード例 #3
0
ファイル: test_knock_out.py プロジェクト: zhanrendong/jkzx1
    def test_ex5_call(self):
        self.params['q'] = -10.
        self.params['instrument'] = instruments.knock_out_continuous(
            self.option_property)
        price = utils.call(self.method, self.params)

        self.assertAlmostEqual(2078150.134764752, price, places=15)
コード例 #4
0
ファイル: test_knock_out.py プロジェクト: zhanrendong/jkzx1
    def test_ex4_call(self):
        self.params['r'] = 10.
        self.params['instrument'] = instruments.knock_out_continuous(
            self.option_property)
        price = utils.call(self.method, self.params)

        self.assertAlmostEqual(94.99542668240535, price, places=15)
コード例 #5
0
ファイル: test_knock_out.py プロジェクト: zhanrendong/jkzx1
    def test_ex2_call(self):
        self.params['valDate'] = '2017-08-08T00:00:00'
        self.params['instrument'] = instruments.knock_out_continuous(
            self.option_property)
        price = utils.call(self.method, self.params)

        self.assertAlmostEqual(0, price, places=15)
コード例 #6
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)
コード例 #7
0
ファイル: test_knock_out.py プロジェクト: zhanrendong/jkzx1
 def test_put_price_case3(self):
     self.option_property['type'] = 'put'
     self.params['instrument'] = instruments.knock_out_continuous(
         self.option_property)
     self.params['spot'] = 100.
     price = utils.call(self.method, self.params)
     self.assertAlmostEqual(11.621517755, price, places=9)
コード例 #8
0
 def test_call_price_case3(self):
     self.params['spot'] = 110.
     self.params['instrument'] = instruments.knock_out_continuous(
         self.option_property)
     pde_price = utils.call(self.method, self.params)
     rebate = self.option_property['rebate_amount']
     self.assertAlmostEqual(pde_price, rebate, places=15)
コード例 #9
0
 def test_ex2_put(self):
     self.params['valDate'] = '2017-08-08T00:00:00'
     self.option_property['type'] = 'put'
     self.params['instrument'] = instruments.knock_out_continuous(
         self.option_property)
     pde_price = utils.call(self.method, self.params)
     price = max(self.option_property['strike'] - self.params['spot'], 0)
     self.assertAlmostEqual(pde_price, price, places=15)
コード例 #10
0
 def test_put_price_case1(self):
     self.option_property['type'] = 'put'
     self.params['spot'] = 90.
     self.params['instrument'] = instruments.knock_out_continuous(
         self.option_property)
     tree_price = utils.call(self.method, self.params)
     rebate = self.option_property['rebate_amount']
     self.assertAlmostEqual(tree_price, rebate, places=15)
コード例 #11
0
ファイル: test_knock_out.py プロジェクト: zhanrendong/jkzx1
    def test_ex5_put(self):
        self.params['q'] = -10.
        self.option_property['type'] = 'put'
        self.params['instrument'] = instruments.knock_out_continuous(
            self.option_property)
        price = utils.call(self.method, self.params)

        self.assertAlmostEqual(5.434851880526098e-07, price, places=15)
コード例 #12
0
ファイル: test_knock_out.py プロジェクト: zhanrendong/jkzx1
    def test_ex4_put(self):
        self.params['r'] = 10.
        self.option_property['type'] = 'put'
        self.params['instrument'] = instruments.knock_out_continuous(
            self.option_property)
        price = utils.call(self.method, self.params)

        self.assertAlmostEqual(6.124622476393796e-07, price, places=15)
コード例 #13
0
 def test_call_price_case2(self):
     self.params['spot'] = 105.
     self.params['instrument'] = instruments.knock_out_continuous(
         self.option_property)
     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)
コード例 #14
0
ファイル: test_knock_out.py プロジェクト: zhanrendong/jkzx1
    def test_ex9_call(self):
        self.params['vol'] = 1e-6
        self.params['r'] = 0
        self.params['q'] = 0
        self.params['instrument'] = instruments.knock_out_continuous(
            self.option_property)
        price = utils.call(self.method, self.params)

        self.assertAlmostEqual(0, price, places=15)
コード例 #15
0
 def test_ex1_put(self):
     self.params['vol'] = 0.0
     self.option_property['type'] = 'put'
     self.params['instrument'] = instruments.knock_out_continuous(
         self.option_property)
     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)
コード例 #16
0
 def test_put_price_case1(self):
     self.option_property['type'] = 'put'
     self.params['spot'] = 100.
     self.params['instrument'] = instruments.knock_out_continuous(
         self.option_property)
     tree_price = utils.call(self.method, self.params)
     black_price = utils.call('qlOptionCalcBlack', self.params)
     eps = self.params['spot'] * 1e-3
     self.assertAlmostEqual(tree_price, black_price, delta=eps)
コード例 #17
0
ファイル: test_knock_out.py プロジェクト: zhanrendong/jkzx1
    def test_ex8_put(self):
        self.params['vol'] = 1e-6
        self.params['r'] = -10.
        self.params['q'] = 0.
        self.option_property['type'] = 'put'
        self.params['instrument'] = instruments.knock_out_continuous(
            self.option_property)
        price = utils.call(self.method, self.params)

        self.assertAlmostEqual(21.11111111111111, price, places=15)
コード例 #18
0
ファイル: test_knock_out.py プロジェクト: zhanrendong/jkzx1
    def test_ex1_put(self):
        self.params['vol'] = 0
        self.option_property['type'] = 'put'
        self.params['instrument'] = instruments.knock_out_continuous(
            self.option_property)
        price1 = utils.call(self.method, self.params)
        self.params['vol'] = 1e-6
        price2 = utils.call(self.method, self.params)

        self.assertAlmostEqual(price1, price2, places=15)
コード例 #19
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)
コード例 #20
0
 def test_ex3_call(self):
     self.params['vol'] = 1e-3
     self.params['r'] = 10.0
     self.params['q'] = 0.0
     self.params['instrument'] = instruments.knock_out_continuous(
         self.option_property)
     self.params['alpha'] = 0.5
     tree_price = utils.call(self.method, self.params)
     black_price = utils.call('qlOptionCalcBlack', self.params)
     eps = self.params['spot'] * 1e-5
     self.assertAlmostEqual(black_price, tree_price, delta=eps)
コード例 #21
0
ファイル: test_knock_out.py プロジェクト: zhanrendong/jkzx1
    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)
コード例 #22
0
ファイル: test_knock_in.py プロジェクト: zhanrendong/jkzx1
    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)
コード例 #23
0
ファイル: test_knock_out.py プロジェクト: zhanrendong/jkzx1
    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)
コード例 #24
0
    def test_lower_limit_case3(self):
        self.option_property['lower_barrier'] = 0.1
        self.option_property['type'] = 'put'
        self.params['instrument'] = instruments.double_knock_out_continuous(
            self.option_property)
        double_knock_out_price = utils.call(self.method, self.params)

        self.option_property['barrier'] = self.option_property['upper_barrier']
        self.option_property['rebate_amount'] = self.option_property[
            'upper_rebate']
        self.option_property['direction'] = 'up_and_out'
        self.params['instrument'] = instruments.knock_out_continuous(
            self.option_property)
        knock_out_price = utils.call(self.method, self.params)
        self.assertAlmostEqual(double_knock_out_price,
                               knock_out_price,
                               places=9)
コード例 #25
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)
コード例 #26
0
ファイル: test_knock_out.py プロジェクト: zhanrendong/jkzx1
 def test_call_price_case2(self):
     self.params['instrument'] = instruments.knock_out_continuous(
         self.option_property)
     self.params['spot'] = 95.
     price = utils.call(self.method, self.params)
     self.assertAlmostEqual(21.284883096, price, places=9)
コード例 #27
0
ファイル: test_knock_out.py プロジェクト: zhanrendong/jkzx1
 def test_call_price_case3(self):
     self.params['instrument'] = instruments.knock_out_continuous(
         self.option_property)
     self.params['spot'] = 100.
     price = utils.call(self.method, self.params)
     self.assertAlmostEqual(22.866574567, price, places=9)