Split proxy leakage tests

This commit is contained in:
2026-04-07 16:31:51 +08:00
parent 7afc60dfcb
commit 26937f035e

View File

@@ -333,7 +333,7 @@ class LocalFactorConstructionTests(unittest.TestCase):
0.0,
)
def test_build_proxy_core_factors_does_not_use_future_prices(self):
def test_build_proxy_core_factors_market_branch_does_not_use_future_benchmark_prices(self):
prices = self._make_price_frame(benchmark="000300.SS")
mutated = prices.copy()
future_start = prices.index[280]
@@ -343,25 +343,9 @@ class LocalFactorConstructionTests(unittest.TestCase):
changed = build_proxy_core_factors(mutated, benchmark="000300.SS", market="cn")
comparison_end = prices.index[279]
pd.testing.assert_frame_equal(original.loc[:comparison_end], changed.loc[:comparison_end])
pd.testing.assert_series_equal(
original["SMB_PROXY"],
changed["SMB_PROXY"],
check_names=False,
)
pd.testing.assert_series_equal(
original["HML_PROXY"],
changed["HML_PROXY"],
check_names=False,
)
pd.testing.assert_series_equal(
original["RMW_PROXY"],
changed["RMW_PROXY"],
check_names=False,
)
pd.testing.assert_series_equal(
original["CMA_PROXY"],
changed["CMA_PROXY"],
original.loc[:comparison_end, "MKT"],
changed.loc[:comparison_end, "MKT"],
check_names=False,
)
self.assertGreater(
@@ -369,6 +353,27 @@ class LocalFactorConstructionTests(unittest.TestCase):
0.0,
)
def test_build_proxy_core_factors_proxy_columns_do_not_use_future_stock_prices(self):
prices = self._make_price_frame(benchmark="000300.SS")
mutated = prices.copy()
future_start = prices.index[280]
mutated.loc[future_start:, "C"] = mutated.loc[future_start:, "C"] * 0.35
mutated.loc[future_start:, "D"] = mutated.loc[future_start:, "D"] * 1.6
original = build_proxy_core_factors(prices, benchmark="000300.SS", market="cn")
changed = build_proxy_core_factors(mutated, benchmark="000300.SS", market="cn")
comparison_end = prices.index[279]
proxy_columns = ["SMB_PROXY", "HML_PROXY", "RMW_PROXY", "CMA_PROXY"]
pd.testing.assert_frame_equal(
original.loc[:comparison_end, proxy_columns],
changed.loc[:comparison_end, proxy_columns],
)
self.assertGreater(
(original.loc[future_start:, proxy_columns] - changed.loc[future_start:, proxy_columns]).abs().sum().sum(),
0.0,
)
def test_build_proxy_core_factors_falls_back_to_equal_weight_market_when_benchmark_missing(self):
prices_with_benchmark = self._make_price_frame(benchmark="CN_BENCH")
prices = prices_with_benchmark.drop(columns=["CN_BENCH"])