Fin Data Acquisition logo

Fin Data Acquisition

Community
csmar432
fin-data-acquisition

根据REFINED_DESIGN.md中的变量定义,自动获取所需数据并生成可执行的回归分析脚本(Python/Stata)。

Overview

Publishercsmar432
Repositoryfinai-research
Skill namefin-data-acquisition
Stars
108
Forks
4
Bundled files
Instructions only
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by csmar432 on GitHub. Read the source before you install it.

Installation

Install the Fin Data Acquisition AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/csmar432/finai-research/tree/main/.agents/skills/fin-data-acquisition
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/csmar432/finai-research.git /tmp/finai-research
mkdir -p .claude/skills
cp -r /tmp/finai-research/.agents/skills/fin-data-acquisition .claude/skills/fin-data-acquisition
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Fin Data Acquisition in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Fin Data Acquisition on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Fin Data Acquisition is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

fin-data-acquisition

根据REFINED_DESIGN.md中的变量定义,自动获取所需数据并生成可执行的回归分析脚本(Python/Stata)。

触发条件

  • 关键词: 获取数据 数据获取 data acquisition 下载数据 数据准备 实证数据
  • Skill语法: Skill: fin-data-acquisition
  • 前置条件: 已完成 REFINED_DESIGN.md (研究设计文档)

核心原则

禁止行为 (未经用户明确授权不得执行)

❌ 静默回退到模拟数据
❌ 自动生成虚假回归结果
❌ 在用户未同意情况下继续流水线使用模拟数据
❌ 跳过数据源预检查直接获取数据

数据源预检查 (强制执行)

在任何数据获取前,必须先运行数据源检查:

python
from scripts.data_source_checker import DataSourceChecker, DataRequirement

# 第一步:定义数据需求
requirements = [
    DataRequirement(
        name="financial_data",
        user_facing_name="A股财务数据",
        description="ROA、资产负债率、企业规模、研发投入",
        sources=["tushare", "wind", "csmar", "akshare"],
        required=True,
    ),
    DataRequirement(
        name="esg_data",
        user_facing_name="ESG评级",
        sources=["msci", "商道融绿", "华证"],
        required=False,
    ),
    DataRequirement(
        name="macro_data",
        user_facing_name="宏观数据",
        sources=["user-financial", "user-wb-data", "user-imf-data"],
        required=True,
    ),
]

# 第二步:运行数据源检查
checker = DataSourceChecker()
results = checker.check(requirements)

# 第三步:展示可用性报告
checker.print_report(results)

数据源Fallback链

每个数据类型都有明确的降级路径:

A股财务数据

tushare (需TUSHARE_TOKEN)
  ↓ 失败/无Token
wind (需Wind账号)
  ↓ 失败/无账号
csmar (需机构账号)
  ↓ 失败/无账号
akshare (免费,备选)
  ↓ 失败
手动下载 -> 询问用户

宏观数据

user-financial (akshare, 免费)
  ↓ 失败
user-wb-data (World Bank, 免费)
  ↓ 失败
user-imf-data (IMF, 免费)
  ↓ 失败
手动下载 -> 询问用户

美股数据

user-yfinance (免费)
  ↓ 失败
user-eodhd (需EODHD_API_KEY)
  ↓ 失败/无Key
手动下载 -> 询问用户

学术文献数据

user-openalex (免费)
  ↓ 失败
user-arxiv (免费)
  ↓ 失败
user-nber-wp (免费)
  ↓ 失败
手动检索 -> 询问用户

DataFetcher API

python
from scripts.research_framework import DataFetcher, ProvenanceTracker

# 初始化 (带数据溯源)
tracker = ProvenanceTracker(output_dir="data/provenance/")
fetcher = DataFetcher(output_dir="data/", tracker=tracker, verbose=True)

# ============ 面板数据获取 ============
df = fetcher.fetch_panel(
    tickers=["000001.SZ", "600000.SH"],
    years=["2018", "2019", "2020", "2021", "2022"],
    statements=["balance", "income", "cashflow"],
    include_sustainability=True,  # ESG数据
)

