Ejemplo n.º 1
0
 def setUp(self):
     self.today = BusinessDate(20161231)
     self.schedule = BusinessSchedule(self.today, self.today + '5y', '1m')
     self.df = DiscountFactorCurve([self.today], [1.],
                                   interpolation=interpolation_scheme)
     self.df2 = DiscountFactorCurve([self.today], [.2],
                                    interpolation=interpolation_scheme)
     self.curve = CashRateCurve([self.today], [.1])
 def test_discount_factor_curve(self):
     zr_curve = ZeroRateCurve([self.today, self.today + '1d'], [.02, .02])
     df_curve = DiscountFactorCurve(
         zr_curve.domain,
         [1., zr_curve.get_discount_factor(self.today + '1d')])
     for p in self.periods:
         x = self.today + p
         self.assertAlmostEqual(df_curve.get_discount_factor(x, x), 1.)
         z = zr_curve.get_zero_rate(x)
         d = df_curve.get_zero_rate(x)
         self.assertAlmostEqual(z, d)
         z = zr_curve.get_discount_factor(x)
         d = df_curve.get_discount_factor(x)
         self.assertAlmostEqual(z, d)
         z = zr_curve.get_short_rate(x)
         d = df_curve.get_short_rate(x)
         self.assertAlmostEqual(z, d)
         z = zr_curve.get_cash_rate(x)
         d = df_curve.get_cash_rate(x)
         self.assertAlmostEqual(z, d)
Ejemplo n.º 3
0
    def test_simulation(self):
        # setup timewave framework
        producer = RiskFactorProducer(self.hull_white_curve)
        x_consumer = Consumer(lambda x: x.value)
        df_consumer = Consumer(lambda x: self.df_func(x.date))
        pv_consumer = ValuationConsumer(self.df_func)
        fw_consumer = Consumer(lambda x: self.fw_func(x.date))
        af_consumer = ValuationConsumer(self.fw_func)

        consumer = ConsumerConsumer(
            [x_consumer, df_consumer, pv_consumer, fw_consumer, af_consumer])

        # run the simulation
        x, df_sim, df_avg, fwd_sim, fwd_avg = Engine(producer, consumer).run(
            self.grid, self.num_of_paths)

        # self.plot['state_avg'] = [[sum(xx) / len(xx) for xx in map(list, zip(*x))]]
        # self.plot['state_path'] = x

        self.plot['libor_avg'] = [
            fwd_avg, [self.zero_curve.get_cash_rate(d) for d in self.grid]
        ]
        self.plot['libor_path'] = fwd_sim

        self.plot['df_avg'] = [
            df_avg,
            [
                self.zero_curve.get_discount_factor(self.today, self.termday)
                for d in self.grid
            ]
        ]
        self.plot['df_path'] = df_sim

        dfc = DiscountFactorCurve(self.grid, df_avg)
        self.plot['zero_avg'] = [[
            dfc.get_zero_rate(self.today, d) for d in self.grid
        ], [self.zero_curve.get_zero_rate(self.today, d) for d in self.grid]]
        zr_list = list()
        for dfs in df_sim:
            dfc = DiscountFactorCurve(self.grid, dfs)
            zr_list.append(
                [dfc.get_zero_rate(self.today, d) for d in self.grid])
        self.plot['zero_path'] = zr_list
Ejemplo n.º 4
0
 def setUp(self):
     self.today = BusinessDate(20161231)
     self.schedule = BusinessSchedule(self.today, self.today + '5y', '1m')
     self.rate = 0.01
     self.df = DiscountFactorCurve(ZeroRateCurve([self.today], [self.rate]))
     self.curve = CashRateCurve([self.today], [self.rate])
 def test_discount_cast(self):
     for p in self.periods:
         curve = self.curve(p)
         cast = self.cast_type(DiscountFactorCurve(curve))
         for d in curve.domain[1:]:
             self.assertAlmostEqual(cast(d), curve(d), self.precision)