feat(factors): 基础行情字段默认从 pro_bar 表获取

- 修改 Symbol 名称与数据库字段对齐:volume->vol, pct_change->pct_chg
- 修改 ExecutionPlanner._infer_data_specs,将基础行情字段路由到 pro_bar 表
- 支持的基础字段:open, high, low, close, vol, amount, pre_close, change, pct_chg 等
This commit is contained in:
2026-03-02 20:59:36 +08:00
parent 1a6fc2eeba
commit 9b826c1845
2 changed files with 46 additions and 12 deletions

View File

@@ -27,8 +27,8 @@ high = Symbol("high")
#: 最低价
low = Symbol("low")
#: 成交量
volume = Symbol("volume")
#: 成交量(数据库字段名为 vol
vol = Symbol("vol")
#: 成交额
amount = Symbol("amount")
@@ -39,8 +39,8 @@ pre_close = Symbol("pre_close")
#: 涨跌额
change = Symbol("change")
#: 涨跌幅
pct_change = Symbol("pct_change")
#: 涨跌幅(数据库字段名为 pct_chg
pct_chg = Symbol("pct_chg")
# ==================== 时间序列函数 (ts_*) ====================

View File

@@ -409,6 +409,8 @@ class ExecutionPlanner:
"""从依赖推导数据规格。
根据表达式中的函数类型推断回看天数需求。
基础行情字段open, high, low, close, vol, amount, pre_close, change, pct_chg
默认从 pro_bar 表获取。
Args:
dependencies: 依赖的字段集合
@@ -421,16 +423,48 @@ class ExecutionPlanner:
max_window = self._extract_max_window(expression)
lookback_days = max(1, max_window)
# 假设所有字段都来自 daily 表
columns = list(dependencies)
# 基础行情字段集合(这些字段从 pro_bar 表获取)
pro_bar_fields = {
"open",
"high",
"low",
"close",
"vol",
"amount",
"pre_close",
"change",
"pct_chg",
"turnover_rate",
"volume_ratio",
}
return [
DataSpec(
table="daily",
columns=columns,
lookback_days=lookback_days,
# 将依赖分为 pro_bar 字段和其他字段
pro_bar_deps = dependencies & pro_bar_fields
other_deps = dependencies - pro_bar_fields
data_specs = []
# pro_bar 表的数据规格
if pro_bar_deps:
data_specs.append(
DataSpec(
table="pro_bar",
columns=sorted(pro_bar_deps),
lookback_days=lookback_days,
)
)
]
# 其他字段从 daily 表获取
if other_deps:
data_specs.append(
DataSpec(
table="daily",
columns=sorted(other_deps),
lookback_days=lookback_days,
)
)
return data_specs
def _extract_max_window(self, node: Node) -> int:
"""从表达式中提取最大窗口大小。