def test_inst_curve(self):
     pre = 1  # some interpolation artifacts may occur
     domain = [
         self.today, self.today + '2y', self.today + '3y', self.today + '4y'
     ]
     data = [0.15, 0.2, 0.2, 0.19]
     inst_curve = InstantaneousVolatilityCurve(domain, data)
     term_curve = TerminalVolatilityCurve(inst_curve)
     for t in self.domain:
         for p in self.periods:
             x = t + p
             self.assertAlmostEqual(term_curve.get_terminal_vol(x),
                                    inst_curve.get_terminal_vol(x), pre)
             self.assertAlmostEqual(term_curve.get_terminal_vol(x, x),
                                    inst_curve.get_terminal_vol(x, x), pre)
             self.assertAlmostEqual(term_curve.get_instantaneous_vol(x),
                                    inst_curve.get_instantaneous_vol(x),
                                    pre)
 def test_terminal2_curve(self):
     domain = [
         self.today, self.today + '2y', self.today + '3y', self.today + '4y'
     ]
     data = [0.15, 0.2, 0.2, 0.15]
     term_curve = TerminalVolatilityCurve(domain, data)
     start = self.today + '3y'
     stop = self.today + '4y'
     self.assertRaises(ZeroDivisionError, term_curve.get_terminal_vol,
                       start, stop)
    def test_flat_curve(self):
        for value in (0.0, 0.01, 0.1, 0.2):
            data = [value] * len(self.domain)
            term_curve = TerminalVolatilityCurve(self.domain, data)
            inst_curve = InstantaneousVolatilityCurve(self.domain, data)
            for t in self.domain:
                for p in self.periods:
                    x = t + p
                    self.assertAlmostEqual(value,
                                           term_curve.get_terminal_vol(x))
                    self.assertAlmostEqual(value,
                                           inst_curve.get_terminal_vol(x))

                    self.assertAlmostEqual(value,
                                           term_curve.get_terminal_vol(x, x))
                    self.assertAlmostEqual(value,
                                           inst_curve.get_terminal_vol(x, x))

                    self.assertAlmostEqual(value,
                                           term_curve.get_instantaneous_vol(x))
                    self.assertAlmostEqual(value,
                                           inst_curve.get_instantaneous_vol(x))
Ejemplo n.º 4
0
 def test_terminal_curve(self):
     pre = 2
     domain = [
         self.today, self.today + '2y', self.today + '3y', self.today + '4y'
     ]
     data = [0.15, 0.2, 0.2, 0.19]
     term_curve = TerminalVolatilityCurve(domain, data)
     inst_curve = term_curve.cast(InstantaneousVolatilityCurve)
     for t in self.domain:
         for p in self.periods:
             x = t + p
             self.assertAlmostEqual(term_curve.get_terminal_vol(x),
                                    inst_curve.get_terminal_vol(x), pre)
             self.assertAlmostEqual(term_curve.get_terminal_vol(x, x),
                                    inst_curve.get_terminal_vol(x, x), pre)
             self.assertAlmostEqual(term_curve.get_instantaneous_vol(x),
                                    inst_curve.get_instantaneous_vol(x),
                                    pre)