def test_interpolated_forwards_with_discrete_forwards(self): dtypes = [np.float32, np.float64] for dtype in dtypes: reference_times = tf.constant([0.25, 0.5, 1.0, 2.0, 3.0], dtype=dtype) discrete_forwards = tf.constant([0.05, 0.051, 0.052, 0.053, 0.055], dtype=dtype) test_times = tf.constant([0.25, 0.5, 1.0, 2.0, 3.0, 1.1], dtype=dtype) expected = np.array( [0.0505, 0.05133333, 0.05233333, 0.054, 0.0555, 0.05241], dtype=dtype) actual = self.evaluate( monotone_convex.interpolate_forward_rate( test_times, reference_times, discrete_forwards=discrete_forwards)) np.testing.assert_allclose(actual, expected, rtol=1e-5)
def test_interpolated_forwards_with_yields(self): dtypes = [np.float32, np.float64] for dtype in dtypes: reference_times = np.array([1.0, 2.0, 3.0, 4.0, 5.0], dtype=dtype) yields = np.array([2.75, 4.0, 4.75, 5.0, 4.75], dtype=dtype) / 100 # Times for which the interpolated values are required. interpolation_times = np.array([0.3, 1.3, 2.1, 4.5], dtype=dtype) actual = self.evaluate( monotone_convex.interpolate_forward_rate( interpolation_times, reference_times=reference_times, yields=yields)) expected = np.array([0.0229375, 0.05010625, 0.0609, 0.03625], dtype=dtype) np.testing.assert_allclose(actual, expected, rtol=1e-5)