WIP: feat: add ashare financial enrichment and skill packs#70
Draft
shadowinlife wants to merge 2 commits intoHKUDS:mainfrom
Draft
WIP: feat: add ashare financial enrichment and skill packs#70shadowinlife wants to merge 2 commits intoHKUDS:mainfrom
shadowinlife wants to merge 2 commits intoHKUDS:mainfrom
Conversation
There was a problem hiding this comment.
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_mapbefore 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 on lines
+569
to
+570
| This gate intentionally fails fast until the dedicated runtime financial | ||
| loader/assembler is wired into the runner. |
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}" |
| 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 |
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
4814540 to
46fd650
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Why
Changes
1.新增财务模块与 A 股子模块:
Test Plan
pytest --ignore=agent/tests/e2e_backtest --tb=short -q)Checklist
src/agent/,src/session/,src/providers/) without prior discussion