def test_quantile_analysis_simple(self): f_df = pd.DataFrame(self.x) calculated = quantile_analysis(f_df, self.x_w, self.r, n_bins=self.n_bins, pre_process=[], post_process=[]) er = self.x_w @ self.x.T expected = er_quantile_analysis(er, self.n_bins, self.r) np.testing.assert_array_almost_equal(calculated, expected)
def test_quantile_analysis_with_factor_processing(self): f_df = pd.DataFrame(self.x) calculated = quantile_analysis(f_df, self.x_w, self.r, n_bins=self.n_bins, risk_exp=self.risk_exp, pre_process=[winsorize_normal, standardize], post_process=[standardize]) er = self.x_w @ factor_processing(self.x, [winsorize_normal, standardize], self.risk_exp, [standardize]).T expected = er_quantile_analysis(er, self.n_bins, self.r) np.testing.assert_array_almost_equal(calculated, expected)
def test_quantile_analysis_with_benchmark(self): f_df = pd.DataFrame(self.x) calculated = quantile_analysis(f_df, self.x_w, self.r, n_bins=self.n_bins, do_neutralize=True, benchmark=self.b_w, risk_exp=self.risk_exp, pre_process=[winsorize_normal, standardize], post_process=[standardize]) er = self.x_w @ factor_processing(self.x, [winsorize_normal, standardize], self.risk_exp, [standardize]).T raw_er = er_quantile_analysis(er, self.n_bins, self.r) expected = raw_er * self.b_w.sum() - np.dot(self.b_w, self.r) np.testing.assert_array_almost_equal(calculated, expected)