# ============ 财务报表获取 ============
fin = fetcher.fetch_financials("000001.SZ", "income")  # 利润表
fin = fetcher.fetch_financials("000001.SZ", "balance")  # 资产负债表
fin = fetcher.fetch_financials("000001.SZ", "cashflow")  # 现金流量表

# ============ 公司信息获取 ============
info = fetcher.fetch_ticker_info("000001.SZ")  # 股票基本信息

# ============ ESG/可持续发展数据 ============
sust = fetcher.fetch_sustainability("000001.SZ")  # ESG评级等

# ============ 宏观数据获取 ============
macro = fetcher.fetch_macro(indicator="gdp", country="CHN")

# ============ 融资融券数据 ============
margin = fetcher.fetch_margin(ts_code="000001.SZ", start_date="20180101")

# ============ 陆股通/港股通 ============
hgt = fetcher.fetch_hsgt_top10(date="20240101")

# ============ 分析师预测 ============
forecast = fetcher.fetch_consensus("000001.SZ")

MCP数据获取

直接调用MCP工具

python
# A股行情数据 (tushare)
server: user-tushare
tool: get_daily_quote
params: { "ts_code": "000001.SZ", "start_date": "20240101", "end_date": "20241231" }

# 财务报告 (tushare)
server: user-tushare
tool: get_financial_report
params: { "ts_code": "000001.SZ", "report_type": "income" }

# 美股数据 (yfinance)
server: user-yfinance
tool: get_yf_historical
params: { "ticker": "AAPL", "start_date": "2024-01-01", "end_date": "2024-12-31" }

# 宏观数据 (World Bank)
server: user-wb-data
tool: get_wb_indicator
params: { "country_code": "CHN", "indicator": "wb_gdp_usd" }

# 研报数据 (eastmoney)
server: user-eastmoney-reports
tool: get_research_report
params: { "ts_code": "000001.SZ", "max_results": 20 }

回归脚本生成

Python脚本模板

python
"""
{研究标题} — 回归分析脚本
Generated by fin-data-acquisition skill
Date: {date}
"""

import pandas as pd
import numpy as np
import statsmodels.api as sm
from scipy import stats
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
warnings.filterwarnings('ignore')

# ============ 配置 ============
DATA_PATH = "data/processed/{dataset_name}.csv"
OUTPUT_DIR = "output/fin-experiments/"

# ============ 数据加载 ============
df = pd.read_csv(DATA_PATH)
print(f"样本量: {len(df)}, 时间范围: {df['year'].min()}-{df['year'].max()}")
print(f"处理组: {df['treat'].sum()}, 对照组: {(1-df['treat']).sum()}")

# ============ 描述性统计 ============
desc = df[['y_var', 'x_var', 'controls']].describe()
desc.to_csv(f"{OUTPUT_DIR}/descriptive_stats.csv")
print(desc)

# ============ 相关性矩阵 ============
corr = df[['y_var', 'x_var', 'controls']].corr()
sns.heatmap(corr, annot=True, cmap='RdBu_r', center=0)
plt.savefig(f"{OUTPUT_DIR}/correlation_matrix.pdf", dpi=300)
plt.close()

# ============ 基准回归 ============
# OLS
X = sm.add_constant(df[['x_var'] + ['controls']])
y = df['y_var']
model = sm.OLS(y, X).fit(cov_type='cluster', cov_kwds={'groups': df['firmid']})
print(model.summary())

# DID回归 (带双向固定效应)
from linearmodels.panel import PanelOLS
df = df.set_index(['firmid', 'year'])
mod = PanelOLS.from_formula('y_var ~ x_var + EntityEffects + TimeEffects', df)
res = mod.fit(cov_type='clustered', cluster_entity=True)
print(res.summary)

# ============ 保存结果 ============
results = {
    'coefficient': model.params,
    'std_error': model.bse,
    'p_value': model.pvalues,
    'r_squared': model.rsquared,
}
pd.DataFrame(results).to_csv(f"{OUTPUT_DIR}/regression_results.csv")

