Commit 9928de58 authored by Dr.李's avatar Dr.李

added more test for linear build

parent ee85a1c4
...@@ -31,6 +31,24 @@ class TestLinearBuild(unittest.TestCase): ...@@ -31,6 +31,24 @@ class TestLinearBuild(unittest.TestCase):
expected_risk = np.zeros(self.risk_exp.shape[1]) expected_risk = np.zeros(self.risk_exp.shape[1])
np.testing.assert_array_almost_equal(calc_risk, expected_risk) np.testing.assert_array_almost_equal(calc_risk, expected_risk)
def test_linear_build_with_inequality_constraints(self):
bm = self.bm / self.bm.sum()
eplson = 1e-6
status, value, w = linear_build(self.er,
0.,
0.01,
self.risk_exp,
bm,
risk_target=(-1e-2, 1e-2))
self.assertEqual(status, 'optimal')
self.assertAlmostEqual(np.sum(w), 1.)
self.assertTrue(np.all(w <= 0.01 + eplson))
self.assertTrue(np.all(w >= -eplson))
calc_risk = (w - bm) @ self.risk_exp / np.abs(bm @ self.risk_exp)
self.assertTrue(np.all(np.abs(calc_risk) <= 1e-2))
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment