feat(data): 财务数据加载与清洗模块

新增 FinancialLoader 类,提供:
- 财务数据加载与清洗(保留合并报表,按 update_flag 去重)
- 支持 as-of join 拼接行情数据(无未来函数)
- 自动识别财务表并配置 asof_backward 拼接模式
This commit is contained in:
2026-03-04 23:35:20 +08:00
parent 620696c842
commit 3b42093100
12 changed files with 695 additions and 379 deletions

View File

@@ -4,24 +4,38 @@
"""
from dataclasses import dataclass, field
from typing import Any, Dict, List, Optional, Set, Union
from typing import Any, Dict, List, Literal, Optional, Set, Union
import polars as pl
@dataclass
class DataSpec:
"""数据规格定义。
"""数据规格定义(支持多表类型)
描述因子计算所需的数据表和字段。
描述因子计算所需的数据表和字段,支持多种拼接类型
Attributes:
table: 数据表名称
columns: 需要的字段列表
join_type: 拼接类型
- "standard": 标准等值匹配(默认)
- "asof_backward": 向后寻找最近历史数据(财务数据用)
left_on: 左表 join 键asof 模式下必须指定)
right_on: 右表 join 键asof 模式下必须指定)
"""
table: str
columns: List[str]
join_type: Literal["standard", "asof_backward"] = "standard"
left_on: Optional[str] = None # 行情表日期列名
right_on: Optional[str] = None # 财务表日期列名
def __post_init__(self):
"""验证 asof_backward 模式的参数。"""
if self.join_type == "asof_backward":
if not self.left_on or not self.right_on:
raise ValueError("asof_backward 模式必须指定 left_on 和 right_on")
@dataclass