Add minute bar feature pipeline
This commit is contained in:
@@ -347,3 +347,69 @@ 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"}
|
||||
|
||||
|
||||
# --- feature-aware alpha integration ----------------------------------------
|
||||
|
||||
def test_compute_alpha_without_feature_path_matches_empty_feature_paths():
|
||||
data = _make_data()
|
||||
|
||||
base = compute_alpha(data, "rev5", "reversal", lookback=5)
|
||||
with_empty_features = compute_alpha(
|
||||
data,
|
||||
"rev5",
|
||||
"reversal",
|
||||
lookback=5,
|
||||
feature_paths=[],
|
||||
)
|
||||
|
||||
pd.testing.assert_frame_equal(base, with_empty_features)
|
||||
|
||||
|
||||
def test_feature_aware_alpha_reads_joined_feature_column(tmp_path):
|
||||
module_path = tmp_path / "feature_aware_alpha.py"
|
||||
module_path.write_text(textwrap.dedent('''
|
||||
import pandas as pd
|
||||
from pipeline.alpha.base import BaseAlpha
|
||||
from pipeline.alpha.registry import register_alpha
|
||||
|
||||
@register_alpha
|
||||
class FeatureAwareAlpha(BaseAlpha):
|
||||
name = "feature_aware_test_alpha"
|
||||
|
||||
def signal_from_data(
|
||||
self,
|
||||
data: pd.DataFrame,
|
||||
close: pd.DataFrame,
|
||||
) -> pd.DataFrame:
|
||||
signal = data.pivot_table(
|
||||
index="date",
|
||||
columns="symbol_id",
|
||||
values="toy_feature",
|
||||
aggfunc="first",
|
||||
)
|
||||
return signal.reindex(index=close.index, columns=close.columns)
|
||||
'''))
|
||||
|
||||
data = _make_data()
|
||||
feature = data[["symbol_id", "date"]].copy()
|
||||
feature["toy_feature"] = feature["symbol_id"].map({
|
||||
"sh600000": 1.0,
|
||||
"sz000001": 2.0,
|
||||
"sh600519": 3.0,
|
||||
})
|
||||
feature_path = tmp_path / "toy_feature.pq"
|
||||
feature.to_parquet(feature_path, index=False)
|
||||
|
||||
load_alpha_module(str(module_path))
|
||||
result = compute_alpha(
|
||||
data,
|
||||
"feature_run",
|
||||
"feature_aware_test_alpha",
|
||||
feature_paths=[str(feature_path)],
|
||||
)
|
||||
|
||||
assert list(result.columns) == ALPHA_COLUMNS
|
||||
assert (result["alpha_name"] == "feature_run").all()
|
||||
last = result[result["date"] == result["date"].max()]
|
||||
assert last.set_index("symbol_id")["weight"].idxmax() == "sh600519"
|
||||
|
||||
Reference in New Issue
Block a user