news 2026/7/21 23:19:50

金融数据采集_financial-data-collector

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
金融数据采集_financial-data-collector

以下为本文档的中文说明

financial-data-collector 是一个专业的金融数据采集技能,能够从 yfinance 等免费公开渠道收集美国上市公司的真实财务数据,并以标准化 JSON 格式输出,供下游金融分析技能(如 DCF 估值建模、可比公司分析、财报审查)使用。该技能有严格的数据采集规范:第一,严格禁止使用回退值——如果某个字段无法获取,必须设置为 null 并附带 _source: missing 标记,绝不允许用默认值替代(例如不能将缺失的 beta 值设为 1.0),由下游技能自行决定如何处理缺失数据。第二,强制数据来源标注——每个数据部分都必须包含 _source 字段,确保数据可追溯。第三,保持原始符号约定——yfinance 返回的 CapEx(资本支出)为负值(现金流出),必须保留原始符号并在输出元数据中注明约定。第四,明确数据差异——yfinance 的自由现金流与投资银行算法不同(yfinance FCF = 运营现金流 + CapEx,不扣除股权激励),必须标注这一差异。该技能采集的数据涵盖:市场数据(价格、流通股、Beta)、历史财务报表(利润表、现金流量表、资产负债表)、WACC 输入参数、分析师预测。核心原则是“真实、可追溯、不篡改”——金融数据的准确性是后续分析的前提,任何人为回退或修改都可能误导决策。


Financial Data Collector

Collect and validate real financial data for US public companies using free data sources.
Output is a standardized JSON file ready for consumption by other financial skills.

Critical Constraints

NO FALLBACK values.If a field cannot be retrieved, set it tonullwith_source: "missing".
Never substitute defaults (e.g.,beta or 1.0). The downstream skill decides how to handle missing data.

Data source attribution is mandatory.Every data section must have a_sourcefield.

CapEx sign convention:yfinance returns CapEx as negative (cash outflow). Preserve the original sign. Document the convention in output metadata. Do NOT flip signs.

yfinance FCF ≠ Investment bank FCF.yfinance FCF = Operating CF + CapEx (no SBC deduction). Flag this in output metadata so downstream DCF skills don’t overstate FCF.

Workflow

Step 1: Collect Data

Run the collection script:

python scripts/collect_data.py TICKER[--years5][--output path/to/output.json]

The script collects in this priority:

  1. yfinance— market data, historical financials, beta, analyst estimates
  2. yfinance ^TNX— 10Y Treasury yield as risk-free rate proxy
  3. User supplement— for years where yfinance returns NaN (report to user, do not guess)

Step 2: Validate Data

python scripts/validate_data.py path/to/output.json

Checks: field completeness, cross-field consistency (Market Cap = Price × Shares), range sanity (WACC 5-20%, beta 0.3-3.0), sign conventions.

Step 3: Deliver JSON

Single file:{TICKER}_financial_data.json. Schema inreferences/output-schema.md.

Do NOT create: README, CSV, summary reports, or any auxiliary files.

Output Schema (Summary)

{"ticker":"META","company_name":"Meta Platforms, Inc.","data_date":"2026-03-02","currency":"USD","unit":"millions_usd","data_sources":{"market_data":"...","2022_to_2024":"..."},"market_data":{"current_price":648.18,"shares_outstanding_millions":2187,"market_cap_millions":1639607,"beta_5y_monthly":1.284},"income_statement":{"2024":{"revenue":164501,"ebit":69380,"tax_expense":...,"net_income":...,"_source":"yfinance"}},"cash_flow":{"2024":{"operating_cash_flow":...,"capex":-37256,"depreciation_amortization":15498,"free_cash_flow":...,"change_in_nwc":...,"_source":"yfinance"}},"balance_sheet":{"2024":{"total_debt":30768,"cash_and_equivalents":77815,"net_debt":-47047,"current_assets":...,"current_liabilities":...,"_source":"yfinance"}},"wacc_inputs":{"risk_free_rate":0.0396,"beta":1.284,"credit_rating":null,"_source":"yfinance + ^TNX"},"analyst_estimates":{"revenue_next_fy":251113,"revenue_fy_after":295558,"eps_next_fy":29.59,"_source":"yfinance"},"metadata":{"_capex_convention":"negative = cash outflow","_fcf_note":"yfinance FCF = OperatingCF + CapEx. Does NOT deduct SBC."}}

Full schema with all field definitions:references/output-schema.md

<correct_patterns>

Handling Missing Years

ifpd.isna(revenue):result[year]={"revenue":None,"_source":"yfinance returned NaN — supplement from 10-K"}# Report missing years to the user. Do NOT skip or fill with estimates.

CapEx Sign Preservation

capex=cash_flow.loc["Capital Expenditure",year_col]# -37256.0result["capex"]=float(capex)# Preserve negative

Datetime Column Indexing

year_col=[cforcinfinancials.columnsifc.year==target_year][0]revenue=financials.loc["Total Revenue",year_col]

Field Name Guards

if"Total Revenue"infinancials.index:revenue=financials.loc["Total Revenue",year_col]elif"Revenue"infinancials.index:revenue=financials.loc["Revenue",year_col]else:revenue=None

</correct_patterns>

<common_mistakes>

Mistake 1: Default Values for Missing Data

# ❌ WRONGbeta=info.get("beta",1.0)growth=data.get("growth")or0.02# ✅ RIGHTbeta=info.get("beta")# May be None — that's OK

Mistake 2: Assuming All Years Have Data

# ❌ WRONG — 2020-2021 may be NaNrevenue=float(financials.loc["Total Revenue",year_col])# ✅ RIGHTvalue=financials.loc["Total Revenue",year_col]revenue=float(value)ifpd.notna(value)elseNone

Mistake 3: Using yfinance FCF in DCF Models Directly

yfinance FCF does NOT deduct SBC. For mega-caps like META, SBC can be $20-30B/yr, making yfinance FCF ~30% higher than investment-bank FCF. Always flag this in output.

Mistake 4: Flipping CapEx Sign

# ❌ WRONG — double-negation risk downstreamcapex=abs(cash_flow.loc["Capital Expenditure",year_col])# ✅ RIGHT — preserve original, document conventioncapex=float(cash_flow.loc["Capital Expenditure",year_col])# -37256.0

</common_mistakes>

Known yfinance Pitfalls

Seereferences/yfinance-pitfalls.mdfor detailed field mapping and workarounds.

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/7/21 23:19:39

企业家AI原生学习平台推荐:AI迭代一日千里,高参学堂直击行业前沿

现下,AI技术迭代速度远超以往任何产业。麦肯锡《2025年AI现状报告》显示,88%的企业已在至少一个业务中部署AI,但近三分之二仍停留在试验阶段,未能规模化落地。与此同时,斯坦福《2026 AI指数报告》指出,全球企业AI投资飙升至5817亿美元,中美AI差距已缩小至2.7%——技术红利窗口正…

作者头像 李华
网站建设 2026/7/21 23:16:34

猿人学第13题逆向实战:破解JS控制流平坦化与反调试

1. 项目概述&#xff1a;猿人学第13题的核心挑战最近在猿人学逆向反混淆练习平台上刷题&#xff0c;做到第13题时&#xff0c;发现它和前面几道题目的风格又不太一样了。这道题的核心&#xff0c;不再是简单的参数加密或者请求头校验&#xff0c;而是将加密逻辑巧妙地隐藏在了J…

作者头像 李华
网站建设 2026/7/21 23:14:43

工业交换机精准破解工业通信中的时间不同步与网络不可靠难题

为什么您的工业网络频频“掉链子”&#xff1f; 在智能电网、轨道交通、能源化工等行业&#xff0c;越来越多的设备依赖以太网进行控制与数据交互。然而&#xff0c;很多用户发现&#xff1a;网络时好时坏&#xff0c;设备动作不同步&#xff0c;一遇到恶劣环境就死机。这些问题…

作者头像 李华
网站建设 2026/7/21 23:09:08

AI 审合同:法务总监从“想吐”到“真香”的三个月

先讲个真事。 去年年底&#xff0c;我帮一家中型制造企业做合同管理咨询。他们法务部只有两个人&#xff0c;一年要审将近两千份合同。采购合同、销售合同、供应商协议、保密协议、劳动合同——什么都有。 他们法务总监姓陈&#xff0c;四十出头&#xff0c;干了十几年企业法务…

作者头像 李华
网站建设 2026/7/21 23:07:23

卷心菜食疗:胃黏膜修复的科学原理与烹饪技巧

1. 这道家常菜为何被称为"胃病克星"&#xff1f;作为一名长期受胃病困扰的过来人&#xff0c;我深知胃黏膜损伤带来的痛苦。烧心、反酸、胃胀这些症状反复发作&#xff0c;吃药只能暂时缓解。直到三年前&#xff0c;我在一位老中医那里得知了一个简单有效的食疗方子—…

作者头像 李华
网站建设 2026/7/21 23:01:04

2026在职国内EMBA中立测评|民营企业家择校干货

一、测评前言民营企业家、企业创始人择校在职国内EMBA&#xff0c;常面临排名繁杂、特色模糊、适配性难判断等问题&#xff0c;容易出现择校与自身发展需求不匹配的情况。本文从全球办学排名、院校办学定位、课程体系、学员圈层、产业资源五大客观维度&#xff0c;横向对比主流…

作者头像 李华