Add offline workflow and coverage tests

This commit is contained in:
Yuxuan Yan
2026-06-16 17:37:16 +08:00
parent 8d908477e2
commit 31baa18ce5
16 changed files with 2104 additions and 9 deletions
+4 -3
View File
@@ -160,7 +160,8 @@ def reversal_vol(data_path, output_dir, lookback, vol_window):
@alpha.command("eval")
@click.option("--alpha-path", required=True, help="Path to alpha parquet file")
@click.option("--data-path", required=True, help="Path to data parquet (for price data)")
def eval_(alpha_path, data_path):
@click.option("--report-dir", default="reports", help="Directory to save JSON report")
def eval_(alpha_path, data_path, report_dir):
"""Evaluate an alpha's performance (return, Sharpe, turnover).
Alphas are interpreted as position WEIGHTS, not return predictors.
@@ -183,9 +184,9 @@ def eval_(alpha_path, data_path):
click.echo("=" * 50)
# Also dump JSON
os.makedirs("reports", exist_ok=True)
os.makedirs(report_dir, exist_ok=True)
alpha_name = alpha_df["alpha_name"].iloc[0]
json_path = f"reports/{alpha_name}_eval.json"
json_path = os.path.join(report_dir, f"{alpha_name}_eval.json")
with open(json_path, "w") as f:
json.dump(metrics, f, indent=2)
click.echo(f"\nReport saved: {json_path}")
+6 -5
View File
@@ -166,13 +166,14 @@ class ReferenceSimulator(ExecutionSimulator):
st = wide(data_df, "isST") if "isST" in data_df.columns else opn * 0.0
symbols = sorted(set(tgt.columns) | set(opn.columns))
data_index = close.index
tgt = tgt.reindex(columns=symbols)
opn = opn.reindex(columns=symbols)
opn = opn.reindex(index=data_index, columns=symbols)
close = close.reindex(columns=symbols)
preclose = preclose.reindex(columns=symbols)
amount = amount.reindex(columns=symbols)
tstat = tstat.reindex(columns=symbols)
st = st.reindex(columns=symbols)
preclose = preclose.reindex(index=data_index, columns=symbols)
amount = amount.reindex(index=data_index, columns=symbols)
tstat = tstat.reindex(index=data_index, columns=symbols)
st = st.reindex(index=data_index, columns=symbols)
sym_arr = np.asarray(symbols, dtype=object)
n = len(symbols)