Use next-open returns for research eval

This commit is contained in:
Yuxuan Yan
2026-06-12 18:41:18 +08:00
parent 16b4988f16
commit 3c58a1372e
10 changed files with 552 additions and 270 deletions
+12 -13
View File
@@ -78,17 +78,17 @@ def test_evaluate_alpha_keys():
assert key in metrics
def test_evaluate_alpha_uses_next_period_returns():
dates = pd.date_range("2024-01-01", periods=4)
def test_evaluate_alpha_uses_next_open_to_next_open_returns():
dates = pd.date_range("2024-01-01", periods=5)
data = pd.concat([
pd.DataFrame({
"symbol_id": "sh600000",
"symbol_name": "sh600000",
"date": dates,
"open": [100.0, 200.0, 200.0, 200.0],
"high": [100.0, 200.0, 200.0, 200.0],
"low": [100.0, 200.0, 200.0, 200.0],
"close": [100.0, 200.0, 200.0, 200.0],
"open": [100.0, 100.0, 100.0, 100.0, 200.0],
"high": [100.0, 1000.0, 1000.0, 1000.0, 1000.0],
"low": [100.0, 1000.0, 1000.0, 1000.0, 1000.0],
"close": [100.0, 1000.0, 1000.0, 1000.0, 1000.0],
"volume": 1_000.0,
"amount": 1_000.0,
}),
@@ -96,10 +96,10 @@ def test_evaluate_alpha_uses_next_period_returns():
"symbol_id": "sz000001",
"symbol_name": "sz000001",
"date": dates,
"open": [100.0, 100.0, 200.0, 200.0],
"high": [100.0, 100.0, 200.0, 200.0],
"low": [100.0, 100.0, 200.0, 200.0],
"close": [100.0, 100.0, 200.0, 200.0],
"open": [100.0, 100.0, 100.0, 200.0, 200.0],
"high": [100.0, 10.0, 10.0, 10.0, 10.0],
"low": [100.0, 10.0, 10.0, 10.0, 10.0],
"close": [100.0, 10.0, 10.0, 10.0, 10.0],
"volume": 1_000.0,
"amount": 1_000.0,
}),
@@ -114,7 +114,7 @@ def test_evaluate_alpha_uses_next_period_returns():
metrics = evaluate_alpha(alpha, data)
assert metrics["n_dates"] == 2
assert np.isclose(metrics["cumulative_return"], 0.5)
assert np.isclose(metrics["cumulative_return"], 1.25)
def test_evaluate_alpha_excludes_signal_without_forward_return():
@@ -145,7 +145,7 @@ def test_evaluate_alpha_excludes_signal_without_forward_return():
], ignore_index=True)
alpha = pd.DataFrame({
"symbol_id": ["sh600000", "sz000001", "sh600000", "sz000001"],
"date": [dates[1], dates[1], dates[2], dates[2]],
"date": [dates[0], dates[0], dates[1], dates[1]],
"alpha_name": ["toy"] * 4,
"weight": [1.0, -1.0, -1.0, 1.0],
})
@@ -347,4 +347,3 @@ def test_universe_filter_does_not_corrupt_signal_history():
held = set(filtered.loc[filtered["weight"] != 0.0, "symbol_id"].unique())
# The two most liquid names (highest amount) are sh600519, sz300750.
assert held == {"sh600519", "sz300750"}