Grid backtest helpers
Language: English · 简体中文
portfolio_backtester.grid_support provides reusable input, schedule, naming, and CSV helpers for backtest grids. It prepares evaluation inputs and result rows; it does not construct portfolios or make research decisions.
Inputs and schedules
resolve_output_pathexpands~and resolves relative output paths from the caller's current working directory.parse_date_listaccepts compactYYYYMMDDand parseable date strings, removes blank or invalid values, then sorts and de-duplicates the dates.resolve_rebalance_datesuses explicit dates when supplied and keeps only dates present in the scored data. Otherwise it derives dates from the requested frequency and, whenmin_symbols_per_dateis greater than one, filters dates that do not meet that symbol count.
Stable run names and result rows
safe_run_namebuilds a deterministic name from the base name,top_k, and cost in basis points. Buffer settings and weighting are included only when their corresponding flags are enabled; decimal points in cost are written asp.GRID_RESULT_FIELDSdefines the fixed CSV column order.init_grid_rowcreates a strategy-neutral row with the run inputs and empty result fields.write_grid_rowscreates the parent directory when needed and writes rows in the declared column order.
The helpers keep grid output structure stable across callers. Strategy-specific rules and interpretation remain with the caller.