def test_corr_to_cov(): df = get_data() rets = risk_models.returns_from_prices(df).dropna() test_corr = risk_models.cov_to_corr(rets.cov()) new_cov = risk_models.corr_to_cov(test_corr, rets.std()) pd.testing.assert_frame_equal(new_cov, rets.cov()) with pytest.warns(RuntimeWarning) as w: cov_numpy = risk_models.corr_to_cov(test_corr.to_numpy(), rets.std()) assert len(w) == 1 assert str(w[0].message) == "corr_matrix is not a dataframe" assert isinstance(cov_numpy, pd.DataFrame) np.testing.assert_equal(cov_numpy.to_numpy(), new_cov.to_numpy())
def test_corr_to_cov(): df = get_data() rets = risk_models.returns_from_prices(df).dropna() test_corr = risk_models.cov_to_corr(rets.cov()) new_cov = risk_models.corr_to_cov(test_corr, rets.std()) pd.testing.assert_frame_equal(new_cov, rets.cov())