fix(factors): 修复 ts_corr/ts_cov 实现并添加 abs 函数支持
- 修复 ts_corr 和 ts_cov 使用 pl.rolling_corr/pl.rolling_cov 模块级函数 - 添加 abs 函数处理器到 translator - 扩展 notebook 中的因子定义(24 -> 49 个) - 更新 AGENTS.md 文档结构和 Training 模块说明
This commit is contained in:
@@ -78,6 +78,7 @@ class PolarsTranslator:
|
||||
self.register_handler("cs_neutral", self._handle_cs_neutral)
|
||||
|
||||
# 元素级数学函数 (element_wise)
|
||||
self.register_handler("abs", self._handle_abs)
|
||||
self.register_handler("log", self._handle_log)
|
||||
self.register_handler("exp", self._handle_exp)
|
||||
self.register_handler("sqrt", self._handle_sqrt)
|
||||
@@ -297,23 +298,23 @@ class PolarsTranslator:
|
||||
|
||||
@time_series
|
||||
def _handle_ts_corr(self, node: FunctionNode) -> pl.Expr:
|
||||
"""处理 ts_corr(x, y, window) -> rolling_corr(y, window)。"""
|
||||
"""处理 ts_corr(x, y, window) -> rolling_corr(x, y, window_size)。"""
|
||||
if len(node.args) != 3:
|
||||
raise ValueError("ts_corr 需要 3 个参数: (x, y, window)")
|
||||
x = self.translate(node.args[0])
|
||||
y = self.translate(node.args[1])
|
||||
window = self._extract_window(node.args[2])
|
||||
return x.rolling_corr(y, window_size=window)
|
||||
return pl.rolling_corr(x, y, window_size=window)
|
||||
|
||||
@time_series
|
||||
def _handle_ts_cov(self, node: FunctionNode) -> pl.Expr:
|
||||
"""处理 ts_cov(x, y, window) -> rolling_cov(y, window)。"""
|
||||
"""处理 ts_cov(x, y, window) -> rolling_cov(x, y, window_size)。"""
|
||||
if len(node.args) != 3:
|
||||
raise ValueError("ts_cov 需要 3 个参数: (x, y, window)")
|
||||
x = self.translate(node.args[0])
|
||||
y = self.translate(node.args[1])
|
||||
window = self._extract_window(node.args[2])
|
||||
return x.rolling_cov(y, window_size=window)
|
||||
return pl.rolling_cov(x, y, window_size=window)
|
||||
|
||||
@time_series
|
||||
def _handle_ts_var(self, node: FunctionNode) -> pl.Expr:
|
||||
@@ -494,6 +495,14 @@ class PolarsTranslator:
|
||||
expr = self.translate(node.args[0])
|
||||
return expr.log()
|
||||
|
||||
@element_wise
|
||||
def _handle_abs(self, node: FunctionNode) -> pl.Expr:
|
||||
"""处理 abs(expr) -> 绝对值。"""
|
||||
if len(node.args) != 1:
|
||||
raise ValueError("abs 需要 1 个参数: (expr)")
|
||||
expr = self.translate(node.args[0])
|
||||
return expr.abs()
|
||||
|
||||
@element_wise
|
||||
def _handle_exp(self, node: FunctionNode) -> pl.Expr:
|
||||
"""处理 exp(expr) -> 指数函数。"""
|
||||
|
||||
Reference in New Issue
Block a user