Implementation:24mlight A Share investment Agent get financial metrics
| Knowledge Sources | |
|---|---|
| Domains | Finance, Data_Engineering |
| Last Updated | 2026-10-10 14:00 GMT |
Overview
Concrete tool for fetching A-share financial metrics (ROE, margins, growth, ratios) from AkShare/Sina with snapshot integration and default fallbacks, provided by the A_Share_investment_Agent repository.
Description
The get_financial_metrics function fetches financial indicators from Sina via the AkShare cache layer. It optionally uses a market snapshot for market cap data, filters by as_of_date, and returns a list of metric dictionaries. When data is unavailable, it returns default zero-valued metrics.
Key metrics returned: return_on_equity, net_margin, operating_margin, revenue_growth, earnings_growth, book_value_growth, current_ratio, debt_to_equity, free_cash_flow_per_share, earnings_per_share, pe_ratio, price_to_book, price_to_sales.
Usage
Import when you need to:
- Fetch financial metrics for fundamental analysis
- Provide data for the fundamentals_agent and valuation_agent
Code Reference
Source Location
- Repository: A_Share_investment_Agent
- File: src/tools/api.py
- Lines: L41-236
Signature
def get_financial_metrics(
symbol: str,
*,
trace_state: dict | None = None,
as_of_date: str | None = None,
snapshot: Dict[str, Any] | None = None,
) -> Dict[str, Any]:
"""Fetch financial metrics data for A-share stocks."""
Import
from src.tools.api import get_financial_metrics
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| symbol | str | Yes | Stock code (6-digit) |
| trace_state | dict | No | Trace state for logging |
| as_of_date | str | No | Cutoff date for data filtering |
| snapshot | dict | No | Pre-fetched market snapshot |
Outputs
| Name | Type | Description |
|---|---|---|
| return | list[dict] | List of financial metric dicts (first item used by agents) |
Usage Examples
from src.tools.api import get_financial_metrics
metrics = get_financial_metrics(
symbol="002848",
as_of_date="2025-01-15",
snapshot={"market_cap": 5000000000},
)
# metrics[0] = {
# "return_on_equity": 0.18,
# "net_margin": 0.22,
# "operating_margin": 0.16,
# "revenue_growth": 0.12,
# "earnings_growth": 0.15,
# ...
# }