def setUp(self): self.prob = np.arange(0, 1.01, 0.01) rate = dcs.prob_to_rate(self.prob, time=1. / 12) mult_rate_2 = rate * 2 mult_rate_half = rate * 0.5 self.mult_prob_2 = dcs.rate_to_prob(mult_rate_2, time=1. / 12) self.mult_prob_half = dcs.rate_to_prob(mult_rate_half, time=1. / 12)
def setUp(self): self.prob = np.arange(0, 1.01, 0.01) rate = dcs.prob_to_rate(self.prob, time=1./12) mult_rate_2 = rate * 2 mult_rate_half = rate * 0.5 self.mult_prob_2 = dcs.rate_to_prob(mult_rate_2, time=1./12) self.mult_prob_half = dcs.rate_to_prob(mult_rate_half, time=1./12)
def test_prob_rate_conversions2c(self): new = dcs.Units.convert(0.5, dcs.Units.AP, dcs.Units.AR) exp = dcs.prob_to_rate(0.5) self.assertEqual(new, exp)
def test_prob_rate_conversions1c(self): new = dcs.Units.convert(0.5, dcs.Units.MP, dcs.Units.AR) exp = dcs.prob_to_rate(dcs.convert_monthly_to_annual_probability(0.5)) self.assertEqual(new, exp)
def test_circular(self): prob = dcs.rate_to_prob(self.rate, self.time) np.testing.assert_array_almost_equal(prob, self.prob) rate = dcs.prob_to_rate(prob, self.time) np.testing.assert_array_almost_equal(rate, self.rate)
def test_gt_one(self): with self.assertRaises(ValueError): dcs.prob_to_rate(np.array([0., 0.5, 1.5]))
def test_lt_zero(self): with self.assertRaises(ValueError): dcs.prob_to_rate(np.array([0., 0.5, -1.]))
def test_scalar(self): rate = dcs.prob_to_rate(0) self.assertIn(rate, self.rate)
def test_conversion(self): rate = dcs.prob_to_rate(self.prob, self.time) np.testing.assert_array_almost_equal(rate, self.rate)