Пример #1
0
 def test_pv_zero_yields(self):
   dtypes = [np.float32, np.float64]
   for dtype in dtypes:
     yield_rates = [0., 0.]
     # 2 and 3 year bonds with 1000 face value and 4%, 6% semi-annual coupons.
     cashflows = np.array([20, 20, 20, 1020, 30, 30, 30, 30, 30, 1030],
                          dtype=dtype)
     times = np.array([0.5, 1, 1.5, 2, 0.5, 1, 1.50, 2, 2.5, 3], dtype=dtype)
     groups = np.array([0] * 4 + [1] * 6)
     expected_pvs = np.array([1080., 1180.])
     actual_pvs = self.evaluate(
         cashflows_lib.pv_from_yields(
             cashflows, times, yield_rates, groups=groups, dtype=dtype))
     np.testing.assert_allclose(expected_pvs, actual_pvs)
Пример #2
0
 def test_pv_from_yields_no_group(self):
   dtypes = [np.float32, np.float64]
   for dtype in dtypes:
     yield_rate = 0.04
     coupon_rate = 0.04
     # Fifteen year bond with semi-annual coupons.
     cashflows = np.array(
         [coupon_rate * 500] * 29 + [1000 + coupon_rate * 500], dtype=dtype)
     times = np.linspace(0.5, 15, num=30).astype(dtype)
     expected_pv = 995.50315587
     actual_pv = self.evaluate(
         cashflows_lib.pv_from_yields(
             cashflows, times, [yield_rate], dtype=dtype))
     np.testing.assert_allclose(expected_pv, actual_pv)
Пример #3
0
 def test_pv_infinite_yields(self):
   """Tests in the limit of very large yields."""
   dtypes = [np.float32, np.float64]
   for dtype in dtypes:
     yield_rates = [300., 300.]
     # 2 and 3 year bonds with 1000 face value and 4%, 6% semi-annual coupons.
     cashflows = np.array([20, 20, 20, 1020, 30, 30, 30, 30, 30, 1030],
                          dtype=dtype)
     times = np.array([0.5, 1, 1.5, 2, 0.5, 1, 1.50, 2, 2.5, 3], dtype=dtype)
     groups = np.array([0] * 4 + [1] * 6)
     expected_pvs = np.array([0., 0.])
     actual_pvs = self.evaluate(
         cashflows_lib.pv_from_yields(
             cashflows, times, yield_rates, groups=groups, dtype=dtype))
     np.testing.assert_allclose(expected_pvs, actual_pvs, atol=1e-9)