Skip to content

WIP: feat: add ashare financial enrichment and skill packs#70

Draft
shadowinlife wants to merge 2 commits intoHKUDS:mainfrom
shadowinlife:checkpoint/ashare-financial-runtime
Draft

WIP: feat: add ashare financial enrichment and skill packs#70
shadowinlife wants to merge 2 commits intoHKUDS:mainfrom
shadowinlife:checkpoint/ashare-financial-runtime

Conversation

@shadowinlife
Copy link
Copy Markdown
Contributor

Summary

  • 新增 A 股基本面回测所需的财务数据增强模块,覆盖字段推断、字段注册、PIT 组装与 tushare 财务加载。
  • 在回测执行链路中接入财务运行时契约,支持策略侧稳定消费财务因子。
  • 补充并更新相关技能与测试,确保财务增强能力可用且可回归验证。

Why

  • 现有回测链路对财务数据支持不足,难以稳定支撑 A 股基本面策略构建与筛选。
  • 需要统一财务字段语义和运行时契约,降低数据路由与策略生成之间的耦合。
  • 通过补充测试覆盖关键路径,降低后续演进风险。

Changes

1.新增财务模块与 A 股子模块:

  • field inference
  • field registry
  • PIT assembler
  • tushare financial loader
  • runtime contracts
  1. 修改 backtest runner 以接入财务增强运行流程。
  2. 新增技能:ashare-financial-enrichment。
  3. 更新技能:data-routing、fundamental-filter、strategy-generate。
  4. 新增 6 个财务相关测试文件,覆盖字段推断、字段注册、契约、PIT 组装、runner 集成与 tushare loader。

Test Plan

  • Existing tests pass (pytest --ignore=agent/tests/e2e_backtest --tb=short -q)
  • New tests added (if applicable)
  • Tested manually (describe below)

Checklist

  • No changes to protected areas (src/agent/, src/session/, src/providers/) without prior discussion
  • No hardcoded values (API keys, file paths, magic numbers)
  • Code follows CONTRIBUTING.md guidelines
  • Documentation updated (if user-facing change)

Copilot AI review requested due to automatic review settings May 3, 2026 23:21
@shadowinlife shadowinlife marked this pull request as draft May 3, 2026 23:21
@shadowinlife shadowinlife changed the title feat: add ashare financial enrichment and skill packs WIP: feat: add ashare financial enrichment and skill packs May 3, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces an A-share (China) financial-statement enrichment pipeline for backtests, including registry-backed field planning, raw Tushare loaders, point-in-time (PIT) projection, and runner-side gating so strategies can reliably consume statement-derived factors.

Changes:

  • Add an A-share financial runtime bundle (field inference + registry + raw Tushare loader + PIT assembler) behind shared contracts.
  • Wire the backtest runner to validate/gate financial requests, plan the fetch mode (per-code vs VIP cross-section), and enrich the price data_map before running the strategy.
  • Add a new skill for the financial enrichment flow and update related skills; add tests covering the new modules and runner integration.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
