aigroup-econ-mcp 1.3.3__py3-none-any.whl → 2.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. .gitignore +253 -0
  2. PKG-INFO +732 -0
  3. README.md +687 -0
  4. __init__.py +14 -0
  5. aigroup_econ_mcp-2.0.1.dist-info/METADATA +732 -0
  6. aigroup_econ_mcp-2.0.1.dist-info/RECORD +170 -0
  7. aigroup_econ_mcp-2.0.1.dist-info/entry_points.txt +2 -0
  8. aigroup_econ_mcp-2.0.1.dist-info/licenses/LICENSE +21 -0
  9. cli.py +32 -0
  10. econometrics/README.md +18 -0
  11. econometrics/__init__.py +191 -0
  12. econometrics/advanced_methods/modern_computing_machine_learning/__init__.py +30 -0
  13. econometrics/advanced_methods/modern_computing_machine_learning/causal_forest.py +253 -0
  14. econometrics/advanced_methods/modern_computing_machine_learning/double_ml.py +268 -0
  15. econometrics/advanced_methods/modern_computing_machine_learning/gradient_boosting.py +249 -0
  16. econometrics/advanced_methods/modern_computing_machine_learning/hierarchical_clustering.py +243 -0
  17. econometrics/advanced_methods/modern_computing_machine_learning/kmeans_clustering.py +293 -0
  18. econometrics/advanced_methods/modern_computing_machine_learning/neural_network.py +264 -0
  19. econometrics/advanced_methods/modern_computing_machine_learning/random_forest.py +195 -0
  20. econometrics/advanced_methods/modern_computing_machine_learning/support_vector_machine.py +226 -0
  21. econometrics/advanced_methods/modern_computing_machine_learning/test_all_modules.py +329 -0
  22. econometrics/advanced_methods/modern_computing_machine_learning/test_report.md +107 -0
  23. econometrics/basic_parametric_estimation/__init__.py +31 -0
  24. econometrics/basic_parametric_estimation/gmm/__init__.py +13 -0
  25. econometrics/basic_parametric_estimation/gmm/gmm_model.py +256 -0
  26. econometrics/basic_parametric_estimation/mle/__init__.py +13 -0
  27. econometrics/basic_parametric_estimation/mle/mle_model.py +241 -0
  28. econometrics/basic_parametric_estimation/ols/__init__.py +13 -0
  29. econometrics/basic_parametric_estimation/ols/ols_model.py +141 -0
  30. econometrics/causal_inference/__init__.py +66 -0
  31. econometrics/causal_inference/causal_identification_strategy/__init__.py +104 -0
  32. econometrics/causal_inference/causal_identification_strategy/control_function.py +112 -0
  33. econometrics/causal_inference/causal_identification_strategy/difference_in_differences.py +107 -0
  34. econometrics/causal_inference/causal_identification_strategy/event_study.py +119 -0
  35. econometrics/causal_inference/causal_identification_strategy/first_difference.py +89 -0
  36. econometrics/causal_inference/causal_identification_strategy/fixed_effects.py +103 -0
  37. econometrics/causal_inference/causal_identification_strategy/hausman_test.py +69 -0
  38. econometrics/causal_inference/causal_identification_strategy/instrumental_variables.py +145 -0
  39. econometrics/causal_inference/causal_identification_strategy/mediation_analysis.py +121 -0
  40. econometrics/causal_inference/causal_identification_strategy/moderation_analysis.py +109 -0
  41. econometrics/causal_inference/causal_identification_strategy/propensity_score_matching.py +140 -0
  42. econometrics/causal_inference/causal_identification_strategy/random_effects.py +100 -0
  43. econometrics/causal_inference/causal_identification_strategy/regression_discontinuity.py +98 -0
  44. econometrics/causal_inference/causal_identification_strategy/synthetic_control.py +111 -0
  45. econometrics/causal_inference/causal_identification_strategy/triple_difference.py +86 -0
  46. econometrics/distribution_analysis/__init__.py +28 -0
  47. econometrics/distribution_analysis/oaxaca_blinder.py +184 -0
  48. econometrics/distribution_analysis/time_series_decomposition.py +152 -0
  49. econometrics/distribution_analysis/variance_decomposition.py +179 -0
  50. econometrics/missing_data/__init__.py +18 -0
  51. econometrics/missing_data/imputation_methods.py +219 -0
  52. econometrics/missing_data/missing_data_measurement_error/__init__.py +0 -0
  53. econometrics/model_specification_diagnostics_robust_inference/README.md +173 -0
  54. econometrics/model_specification_diagnostics_robust_inference/__init__.py +78 -0
  55. econometrics/model_specification_diagnostics_robust_inference/diagnostic_tests/__init__.py +20 -0
  56. econometrics/model_specification_diagnostics_robust_inference/diagnostic_tests/diagnostic_tests_model.py +149 -0
  57. econometrics/model_specification_diagnostics_robust_inference/generalized_least_squares/__init__.py +15 -0
  58. econometrics/model_specification_diagnostics_robust_inference/generalized_least_squares/gls_model.py +130 -0
  59. econometrics/model_specification_diagnostics_robust_inference/model_selection/__init__.py +18 -0
  60. econometrics/model_specification_diagnostics_robust_inference/model_selection/model_selection_model.py +286 -0
  61. econometrics/model_specification_diagnostics_robust_inference/regularization/__init__.py +15 -0
  62. econometrics/model_specification_diagnostics_robust_inference/regularization/regularization_model.py +177 -0
  63. econometrics/model_specification_diagnostics_robust_inference/robust_errors/__init__.py +15 -0
  64. econometrics/model_specification_diagnostics_robust_inference/robust_errors/robust_errors_model.py +122 -0
  65. econometrics/model_specification_diagnostics_robust_inference/simultaneous_equations/__init__.py +15 -0
  66. econometrics/model_specification_diagnostics_robust_inference/simultaneous_equations/simultaneous_equations_model.py +246 -0
  67. econometrics/model_specification_diagnostics_robust_inference/weighted_least_squares/__init__.py +15 -0
  68. econometrics/model_specification_diagnostics_robust_inference/weighted_least_squares/wls_model.py +127 -0
  69. econometrics/nonparametric/__init__.py +35 -0
  70. econometrics/nonparametric/gam_model.py +117 -0
  71. econometrics/nonparametric/kernel_regression.py +161 -0
  72. econometrics/nonparametric/nonparametric_semiparametric_methods/__init__.py +0 -0
  73. econometrics/nonparametric/quantile_regression.py +249 -0
  74. econometrics/nonparametric/spline_regression.py +100 -0
  75. econometrics/spatial_econometrics/__init__.py +68 -0
  76. econometrics/spatial_econometrics/geographically_weighted_regression.py +211 -0
  77. econometrics/spatial_econometrics/gwr_simple.py +154 -0
  78. econometrics/spatial_econometrics/spatial_autocorrelation.py +356 -0
  79. econometrics/spatial_econometrics/spatial_durbin_model.py +177 -0
  80. econometrics/spatial_econometrics/spatial_econometrics_new/__init__.py +0 -0
  81. econometrics/spatial_econometrics/spatial_regression.py +315 -0
  82. econometrics/spatial_econometrics/spatial_weights.py +226 -0
  83. econometrics/specific_data_modeling/micro_discrete_limited_data/README.md +164 -0
  84. econometrics/specific_data_modeling/micro_discrete_limited_data/__init__.py +40 -0
  85. econometrics/specific_data_modeling/micro_discrete_limited_data/count_data_models.py +311 -0
  86. econometrics/specific_data_modeling/micro_discrete_limited_data/discrete_choice_models.py +294 -0
  87. econometrics/specific_data_modeling/micro_discrete_limited_data/limited_dependent_variable_models.py +282 -0
  88. econometrics/specific_data_modeling/survival_duration_data/__init__.py +0 -0
  89. econometrics/specific_data_modeling/time_series_panel_data/__init__.py +143 -0
  90. econometrics/specific_data_modeling/time_series_panel_data/arima_model.py +104 -0
  91. econometrics/specific_data_modeling/time_series_panel_data/cointegration_vecm.py +334 -0
  92. econometrics/specific_data_modeling/time_series_panel_data/dynamic_panel_models.py +653 -0
  93. econometrics/specific_data_modeling/time_series_panel_data/exponential_smoothing.py +176 -0
  94. econometrics/specific_data_modeling/time_series_panel_data/garch_model.py +198 -0
  95. econometrics/specific_data_modeling/time_series_panel_data/panel_diagnostics.py +125 -0
  96. econometrics/specific_data_modeling/time_series_panel_data/panel_var.py +60 -0
  97. econometrics/specific_data_modeling/time_series_panel_data/structural_break_tests.py +87 -0
  98. econometrics/specific_data_modeling/time_series_panel_data/time_varying_parameter_models.py +106 -0
  99. econometrics/specific_data_modeling/time_series_panel_data/unit_root_tests.py +204 -0
  100. econometrics/specific_data_modeling/time_series_panel_data/var_svar_model.py +372 -0
  101. econometrics/statistical_inference/__init__.py +21 -0
  102. econometrics/statistical_inference/bootstrap_methods.py +162 -0
  103. econometrics/statistical_inference/permutation_test.py +177 -0
  104. econometrics/statistical_inference/statistical_inference_techniques/__init__.py +0 -0
  105. econometrics/statistics/distribution_decomposition_methods/__init__.py +0 -0
  106. econometrics/survival_analysis/__init__.py +18 -0
  107. econometrics/survival_analysis/survival_models.py +259 -0
  108. econometrics/tests/basic_parametric_estimation_tests/__init__.py +3 -0
  109. econometrics/tests/basic_parametric_estimation_tests/test_gmm.py +128 -0
  110. econometrics/tests/basic_parametric_estimation_tests/test_mle.py +127 -0
  111. econometrics/tests/basic_parametric_estimation_tests/test_ols.py +100 -0
  112. econometrics/tests/causal_inference_tests/__init__.py +3 -0
  113. econometrics/tests/causal_inference_tests/detailed_test.py +441 -0
  114. econometrics/tests/causal_inference_tests/test_all_methods.py +418 -0
  115. econometrics/tests/causal_inference_tests/test_causal_identification_strategy.py +202 -0
  116. econometrics/tests/causal_inference_tests/test_difference_in_differences.py +53 -0
  117. econometrics/tests/causal_inference_tests/test_instrumental_variables.py +44 -0
  118. econometrics/tests/model_specification_diagnostics_tests/__init__.py +3 -0
  119. econometrics/tests/model_specification_diagnostics_tests/test_diagnostic_tests.py +86 -0
  120. econometrics/tests/model_specification_diagnostics_tests/test_robust_errors.py +89 -0
  121. econometrics/tests/specific_data_modeling_tests/__init__.py +3 -0
  122. econometrics/tests/specific_data_modeling_tests/test_arima.py +98 -0
  123. econometrics/tests/specific_data_modeling_tests/test_dynamic_panel.py +198 -0
  124. econometrics/tests/specific_data_modeling_tests/test_exponential_smoothing.py +105 -0
  125. econometrics/tests/specific_data_modeling_tests/test_garch.py +118 -0
  126. econometrics/tests/specific_data_modeling_tests/test_micro_discrete_limited_data.py +189 -0
  127. econometrics/tests/specific_data_modeling_tests/test_unit_root.py +156 -0
  128. econometrics/tests/specific_data_modeling_tests/test_var.py +124 -0
  129. econometrics//321/206/320/254/320/272/321/205/342/225/235/320/220/321/205/320/237/320/241/321/205/320/264/320/267/321/207/342/226/222/342/225/227/321/204/342/225/235/320/250/321/205/320/225/320/230/321/207/342/225/221/320/267/321/205/320/230/320/226/321/206/320/256/320/240.md +544 -0
  130. prompts/__init__.py +0 -0
  131. prompts/analysis_guides.py +43 -0
  132. pyproject.toml +85 -0
  133. resources/MCP_MASTER_GUIDE.md +422 -0
  134. resources/MCP_TOOLS_DATA_FORMAT_GUIDE.md +185 -0
  135. resources/__init__.py +0 -0
  136. server.py +97 -0
  137. tools/README.md +88 -0
  138. tools/__init__.py +119 -0
  139. tools/causal_inference_adapter.py +658 -0
  140. tools/data_loader.py +213 -0
  141. tools/decorators.py +38 -0
  142. tools/distribution_analysis_adapter.py +121 -0
  143. tools/econometrics_adapter.py +286 -0
  144. tools/gwr_simple_adapter.py +54 -0
  145. tools/machine_learning_adapter.py +567 -0
  146. tools/mcp_tool_groups/__init__.py +15 -0
  147. tools/mcp_tool_groups/basic_parametric_tools.py +173 -0
  148. tools/mcp_tool_groups/causal_inference_tools.py +643 -0
  149. tools/mcp_tool_groups/distribution_analysis_tools.py +169 -0
  150. tools/mcp_tool_groups/machine_learning_tools.py +422 -0
  151. tools/mcp_tool_groups/microecon_tools.py +325 -0
  152. tools/mcp_tool_groups/missing_data_tools.py +117 -0
  153. tools/mcp_tool_groups/model_specification_tools.py +402 -0
  154. tools/mcp_tool_groups/nonparametric_tools.py +225 -0
  155. tools/mcp_tool_groups/spatial_econometrics_tools.py +323 -0
  156. tools/mcp_tool_groups/statistical_inference_tools.py +131 -0
  157. tools/mcp_tool_groups/time_series_tools.py +494 -0
  158. tools/mcp_tools_registry.py +124 -0
  159. tools/microecon_adapter.py +412 -0
  160. tools/missing_data_adapter.py +73 -0
  161. tools/model_specification_adapter.py +369 -0
  162. tools/nonparametric_adapter.py +190 -0
  163. tools/output_formatter.py +563 -0
  164. tools/spatial_econometrics_adapter.py +318 -0
  165. tools/statistical_inference_adapter.py +90 -0
  166. tools/survival_analysis_adapter.py +46 -0
  167. tools/time_series_panel_data_adapter.py +858 -0
  168. tools/time_series_panel_data_tools.py +65 -0
  169. aigroup_econ_mcp/__init__.py +0 -19
  170. aigroup_econ_mcp/cli.py +0 -82
  171. aigroup_econ_mcp/config.py +0 -561
  172. aigroup_econ_mcp/server.py +0 -452
  173. aigroup_econ_mcp/tools/__init__.py +0 -19
  174. aigroup_econ_mcp/tools/base.py +0 -470
  175. aigroup_econ_mcp/tools/cache.py +0 -533
  176. aigroup_econ_mcp/tools/data_loader.py +0 -195
  177. aigroup_econ_mcp/tools/file_parser.py +0 -1027
  178. aigroup_econ_mcp/tools/machine_learning.py +0 -60
  179. aigroup_econ_mcp/tools/ml_ensemble.py +0 -210
  180. aigroup_econ_mcp/tools/ml_evaluation.py +0 -272
  181. aigroup_econ_mcp/tools/ml_models.py +0 -54
  182. aigroup_econ_mcp/tools/ml_regularization.py +0 -186
  183. aigroup_econ_mcp/tools/monitoring.py +0 -555
  184. aigroup_econ_mcp/tools/optimized_example.py +0 -229
  185. aigroup_econ_mcp/tools/panel_data.py +0 -619
  186. aigroup_econ_mcp/tools/regression.py +0 -214
  187. aigroup_econ_mcp/tools/statistics.py +0 -154
  188. aigroup_econ_mcp/tools/time_series.py +0 -698
  189. aigroup_econ_mcp/tools/timeout.py +0 -283
  190. aigroup_econ_mcp/tools/tool_descriptions.py +0 -410
  191. aigroup_econ_mcp/tools/tool_handlers.py +0 -1016
  192. aigroup_econ_mcp/tools/tool_registry.py +0 -478
  193. aigroup_econ_mcp/tools/validation.py +0 -482
  194. aigroup_econ_mcp-1.3.3.dist-info/METADATA +0 -525
  195. aigroup_econ_mcp-1.3.3.dist-info/RECORD +0 -30
  196. aigroup_econ_mcp-1.3.3.dist-info/entry_points.txt +0 -2
  197. /aigroup_econ_mcp-1.3.3.dist-info/licenses/LICENSE → /LICENSE +0 -0
  198. {aigroup_econ_mcp-1.3.3.dist-info → aigroup_econ_mcp-2.0.1.dist-info}/WHEEL +0 -0
@@ -0,0 +1,563 @@
1
+ """
2
+ 输出格式化组件 - 支持Markdown和TXT格式
3
+ """
4
+
5
+ from typing import Any, Dict, List
6
+ from datetime import datetime
7
+ from pathlib import Path
8
+
9
+
10
+ class OutputFormatter:
11
+ """输出格式化器基类"""
12
+
13
+ @staticmethod
14
+ def format_ols_result(result: Any, format_type: str = "markdown") -> str:
15
+ """格式化OLS结果"""
16
+ if format_type.lower() == "markdown":
17
+ return MarkdownFormatter.format_ols(result)
18
+ else:
19
+ return TextFormatter.format_ols(result)
20
+
21
+ @staticmethod
22
+ def format_mle_result(result: Any, format_type: str = "markdown") -> str:
23
+ """格式化MLE结果"""
24
+ if format_type.lower() == "markdown":
25
+ return MarkdownFormatter.format_mle(result)
26
+ else:
27
+ return TextFormatter.format_mle(result)
28
+
29
+ @staticmethod
30
+ def format_gmm_result(result: Any, format_type: str = "markdown") -> str:
31
+ """格式化GMM结果"""
32
+ if format_type.lower() == "markdown":
33
+ return MarkdownFormatter.format_gmm(result)
34
+ else:
35
+ return TextFormatter.format_gmm(result)
36
+
37
+ @staticmethod
38
+ def format_arima_result(result: Any, format_type: str = "markdown") -> str:
39
+ """格式化ARIMA结果"""
40
+ if format_type.lower() == "markdown":
41
+ return MarkdownFormatter.format_arima(result)
42
+ else:
43
+ return TextFormatter.format_arima(result)
44
+
45
+ @staticmethod
46
+ def format_exponential_smoothing_result(result: Any, format_type: str = "markdown") -> str:
47
+ """格式化指数平滑结果"""
48
+ if format_type.lower() == "markdown":
49
+ return MarkdownFormatter.format_exp_smoothing(result)
50
+ else:
51
+ return TextFormatter.format_exp_smoothing(result)
52
+
53
+ @staticmethod
54
+ def format_garch_result(result: Any, format_type: str = "markdown") -> str:
55
+ """格式化GARCH结果"""
56
+ if format_type.lower() == "markdown":
57
+ return MarkdownFormatter.format_garch(result)
58
+ else:
59
+ return TextFormatter.format_garch(result)
60
+
61
+ @staticmethod
62
+ def format_unit_root_test_result(result: Any, format_type: str = "markdown") -> str:
63
+ """格式化单位根检验结果"""
64
+ if format_type.lower() == "markdown":
65
+ return MarkdownFormatter.format_unit_root(result)
66
+ else:
67
+ return TextFormatter.format_unit_root(result)
68
+
69
+ @staticmethod
70
+ def format_var_result(result: Any, format_type: str = "markdown") -> str:
71
+ """格式化VAR/SVAR结果"""
72
+ if format_type.lower() == "markdown":
73
+ return MarkdownFormatter.format_var(result)
74
+ else:
75
+ return TextFormatter.format_var(result)
76
+
77
+ @staticmethod
78
+ def format_cointegration_result(result: Any, format_type: str = "markdown") -> str:
79
+ """格式化协整检验结果"""
80
+ if format_type.lower() == "markdown":
81
+ return MarkdownFormatter.format_cointegration(result)
82
+ else:
83
+ return TextFormatter.format_cointegration(result)
84
+
85
+ @staticmethod
86
+ def format_vecm_result(result: Any, format_type: str = "markdown") -> str:
87
+ """格式化VECM结果"""
88
+ if format_type.lower() == "markdown":
89
+ return MarkdownFormatter.format_vecm(result)
90
+ else:
91
+ return TextFormatter.format_vecm(result)
92
+
93
+ @staticmethod
94
+ def format_dynamic_panel_result(result: Any, format_type: str = "markdown") -> str:
95
+ """格式化动态面板模型结果"""
96
+ if format_type.lower() == "markdown":
97
+ return MarkdownFormatter.format_dynamic_panel(result)
98
+ else:
99
+ return TextFormatter.format_dynamic_panel(result)
100
+
101
+ @staticmethod
102
+ def save_to_file(content: str, file_path: str) -> str:
103
+ """保存内容到文件"""
104
+ path = Path(file_path)
105
+ path.parent.mkdir(parents=True, exist_ok=True)
106
+
107
+ with open(path, 'w', encoding='utf-8') as f:
108
+ f.write(content)
109
+
110
+ return f"结果已保存到: {file_path}"
111
+
112
+
113
+ class MarkdownFormatter:
114
+ """Markdown格式化器"""
115
+
116
+ @staticmethod
117
+ def format_ols(result: Any) -> str:
118
+ """格式化OLS结果为Markdown"""
119
+ timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
120
+
121
+ md = f"""# OLS回归分析结果
122
+
123
+ **生成时间**: {timestamp}
124
+
125
+ ## 模型概览
126
+
127
+ - **观测数量**: {result.n_obs}
128
+ - **R²**: {result.r_squared:.4f}
129
+ - **调整R²**: {result.adj_r_squared:.4f}
130
+ - **F统计量**: {result.f_statistic:.4f}
131
+ - **F检验p值**: {result.f_p_value:.4f}
132
+
133
+ ## 系数估计
134
+
135
+ | 变量 | 系数 | 标准误 | t值 | p值 | 95%置信区间下限 | 95%置信区间上限 |
136
+ |------|------|--------|-----|-----|----------------|----------------|
137
+ """
138
+
139
+ for i, name in enumerate(result.feature_names):
140
+ md += f"| {name} | {result.coefficients[i]:.6f} | {result.std_errors[i]:.6f} | "
141
+ md += f"{result.t_values[i]:.4f} | {result.p_values[i]:.4f} | "
142
+ md += f"{result.conf_int_lower[i]:.6f} | {result.conf_int_upper[i]:.6f} |\n"
143
+
144
+ md += "\n## 解释\n\n"
145
+ md += f"- 模型的拟合优度R²为 {result.r_squared:.4f},"
146
+ md += f"表示模型解释了因变量 {result.r_squared*100:.2f}% 的变异。\n"
147
+ md += f"- F统计量为 {result.f_statistic:.4f},p值为 {result.f_p_value:.4f},"
148
+ md += "模型整体显著。\n" if result.f_p_value < 0.05 else "模型整体不显著。\n"
149
+
150
+ return md
151
+
152
+ @staticmethod
153
+ def format_mle(result: Any) -> str:
154
+ """格式化MLE结果为Markdown"""
155
+ timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
156
+
157
+ md = f"""# 最大似然估计(MLE)结果
158
+
159
+ **生成时间**: {timestamp}
160
+
161
+ ## 模型信息
162
+
163
+ - **观测数量**: {result.n_obs}
164
+ - **对数似然值**: {result.log_likelihood:.4f}
165
+ - **AIC**: {result.aic:.4f}
166
+ - **BIC**: {result.bic:.4f}
167
+ - **收敛状态**: {'已收敛' if result.convergence else '未收敛'}
168
+
169
+ ## 参数估计
170
+
171
+ | 参数 | 估计值 | 标准误 | 95%置信区间下限 | 95%置信区间上限 |
172
+ |------|--------|--------|----------------|----------------|
173
+ """
174
+
175
+ for i, name in enumerate(result.param_names):
176
+ md += f"| {name} | {result.parameters[i]:.6f} | {result.std_errors[i]:.6f} | "
177
+ md += f"{result.conf_int_lower[i]:.6f} | {result.conf_int_upper[i]:.6f} |\n"
178
+
179
+ md += "\n## 模型选择\n\n"
180
+ md += f"- AIC (赤池信息准则): {result.aic:.4f} - 越小越好\n"
181
+ md += f"- BIC (贝叶斯信息准则): {result.bic:.4f} - 越小越好\n"
182
+
183
+ return md
184
+
185
+ @staticmethod
186
+ def format_gmm(result: Any) -> str:
187
+ """格式化GMM结果为Markdown"""
188
+ timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
189
+
190
+ md = f"""# 广义矩估计(GMM)结果
191
+
192
+ **生成时间**: {timestamp}
193
+
194
+ ## 模型信息
195
+
196
+ - **观测数量**: {result.n_obs}
197
+ - **矩条件数量**: {result.n_moments}
198
+ - **J统计量**: {result.j_statistic:.4f}
199
+ - **J检验p值**: {result.j_p_value:.4f}
200
+
201
+ ## 系数估计
202
+
203
+ | 变量 | 系数 | 标准误 | t值 | p值 | 95%置信区间下限 | 95%置信区间上限 |
204
+ |------|------|--------|-----|-----|----------------|----------------|
205
+ """
206
+
207
+ for i, name in enumerate(result.feature_names):
208
+ md += f"| {name} | {result.coefficients[i]:.6f} | {result.std_errors[i]:.6f} | "
209
+ md += f"{result.t_values[i]:.4f} | {result.p_values[i]:.4f} | "
210
+ md += f"{result.conf_int_lower[i]:.6f} | {result.conf_int_upper[i]:.6f} |\n"
211
+
212
+ md += "\n## 过度识别检验\n\n"
213
+ if result.j_p_value < 0.05:
214
+ md += f"- J统计量为 {result.j_statistic:.4f},p值为 {result.j_p_value:.4f}\n"
215
+ md += "- **警告**: 拒绝过度识别限制的原假设,模型可能存在设定偏误\n"
216
+ else:
217
+ md += f"- J统计量为 {result.j_statistic:.4f},p值为 {result.j_p_value:.4f}\n"
218
+ md += "- 不能拒绝过度识别限制的原假设,工具变量有效\n"
219
+
220
+ return md
221
+
222
+ @staticmethod
223
+ def format_arima(result: Any) -> str:
224
+ """格式化ARIMA结果为Markdown"""
225
+ timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
226
+
227
+ md = f"""# ARIMA模型分析结果
228
+
229
+ **生成时间**: {timestamp}
230
+
231
+ ## 模型信息
232
+
233
+ - **模型类型**: {result.model_type}
234
+ - **观测数量**: {result.n_obs}
235
+ - **AIC**: {result.aic:.4f}
236
+ - **BIC**: {result.bic:.4f}
237
+ - **HQIC**: {result.hqic:.4f}
238
+
239
+ ## 参数估计
240
+
241
+ | 参数 | 系数 | 标准误 | t值 | p值 | 95%置信区间下限 | 95%置信区间上限 |
242
+ |------|------|--------|-----|-----|----------------|----------------|
243
+ """
244
+
245
+ for i in range(len(result.coefficients)):
246
+ md += f"| 参数{i+1} | {result.coefficients[i]:.6f} | "
247
+ md += f"{result.std_errors[i] if result.std_errors else 0:.6f} | "
248
+ md += f"{result.t_values[i] if result.t_values else 0:.4f} | "
249
+ md += f"{result.p_values[i] if result.p_values else 0:.4f} | "
250
+ md += f"{result.conf_int_lower[i] if result.conf_int_lower else 0:.6f} | "
251
+ md += f"{result.conf_int_upper[i] if result.conf_int_upper else 0:.6f} |\n"
252
+
253
+ if hasattr(result, 'forecast') and result.forecast:
254
+ md += "\n## 预测值\n\n| 步骤 | 预测值 |\n|------|--------|\n"
255
+ for i, val in enumerate(result.forecast):
256
+ md += f"| {i+1} | {val:.4f} |\n"
257
+
258
+ return md
259
+
260
+ @staticmethod
261
+ def format_exp_smoothing(result: Any) -> str:
262
+ """格式化指数平滑结果为Markdown"""
263
+ timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
264
+
265
+ md = f"""# 指数平滑模型分析结果
266
+
267
+ **生成时间**: {timestamp}
268
+
269
+ ## 模型信息
270
+
271
+ - **模型类型**: {result.model_type}
272
+ - **观测数量**: {result.n_obs}
273
+ """
274
+
275
+ if result.smoothing_level is not None:
276
+ md += f"- **水平平滑参数**: {result.smoothing_level:.4f}\n"
277
+ if result.smoothing_trend is not None:
278
+ md += f"- **趋势平滑参数**: {result.smoothing_trend:.4f}\n"
279
+ if result.smoothing_seasonal is not None:
280
+ md += f"- **季节平滑参数**: {result.smoothing_seasonal:.4f}\n"
281
+
282
+ md += "\n## 模型统计\n\n"
283
+ if result.aic is not None:
284
+ md += f"- **AIC**: {result.aic:.4f}\n"
285
+ if result.bic is not None:
286
+ md += f"- **BIC**: {result.bic:.4f}\n"
287
+ if result.sse is not None:
288
+ md += f"- **SSE**: {result.sse:.4f}\n"
289
+ if result.mse is not None:
290
+ md += f"- **MSE**: {result.mse:.4f}\n"
291
+ if result.rmse is not None:
292
+ md += f"- **RMSE**: {result.rmse:.4f}\n"
293
+ if result.mae is not None:
294
+ md += f"- **MAE**: {result.mae:.4f}\n"
295
+
296
+ if hasattr(result, 'forecast') and result.forecast:
297
+ md += "\n## 预测值\n\n| 步骤 | 预测值 |\n|------|--------|\n"
298
+ for i, val in enumerate(result.forecast):
299
+ md += f"| {i+1} | {val:.4f} |\n"
300
+
301
+ return md
302
+
303
+ @staticmethod
304
+ def format_garch(result: Any) -> str:
305
+ """格式化GARCH结果为Markdown"""
306
+ timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
307
+
308
+ md = f"""# GARCH模型分析结果
309
+
310
+ **生成时间**: {timestamp}
311
+
312
+ ## 模型信息
313
+
314
+ - **模型类型**: {result.model_type}
315
+ - **观测数量**: {result.n_obs}
316
+ - **对数似然值**: {result.log_likelihood:.4f}
317
+ - **AIC**: {result.aic:.4f}
318
+ - **BIC**: {result.bic:.4f}
319
+
320
+ ## 参数估计
321
+
322
+ | 参数 | 系数 | 标准误 | t值 | p值 |
323
+ |------|------|--------|-----|-----|
324
+ """
325
+
326
+ for i in range(len(result.coefficients)):
327
+ md += f"| 参数{i+1} | {result.coefficients[i]:.6f} | "
328
+ md += f"{result.std_errors[i] if result.std_errors else 0:.6f} | "
329
+ md += f"{result.t_values[i] if result.t_values else 0:.4f} | "
330
+ md += f"{result.p_values[i] if result.p_values else 0:.4f} |\n"
331
+
332
+ if result.persistence is not None:
333
+ md += f"\n## 波动率持续性\n\n- **持续性参数**: {result.persistence:.4f}\n"
334
+
335
+ if hasattr(result, 'volatility') and result.volatility:
336
+ md += f"\n## 波动率统计\n\n"
337
+ md += f"- **平均波动率**: {sum(result.volatility)/len(result.volatility):.6f}\n"
338
+ md += f"- **最大波动率**: {max(result.volatility):.6f}\n"
339
+ md += f"- **最小波动率**: {min(result.volatility):.6f}\n"
340
+
341
+ return md
342
+
343
+ @staticmethod
344
+ def format_unit_root(result: Any) -> str:
345
+ """格式化单位根检验结果为Markdown"""
346
+ timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
347
+
348
+ md = f"""# 单位根检验结果
349
+
350
+ **生成时间**: {timestamp}
351
+
352
+ ## 检验信息
353
+
354
+ - **检验类型**: {result.test_type}
355
+ - **观测数量**: {result.n_obs}
356
+ - **检验统计量**: {result.test_statistic:.4f}
357
+ - **p值**: {result.p_value:.4f}
358
+ - **是否平稳**: {'是' if result.stationary else '否'}
359
+ """
360
+
361
+ if result.lags is not None:
362
+ md += f"- **滞后阶数**: {result.lags}\n"
363
+
364
+ if result.critical_values:
365
+ md += "\n## 临界值\n\n"
366
+ for key, value in result.critical_values.items():
367
+ md += f"- **{key}**: {value:.4f}\n"
368
+
369
+ md += "\n## 解释\n\n"
370
+ if result.stationary:
371
+ md += "- 序列是平稳的,可以直接进行时间序列分析\n"
372
+ else:
373
+ md += "- 序列是非平稳的,建议进行差分或其他转换\n"
374
+
375
+ return md
376
+
377
+ @staticmethod
378
+ def format_var(result: Any) -> str:
379
+ """格式化VAR/SVAR结果为Markdown"""
380
+ timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
381
+
382
+ md = f"""# {result.model_type}模型分析结果
383
+
384
+ **生成时间**: {timestamp}
385
+
386
+ ## 模型信息
387
+
388
+ - **变量**: {', '.join(result.variables)}
389
+ - **滞后期数**: {result.lags}
390
+ - **观测数量**: {result.n_obs}
391
+
392
+ ## 参数估计
393
+
394
+ | 参数 | 系数 | 标准误 | t值 | p值 |
395
+ |------|------|--------|-----|-----|
396
+ """
397
+
398
+ for i in range(len(result.coefficients)):
399
+ md += f"| 参数{i+1} | {result.coefficients[i]:.6f} | "
400
+ md += f"{result.std_errors[i] if result.std_errors else 0:.6f} | "
401
+ md += f"{result.t_values[i] if result.t_values else 0:.4f} | "
402
+ md += f"{result.p_values[i] if result.p_values else 0:.4f} |\n"
403
+
404
+ md += "\n## 模型统计\n\n"
405
+ if result.aic is not None:
406
+ md += f"- **AIC**: {result.aic:.4f}\n"
407
+ if result.bic is not None:
408
+ md += f"- **BIC**: {result.bic:.4f}\n"
409
+ if result.fpe is not None:
410
+ md += f"- **FPE**: {result.fpe:.4f}\n"
411
+ if result.hqic is not None:
412
+ md += f"- **HQIC**: {result.hqic:.4f}\n"
413
+
414
+ return md
415
+
416
+ @staticmethod
417
+ def format_cointegration(result: Any) -> str:
418
+ """格式化协整检验结果为Markdown"""
419
+ timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
420
+
421
+ md = f"""# 协整检验结果
422
+
423
+ **生成时间**: {timestamp}
424
+
425
+ ## 检验信息
426
+
427
+ - **检验类型**: {result.model_type}
428
+ - **观测数量**: {result.n_obs}
429
+ - **检验统计量**: {result.test_statistic:.4f}
430
+ - **p值**: {result.p_value:.4f}
431
+ """
432
+
433
+ if result.rank is not None:
434
+ md += f"- **协整秩**: {result.rank}\n"
435
+
436
+ if result.critical_values:
437
+ md += "\n## 临界值\n\n"
438
+ for key, value in result.critical_values.items():
439
+ md += f"- **{key}**: {value:.4f}\n"
440
+
441
+ return md
442
+
443
+ @staticmethod
444
+ def format_vecm(result: Any) -> str:
445
+ """格式化VECM结果为Markdown"""
446
+ timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
447
+
448
+ md = f"""# VECM模型分析结果
449
+
450
+ **生成时间**: {timestamp}
451
+
452
+ ## 模型信息
453
+
454
+ - **协整秩**: {result.coint_rank}
455
+ - **观测数量**: {result.n_obs}
456
+
457
+ ## 参数估计
458
+
459
+ | 参数 | 系数 | 标准误 | t值 | p值 |
460
+ |------|------|--------|-----|-----|
461
+ """
462
+
463
+ for i in range(len(result.coefficients)):
464
+ md += f"| 参数{i+1} | {result.coefficients[i]:.6f} | "
465
+ md += f"{result.std_errors[i] if result.std_errors else 0:.6f} | "
466
+ md += f"{result.t_values[i] if result.t_values else 0:.4f} | "
467
+ md += f"{result.p_values[i] if result.p_values else 0:.4f} |\n"
468
+
469
+ md += "\n## 模型统计\n\n"
470
+ if result.log_likelihood is not None:
471
+ md += f"- **对数似然值**: {result.log_likelihood:.4f}\n"
472
+ if result.aic is not None:
473
+ md += f"- **AIC**: {result.aic:.4f}\n"
474
+ if result.bic is not None:
475
+ md += f"- **BIC**: {result.bic:.4f}\n"
476
+
477
+ return md
478
+
479
+ @staticmethod
480
+ def format_dynamic_panel(result: Any) -> str:
481
+ """格式化动态面板模型结果为Markdown"""
482
+ timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
483
+
484
+ md = f"""# 动态面板模型分析结果
485
+
486
+ **生成时间**: {timestamp}
487
+
488
+ ## 模型信息
489
+
490
+ - **模型类型**: {result.model_type}
491
+ - **观测数量**: {result.n_obs}
492
+ - **个体数量**: {result.n_individuals}
493
+ - **时间期数**: {result.n_time_periods}
494
+
495
+ ## 参数估计
496
+
497
+ | 参数 | 系数 | 标准误 | t值 | p值 |
498
+ |------|------|--------|-----|-----|
499
+ """
500
+
501
+ for i in range(len(result.coefficients)):
502
+ md += f"| 参数{i+1} | {result.coefficients[i]:.6f} | "
503
+ md += f"{result.std_errors[i] if result.std_errors else 0:.6f} | "
504
+ md += f"{result.t_values[i] if result.t_values else 0:.4f} | "
505
+ md += f"{result.p_values[i] if result.p_values else 0:.4f} |\n"
506
+
507
+ md += "\n## 模型统计\n\n"
508
+ if result.instruments is not None:
509
+ md += f"- **工具变量数量**: {result.instruments}\n"
510
+ if result.j_statistic is not None:
511
+ md += f"- **J统计量**: {result.j_statistic:.4f}\n"
512
+ if result.j_p_value is not None:
513
+ md += f"- **J统计量p值**: {result.j_p_value:.4f}\n"
514
+
515
+ return md
516
+
517
+
518
+ class TextFormatter:
519
+ """纯文本格式化器(简化版本)"""
520
+
521
+ @staticmethod
522
+ def format_ols(result: Any) -> str:
523
+ return f"OLS回归结果\n观测数量: {result.n_obs}\nR²: {result.r_squared:.4f}"
524
+
525
+ @staticmethod
526
+ def format_mle(result: Any) -> str:
527
+ return f"MLE估计结果\n观测数量: {result.n_obs}\nAIC: {result.aic:.4f}"
528
+
529
+ @staticmethod
530
+ def format_gmm(result: Any) -> str:
531
+ return f"GMM估计结果\n观测数量: {result.n_obs}\nJ统计量: {result.j_statistic:.4f}"
532
+
533
+ @staticmethod
534
+ def format_arima(result: Any) -> str:
535
+ return f"ARIMA模型结果\n观测数量: {result.n_obs}\nAIC: {result.aic:.4f}"
536
+
537
+ @staticmethod
538
+ def format_exp_smoothing(result: Any) -> str:
539
+ return f"指数平滑模型结果\n观测数量: {result.n_obs}"
540
+
541
+ @staticmethod
542
+ def format_garch(result: Any) -> str:
543
+ return f"GARCH模型结果\n观测数量: {result.n_obs}\nAIC: {result.aic:.4f}"
544
+
545
+ @staticmethod
546
+ def format_unit_root(result: Any) -> str:
547
+ return f"单位根检验结果\n检验统计量: {result.test_statistic:.4f}\np值: {result.p_value:.4f}"
548
+
549
+ @staticmethod
550
+ def format_var(result: Any) -> str:
551
+ return f"VAR模型结果\n观测数量: {result.n_obs}\n滞后期数: {result.lags}"
552
+
553
+ @staticmethod
554
+ def format_cointegration(result: Any) -> str:
555
+ return f"协整检验结果\n检验统计量: {result.test_statistic:.4f}\np值: {result.p_value:.4f}"
556
+
557
+ @staticmethod
558
+ def format_vecm(result: Any) -> str:
559
+ return f"VECM模型结果\n协整秩: {result.coint_rank}\n观测数量: {result.n_obs}"
560
+
561
+ @staticmethod
562
+ def format_dynamic_panel(result: Any) -> str:
563
+ return f"动态面板模型结果\n观测数量: {result.n_obs}\n个体数量: {result.n_individuals}"