mirror of
https://ghfast.top/https://github.com/aeroxw/easy-tdx.git
synced 2026-09-12 22:44:17 +08:00
feat(factor): wire up builtin factor auto-registration and export
This commit is contained in:
@@ -1,7 +1,18 @@
|
||||
# src/easy_tdx/factor/__init__.py
|
||||
"""因子研究模块。"""
|
||||
from __future__ import annotations
|
||||
|
||||
from easy_tdx.factor.base import FACTORY_REGISTRY, Factor, register_factor
|
||||
from easy_tdx.factor.engine import FactorEngine
|
||||
|
||||
__all__ = ["Factor", "register_factor", "FACTORY_REGISTRY", "FactorEngine"]
|
||||
# 导入 builtin 触发自动注册
|
||||
from easy_tdx.factor.builtin import get_factor, list_factors # noqa: F401
|
||||
|
||||
__all__ = [
|
||||
"Factor",
|
||||
"register_factor",
|
||||
"FACTORY_REGISTRY",
|
||||
"FactorEngine",
|
||||
"list_factors",
|
||||
"get_factor",
|
||||
]
|
||||
|
||||
@@ -1,2 +1,41 @@
|
||||
"""内置因子包 — 导入即注册。"""
|
||||
"""内置因子库 — 导入子模块触发注册。"""
|
||||
from __future__ import annotations
|
||||
|
||||
from easy_tdx.factor.base import FACTORY_REGISTRY, Factor
|
||||
|
||||
# 导入所有子模块以触发 @register_factor 装饰器
|
||||
from easy_tdx.factor.builtin import ( # noqa: F401
|
||||
chanlun,
|
||||
momentum,
|
||||
quality,
|
||||
technical,
|
||||
value,
|
||||
volatility,
|
||||
volume,
|
||||
)
|
||||
|
||||
|
||||
def list_factors() -> list[dict[str, str | tuple[str, ...]]]:
|
||||
"""返回所有已注册因子的元数据。"""
|
||||
return [
|
||||
{
|
||||
"name": cls.name,
|
||||
"category": cls.category,
|
||||
"description": cls.description,
|
||||
"inputs": cls.inputs,
|
||||
}
|
||||
for cls in FACTORY_REGISTRY.values()
|
||||
]
|
||||
|
||||
|
||||
def get_factor(name: str) -> type[Factor]:
|
||||
"""按名称获取因子类。
|
||||
|
||||
Raises:
|
||||
ValueError: 因子不存在。
|
||||
"""
|
||||
if name not in FACTORY_REGISTRY:
|
||||
raise ValueError(
|
||||
f"未知因子: {name!r}。可用因子: {sorted(FACTORY_REGISTRY.keys())}"
|
||||
)
|
||||
return FACTORY_REGISTRY[name]
|
||||
|
||||
Reference in New Issue
Block a user