agent/backtest/runner.py Adds financial gating, points checks, universe code resolution, fetch planning, and PIT enrichment integration into runner execution.
agent/backtest/financials/contracts.py Defines cross-market financial contracts (registry/loader/enricher/inference) and runtime bundle structure.
agent/backtest/financials/init.py Introduces package-level docs for market-scoped financial integrations.
agent/backtest/financials/ashare/init.py Exposes get_ashare_financial_runtime() runtime bundle for A-share financial enrichment.
agent/backtest/financials/ashare/field_registry.py Implements registry built from local Tushare markdown references; provides ownership lookup and grouped query planning.
agent/backtest/financials/ashare/field_inference.py Adds prompt/source-based field inference and produces a non-strict query plan for ambiguity reporting.
agent/backtest/financials/ashare/tushare_loader.py Implements raw Tushare table fetches for per-code and VIP period cross-sections with reserved-param protection.
agent/backtest/financials/ashare/pit_assembler.py Implements PIT visibility rules (ann_date next trade day), canonicalization, and data_map enrichment.
agent/tests/test_financial_runtime_contracts.py Validates the A-share runtime bundle conforms to shared protocol contracts.
agent/tests/test_financial_field_registry.py Tests supported tables, metadata parsing, ownership mapping, and query-plan behavior.
agent/tests/test_financial_field_inference.py Tests prompt/source inference and combined inference behavior with ambiguity preservation.
agent/tests/test_tushare_financial_loader.py Tests raw loader endpoint selection, field validation, and grouped fetching behavior.
agent/tests/test_pit_financial_assembler.py Tests PIT visibility logic, canonicalization rules, and enrichment schema validation.
agent/tests/test_runner_financials.py Tests runner gating (token/market/interval), points resolution, fetch-plan behavior, and main() integration.
agent/src/skills/ashare-financial-enrichment/SKILL.md Adds the dedicated gating/planning skill for A-share financial statement enrichment and PIT semantics.
agent/src/skills/strategy-generate/SKILL.md Updates strategy generation guidance to classify/route A-share statement-field strategies into the enrichment flow.
agent/src/skills/fundamental-filter/SKILL.md Clarifies scope boundary between simple fundamentals vs statement-style enrichment and routing rules.
agent/src/skills/data-routing/SKILL.md Adds a carve-out: no silent fallback routing when statement tables are required; require strict Tushare flow.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread agent/backtest/runner.py
Comment on lines +569 to +570
This gate intentionally fails fast until the dedicated runtime financial
loader/assembler is wired into the runner.
Comment thread agent/backtest/runner.py
Comment on lines +662 to +667
raise ValueError(
"financials require at least 2000 Tushare points for requested tables; "
f"requested tables={requested_tables_text}; "
f"current account points={available_points}; "
f"ordinary required points={ordinary_required_points}; "
f"ordinary required points by table={ordinary_required_points_text}"
Comment thread agent/backtest/runner.py
def _parse_explicit_tushare_points(config: dict) -> int | None:
"""Parse an explicit Tushare points override for compatibility fallbacks."""
financials = config.get("financials") or {}
raw_value = financials.get("tushare_points", os.getenv("TUSHARE_POINTS", "")).strip() if isinstance(financials.get("tushare_points", os.getenv("TUSHARE_POINTS", "")), str) else financials.get("tushare_points", os.getenv("TUSHARE_POINTS", ""))
Comment on lines +8 to +13
from backtest.financials.ashare.field_inference import (
infer_financial_fields,
infer_financial_fields_from_file,
infer_financial_fields_from_prompt,
infer_financial_fields_from_source,
)
from backtest.financials.contracts import FinancialFieldInferenceResult

from backtest.financials.ashare.field_registry import (
FinancialQueryPlan,
Comment on lines +117 to +120
result = api_method(**params)
if result is None:
return pd.DataFrame(columns=list(query_fields))
return result.copy()
Comment on lines +226 to +236

for code, frame in data_map.items():
enriched_frame = frame.copy()
for table_name, requested_fields in query_plan.requested_fields.items():
table_rows = raw_tables.get(table_name)
if table_rows is None or table_rows.empty:
continue
_validate_financial_table_schema(table_name, table_rows, requested_fields)
code_rows = table_rows[table_rows["ts_code"] == code].copy()
if code_rows.empty:
continue
shadowinlife and others added 2 commits May 4, 2026 07:28
Co-Authored-By: Claude Code <noreply@anthropic.com>

Co-Authored-By: copilot <noreply@ai-tool.com>
AI-Model: GPT-5.3-Codex
AI-Contributed/Feature: 2235/2235
AI-Contributed/UT: 987/987
Prevent macOS /tmp path canonicalization drift in run_dir normalization and add HOME-scoped fallback for extract tool journal path validation.

Co-Authored-By: Claude Code <noreply@anthropic.com>

AI-Model: GPT-5.3-Codex
Co-Authored-By: github-copilot <noreply@ai-tool.com>
AI-Contributed/Feature: 26/26
AI-Contributed/UT: 0/0
@shadowinlife shadowinlife force-pushed the checkpoint/ashare-financial-runtime branch from 4814540 to 46fd650 Compare May 3, 2026 23:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants