跳转至

Python API 与公开模块参考(v0.6+)

本文件是 FinAI Research Workflow 稳定公开 Python API 与 CLI 模块的权威参考。

最后更新:2026-12-01(同步 v0.4–v0.6 旗舰引擎、63 个计量方法模块、18 个 AI Skills、36 款宿主接入与 43 个 MCP 服务器)


0. 双轨边界:实证轨 vs 写作轨(严禁混用)

入口 所属轨道 核心职责
finai lab / scripts/research_framework/enhanced_pipeline.py 实证生产轨 调用 6 类因果路由、modern_did、黄金八格、双推断族 $T \to M$ 机制与 19 类稳健性,写出 GOLD_TABLES.md、empirical_package.json、numeric_ledger.json 与 Empirical Lab Studio v2.5
finai audit / scripts/core/empirical_package.py 写稿门控(Stage 6.5) 核验主效应显著性、控制变量职务、机制双推断族与推断地板,阻断不合格结果进入因果声称
finai draft / scripts/agent_pipeline.py 写作轨 大纲 → 文献 → 制图 → \empval{} 零漂移写稿 → 润色(含 HITL 人工门控)
finai review / scripts/core/llm_reviewer.py + adversarial_referee.py 红队审稿与 R&R 轨 econ-review 证据锚定问题台账(Findings Ledger)+ 8 项可执行实证证伪压测 + RRWorkbench 点对点回复信
scripts/research_framework/pipeline.py 轻量设计脚手架 --mode design 生成研究设计模板(非生产级交错 DID 入口)

详见 ARCHITECTURE.md §0。


1. 统一 CLI、多宿主接入与系统治理(v0.5–v0.6)

类 / 函数 / 模块 路径 用途
main (finai CLI) scripts/cli.py 统一命令行入口:init, setup-ide (harness), doctor, lab, studio, audit, novelty, draft, review, pipeline
HARNESS_REGISTRY, install_harness, detect_installed_harnesses scripts/core/ide_harness_setup.py 支持 36 款 IDE(12)、VSCode 扩展(10)、CLI Agent(10)与桌面宿主(4)的 JSON/TOML/YAML 安全合并与 .bak 备份
EmpiricalCatalog, ProxyLaunderingAuditor scripts/core/empirical_catalog.py Layer-0 本地实证面板 Schema 扫描与反代理变量洗白审计
PolicyGrounder scripts/core/policy_grounder.py 准自然实验政策精确生效时点落地与同期混淆政策重叠核查
StructuredNoveltyEngine scripts/core/novelty_engine.py 5-Tuple $(T, Y, I, S, K)$ 双语结构化新颖性评估与 NOVELTY_POSITIONING.md 生成
CausalDAGAuditor, CausalDAG, detect_bad_controls, detect_collider_bias scripts/core/causal_dag_auditor.py 基于 d-separation 后门准则的坏控制与碰撞偏误自动拦截
NumericLedger scripts/core/numeric_provenance.py \empval{} 数值溯源账本与 numeric_macros.tex 导出(配合 scripts/core/manuscript_trace.py 审计零裸写漂移)
CitationVerifier, ClaimCitationAuditor scripts/core/citation_verifier.py & citation_stance.py OpenAlex + CrossRef + Semantic Scholar 3 层反 DOI 劫持、撤稿核查与引文立场审计
build_empirical_explorer_html scripts/core/empirical_explorer_html.py 生成单文件离线交互式工作台 Empirical Lab Studio v2.5(Light/Dark 双主题 + 5 卡 KPI + SVG 悬停探针)
LLMReviewer, ReviewFinding, build_prioritized_fix_plan, render_referee_report_markdown scripts/core/llm_reviewer.py econ-review 证据锚定问题台账(分离 Referee Report 与 Editing Comments)及 P0/P1/P2 修复计划
AdversarialRefereeAgent, FalsificationExecutor scripts/core/adversarial_referee.py 可执行对抗性审稿人 #2(8 项实证证伪压测)
RRWorkbench, write_rr_bundle scripts/core/rr_workbench.py 点对点 R&R 审稿回复信工作台(Markdown + LaTeX)
generate_aea_readme scripts/core/replication_package.py AEA Data Editor 标准复现包 README.md 与 SHA-256 清单生成

2. 选题澄清与多智能体编排

类 / 模块 路径 用途
ProgressiveClarifier, ResearchProfile scripts/core/progressive_clarifier.py 5 轮渐进式主题澄清与研究画像锁定
AgentOrchestrator, HITLGate scripts/core/orchestrator.py & hitl_gate.py 固定多阶段论文写作流水线与人工门控(approve / reject & resume)
ParallelAnalystOrchestrator scripts/core/analyst_agents.py 6 分析师并行机构级金融研报编排
MultiAgentOrchestrator scripts/core/multi_agent.py 基于能力匹配的通用异步多智能体路由

3. 因果识别与计量方法库(63 个方法模块)

scripts/research_framework/ 当前共包含 63 个计量与实证模块,其中 61 个模块(96.83%)配备独立单元测试(由 python scripts/count_assets.py 实时核验)。

类 模块路径 用途
CausalMethodRouter, CausalEstimateContract scripts/research_framework/causal_router.py 6 类核心因果识别自动路由(DID / IV / RDD / SDID / Event Study / GMM)与统一输出契约
DSLEstimator, PPIRegressor, StratifiedAuditSampler scripts/research_framework/dsl_ppi_econometrics.py LLM 文本标注变量统计学去偏推断(Design-based Supervised Learning & PPI++)
EnhancedPipeline scripts/research_framework/enhanced_pipeline.py 生产级实证流水线(黄金八格 gold_tables.py + 机制 + 稳健性 + 实证包导出)
ModernDiDEngine scripts/research_framework/modern_did.py 现代交错 DID(Callaway-Sant'Anna / Sun-Abraham / Borusyak / Goodman-Bacon / dCdH / HonestDiD)
RegressionEngine scripts/research_framework/regression_engine.py 标准双向固定效应 DID / OLS / PSM / 面板回归
PSMDID scripts/research_framework/psm_did.py 倾向得分匹配双重差分与平衡性检验
TripleDiffDIDEngine scripts/research_framework/triple_diff_did.py 三重差分(DDD)估计
LocalProjectionsDIDEngine scripts/research_framework/local_projections_did.py Jordà (2005) 局部投影动态 DID
SyntheticControlEngine scripts/research_framework/synthetic_control.py 合成控制法(Abadie et al. 2010/2015)与安慰剂推断
SyntheticDiDEngine scripts/research_framework/synthetic_did.py 合成双重差分(Arkhangelsky et al. 2021)
IVPanel scripts/research_framework/iv_panel.py 面板 IV/2SLS、Jackknife IV、Arellano-Bond / Blundell-Bond GMM、Fama-MacBeth
RDDEngine scripts/research_framework/rdd.py 精确/模糊断点回归、CCT 最优带宽与操纵检验
InteractiveFixedEffects scripts/research_framework/interactive_fixed_effects.py Bai (2009) 交互固定效应与 Pesaran CCE
PanelThresholdRegression scripts/research_framework/panel_threshold_regression.py Hansen (2000) 面板门槛回归与 Bootstrap 推断
PanelQuantileRegression scripts/research_framework/panel_quantile_regression.py Canay (2011) 面板分位数回归与 QTE
SpatialRegressionEngine scripts/research_framework/spatial_regression.py 空间计量 SAR / SEM / SDM / SLX
RobustnessRunner scripts/research_framework/robustness_runner.py 19 类自动化稳健性与安慰剂检验
PanelVAR scripts/research_framework/panel_var.py 面板 VAR、脉冲响应(IRF)与方差分解
DiscreteChoiceModel scripts/research_framework/discrete_choice.py Logit / Probit / Ordered / 负二项回归
GARCHModel, TVPVAR, DCCGARCH volatility_models.py & time_varying_models.py GARCH 族、HAR-RV、TVP-VAR 与动态条件相关
CoxPHModel scripts/research_framework/survival_analysis.py Cox 比例风险、Kaplan-Meier 与 Fine-Gray 竞争风险
CausalForest, DoubleML scripts/research_framework/causal_ml.py 因果森林、双重机器学习(DML)与异质处理效应
PanelCointegrationTest scripts/research_framework/panel_cointegration.py Pedroni / Kao / Westerlund 面板协整与 ECM
VuongTest, OaxacaBlinderDecomposition, KOBDecomposition scripts/research_framework/vuong_kob.py 非嵌套模型选择与 Oaxaca-Blinder / Kitagawa 分解
GreenBondFactorModel, IVSurfaceBuilder green_bond_model.py & options_iv_surface.py 绿色债券溢价分解与期权隐含波动率曲面

4. 顶刊出版样式、图表与模板系统

模块 / 函数 路径 用途
get_journal_preset, journal_style_context scripts/research_framework/pub_styles.py aer / jingji_yanjiu / jf / grayscale 灰度安全样式与对比度校核
plot_event_study_pub, plot_placebo_dual_axis, plot_bacon_decomposition, plot_sensitivity_bounds, plot_heterogeneity_forest_pub, plot_grouped_event_study, plot_spec_curve scripts/research_framework/empirical_figures.py 7 大顶刊出版级实证图生成器(≥300 DPI PDF/SVG/PNG)
FinancialChartFactory scripts/research_framework/fin_charts.py 20+ 种金融与统计图表工厂
ReportGenerator scripts/research_framework/report_generator.py LaTeX / Word 双格式文稿生成(集成 NumericLedger)
JournalTemplate, get_all_templates scripts/journal_template.py 30 种中英日德期刊 LaTeX 模板

5. 全部 18 个 AI 研究技能(5 路目录零漂移同步)

通过 python scripts/sync_skills.py --check 保证 knowledge/skills/、.claude/skills/、.github/skills/、.cursor/skills/ 与 .agents/skills/ 完全一致:

Skill 功能
fin-full-pipeline 端到端研究闭环编排(含隔离槽位协议)
fin-idea-discovery 研究想法发现 + 数据前置可行性核验
fin-lit-review 多源系统性文献综述
fin-generate-idea 8–12 个可证伪排序想法
fin-novelty-check 5-Tuple $(T,Y,I,S,K)$ 结构化新颖性与定位矩阵
fin-experiment-design 6 类因果路由 + DAG 审计 + DSL/PPI++ 去偏设计
fin-data-acquisition 本地实证库优先 + 反代理洗白 + 政策重叠核查 + 43 MCP
fin-paper-writing 多章节论文写作编排与语言质量门控
fin-paper-draft \empval{} 零漂移正文生成 + 3 层反 DOI 劫持 + AEA 复现包
fin-paper-plan 30 种顶刊结构化大纲与段落质量门槛
fin-paper-figure 灰度安全出版图表(≥300 DPI)+ Empirical Lab Studio v2.5
fin-paper-convert LaTeX 编译与多格式导出
fin-review-loop econ-review Findings Ledger + 可执行红队审稿 #2 + R&R 工作台
fin-submit-check 投稿前自动化门禁与十大检查清单
fin-brief-generator 生成 FIN_BRIEF.md
fin-ref-paper BibTeX 参考文献管理
fin-viz-launch 自然语言 → 学术统计图表
fin-arch-diagram 研究/系统架构图、流程图与 CONSORT 树图(graphviz / matplotlib 双后端)

6. MCP 数据源(43 个服务器目录)

  • 总计 43 个目录:28 个免 Key 免费 · 12 个需 API Key · 3 个 opt-in 法律风险源默认禁用(详见 MCP_SERVER_TIERING.md 与 MOCK_DATA_POLICY.md)。
  • 一键导入任意 IDE:finai setup-ide --target all --profile academic --apply 或 python scripts/register_mcp_servers.py --list。