Ejemplo n.º 1
0
 def test_balance_interpolate_edge_rate(self):
     rates = [
         Rate(self.base_date, 0.003),
         Rate(self.base_date + timedelta(1), 0.004)
     ]
     output = UserAccount.balance_interpolate(100, self.base_date,
                                              self.base_date + timedelta(1),
                                              rates)
     self.assertEqual(output, 100 * 1.003)
Ejemplo n.º 2
0
    def test_balance_interpolate_multiple_rates(self):
        rates = [
            Rate(self.base_date, 0.003),
            Rate(self.base_date + timedelta(10), 0.004),
            Rate(self.base_date + timedelta(15), 0.007),
            Rate(self.base_date + timedelta(20), 0.001)
        ]

        output = UserAccount.balance_interpolate(
            200, self.base_date + timedelta(4), self.base_date + timedelta(24),
            rates)
        self.assertEqual(
            output, 200 * (1 + 0.003)**6 * (1 + 0.004)**5 * (1 + 0.007)**5 *
            (1 + 0.001)**4)
Ejemplo n.º 3
0
    def setUp(self):
        super().setUp()

        self.base_datetime = datetime(
            2015,
            1,
            1,
        )
        self.base_date = self.base_datetime.date()
        self.day = timedelta(1)
        self.cashflows = [
            CashFlow(amount=am, datetime=self.base_datetime + td * self.day)
            for am, td in [(-1000,
                            0), (200, 20), (300, 30), (250, 30), (-100,
                                                                  40), (50,
                                                                        40)]
        ]
        self.rates = [
            Rate(self.base_date + td * self.day, rate)
            for rate, td in [(0.005, -5), (0.004, 0), (0., 50), (0.001, 100)]
        ]
Ejemplo n.º 4
0
 def test_balance_interpolate_same_day(self):
     rates = [Rate(self.base_date - timedelta(50), 0.003)]
     output = UserAccount.balance_interpolate(100, self.base_date,
                                              self.base_date, rates)
     self.assertEqual(output, 100.)
Ejemplo n.º 5
0
 def test_balance_interpolate_partial_rate(self):
     rates = [Rate(self.base_date + timedelta(50), 0.003)]
     output = UserAccount.balance_interpolate(
         100, self.base_date, self.base_date + timedelta(60), rates)
     self.assertEqual(output, 100 * (1 + 0.003)**10)
Ejemplo n.º 6
0
 def test_balance_interpolate_future_rate(self):
     rates = [Rate(self.base_date + timedelta(70), 0.003)]
     output = UserAccount.balance_interpolate(
         100, self.base_date, self.base_date + timedelta(60), rates)
     self.assertEqual(output, 100)
Ejemplo n.º 7
0
 def balance(as_of):
     return UserAccount.balance_from_cashflows(
         cashflows, [Rate(self.dt, interest_daily)], as_of)