Stata脚本模板

stata
/*
{研究标题} — Stata回归分析
Generated by fin-data-acquisition skill
Date: {date}
*/

clear all
cd "data/processed/"

* 加载数据
import delimited "{dataset_name}.csv", clear

* 描述性统计
estpost summarize y_var x_var controls, detail
esttab using "descriptive_stats.tex", cells("mean sd min p25 p50 p75 max") replace

* 相关性矩阵
pwcorr y_var x_var controls, star(5) sig

* 基准回归 (OLS + 聚类标准误)
reg y_var x_var controls, vce(cluster firmid)

* 双向固定效应 (DID)
encode firmid, gen(firm)
encode year, gen(year_dum)
xtset firm year_dum
xtreg y_var x_var controls i.year_dum, fe vce(cluster firm)

* 平行趋势检验
gen pre1 = (year == treated_year - 1)
gen post0 = (year == treated_year)
gen post1 = (year == treated_year + 1)
reg y_var pre1 post0 post1 controls i.year_dum, vce(cluster firm)

* 安慰剂检验
xtreg y_var placebo_* controls i.year_dum, fe vce(cluster firm)

* 异质性分析
bysort group: xtreg y_var x_var controls i.year_dum, fe vce(cluster firm)

esttab using "regression_results.tex", b(4) se(4) star(* 0.1 ** 0.05 *** 0.01) replace

数据溯源追踪

每个数据获取操作都记录溯源信息:

python
from scripts.core.provenance import DataProvenance

provenance = DataProvenance()

# 记录数据获取
provenance.record_fetch(
    source="tushare",
    table="financial_statement",
    timestamp=datetime.now(),
    rows=len(df),
    fields=list(df.columns),
    query_params={"ts_code": "000001.SZ", "year": 2022},
)

# 记录数据转换
provenance.record_transform(
    input_tables=["financial_statement", "trading_data"],
    output_table="merged_panel",
    transformation="merge on [ts_code, year]",
    rows_before=[1000, 500],
    rows_after=800,
)

# 导出溯源报告
provenance.export("data/provenance/provenance_report.json")

Checkpoint (强制交互)

[CHECKPOINT] 数据源预检查完成。

可用性报告:
✅ A股财务数据: tushare 可用 (Token已配置)
✅ 宏观数据: user-financial 可用
⚠️ ESG数据: MSCI需账号 (可选数据)
❌ 陆股通数据: tushare当前版本不支持

问题数据:
- 陆股通成分股数据需要Wind账号或手动下载

请选择:
1. 授权使用模拟数据 (用于测试脚本)
2. 提供替代数据源
3. 更换研究变量/设计
4. 继续 (缺失数据将在后续处理)

依赖项

  • scripts/data_source_checker.py — 数据源预检查
  • scripts/research_framework/data_fetcher.py — 数据获取接口
  • scripts/core/provenance.py — 数据溯源追踪
  • scripts/research_framework/regression_engine.py — 回归引擎

约束

  1. 必须先运行数据源预检查 — 不跳过他
  2. 禁止静默Fallback — 模拟数据必须用户授权
  3. 每个数据操作必须记录溯源 — 包括来源、时间戳、行数
  4. 检查点强制暂停 — 用户确认前不继续
  5. 失败时显示具体原因 — 而非笼统错误

Frequently asked questions

What does the Fin Data Acquisition AI skill do?

根据REFINED_DESIGN.md中的变量定义,自动获取所需数据并生成可执行的回归分析脚本(Python/Stata)。

Why use Fin Data Acquisition on TypingMind?

Because you install it once and use it with any model. Fin Data Acquisition is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Fin Data Acquisition in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/csmar432/finai-research/tree/main/.agents/skills/fin-data-acquisition. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Fin Data Acquisition?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Fin Data Acquisition?

As many as you like. As long as a model supports skills, you can use Fin Data Acquisition with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Fin Data Acquisition AI skill free?

Yes. It is published on GitHub by csmar432 under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