f93621e3fc
- 实现因子表达式注册表(registry.py) - 实现 Alpha158 子集内置因子库(library.py) - 使用 vnpy.alpha ts_ 算子语法(ts_mean, ts_delta, ts_max, ts_min) - 修正列名:close/open/high/low/volume(非 _price 后缀) - TDD 实现:8 测试全部通过 - 支持因子分类过滤(custom/builtin) - 防止重复注册 Co-Authored-By: Claude <noreply@anthropic.com>
30 lines
899 B
Python
30 lines
899 B
Python
"""内置因子库测试."""
|
|
from sanguo_factor.registry import list_factors, get_factor, _REGISTRY
|
|
import importlib
|
|
import sanguo_factor.library
|
|
|
|
|
|
def test_library_registers_on_import():
|
|
"""测试导入时自动注册内置因子."""
|
|
_REGISTRY.clear()
|
|
importlib.reload(sanguo_factor.library)
|
|
assert len(list_factors(category="builtin")) > 0
|
|
|
|
|
|
def test_builtin_factors_count():
|
|
"""测试内置因子数量正确."""
|
|
_REGISTRY.clear()
|
|
importlib.reload(sanguo_factor.library)
|
|
builtin_factors = list_factors(category="builtin")
|
|
assert len(builtin_factors) == 7
|
|
|
|
|
|
def test_builtin_factor_expressions():
|
|
"""测试内置因子表达式格式正确."""
|
|
_REGISTRY.clear()
|
|
importlib.reload(sanguo_factor.library)
|
|
ma5 = get_factor("ma5")
|
|
assert ma5 is not None
|
|
assert ma5["category"] == "builtin"
|
|
assert "ts_mean(close, 5)" in ma5["expression"]
|