aigroup-econ-mcp 0.4.2__py3-none-any.whl → 1.4.3__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.
- .gitignore +253 -0
- PKG-INFO +710 -0
- README.md +672 -0
- __init__.py +14 -0
- aigroup_econ_mcp-1.4.3.dist-info/METADATA +710 -0
- aigroup_econ_mcp-1.4.3.dist-info/RECORD +92 -0
- aigroup_econ_mcp-1.4.3.dist-info/entry_points.txt +2 -0
- aigroup_econ_mcp-1.4.3.dist-info/licenses/LICENSE +21 -0
- cli.py +28 -0
- econometrics/README.md +18 -0
- econometrics/__init__.py +191 -0
- econometrics/advanced_methods/modern_computing_machine_learning/__init__.py +0 -0
- econometrics/basic_parametric_estimation/__init__.py +31 -0
- econometrics/basic_parametric_estimation/gmm/__init__.py +13 -0
- econometrics/basic_parametric_estimation/gmm/gmm_model.py +256 -0
- econometrics/basic_parametric_estimation/mle/__init__.py +13 -0
- econometrics/basic_parametric_estimation/mle/mle_model.py +241 -0
- econometrics/basic_parametric_estimation/ols/__init__.py +13 -0
- econometrics/basic_parametric_estimation/ols/ols_model.py +141 -0
- econometrics/causal_inference/causal_identification_strategy/__init__.py +0 -0
- econometrics/missing_data/missing_data_measurement_error/__init__.py +0 -0
- econometrics/model_specification_diagnostics_robust_inference/README.md +173 -0
- econometrics/model_specification_diagnostics_robust_inference/__init__.py +78 -0
- econometrics/model_specification_diagnostics_robust_inference/diagnostic_tests/__init__.py +20 -0
- econometrics/model_specification_diagnostics_robust_inference/diagnostic_tests/diagnostic_tests_model.py +149 -0
- econometrics/model_specification_diagnostics_robust_inference/generalized_least_squares/__init__.py +15 -0
- econometrics/model_specification_diagnostics_robust_inference/generalized_least_squares/gls_model.py +130 -0
- econometrics/model_specification_diagnostics_robust_inference/model_selection/__init__.py +18 -0
- econometrics/model_specification_diagnostics_robust_inference/model_selection/model_selection_model.py +286 -0
- econometrics/model_specification_diagnostics_robust_inference/regularization/__init__.py +15 -0
- econometrics/model_specification_diagnostics_robust_inference/regularization/regularization_model.py +177 -0
- econometrics/model_specification_diagnostics_robust_inference/robust_errors/__init__.py +15 -0
- econometrics/model_specification_diagnostics_robust_inference/robust_errors/robust_errors_model.py +122 -0
- econometrics/model_specification_diagnostics_robust_inference/simultaneous_equations/__init__.py +15 -0
- econometrics/model_specification_diagnostics_robust_inference/simultaneous_equations/simultaneous_equations_model.py +246 -0
- econometrics/model_specification_diagnostics_robust_inference/weighted_least_squares/__init__.py +15 -0
- econometrics/model_specification_diagnostics_robust_inference/weighted_least_squares/wls_model.py +127 -0
- econometrics/nonparametric/nonparametric_semiparametric_methods/__init__.py +0 -0
- econometrics/spatial_econometrics/spatial_econometrics_new/__init__.py +0 -0
- econometrics/specific_data_modeling/micro_discrete_limited_data/__init__.py +0 -0
- econometrics/specific_data_modeling/survival_duration_data/__init__.py +0 -0
- econometrics/specific_data_modeling/time_series_panel_data/__init__.py +143 -0
- econometrics/specific_data_modeling/time_series_panel_data/arima_model.py +104 -0
- econometrics/specific_data_modeling/time_series_panel_data/cointegration_vecm.py +334 -0
- econometrics/specific_data_modeling/time_series_panel_data/dynamic_panel_models.py +653 -0
- econometrics/specific_data_modeling/time_series_panel_data/exponential_smoothing.py +176 -0
- econometrics/specific_data_modeling/time_series_panel_data/garch_model.py +198 -0
- econometrics/specific_data_modeling/time_series_panel_data/panel_diagnostics.py +125 -0
- econometrics/specific_data_modeling/time_series_panel_data/panel_var.py +60 -0
- econometrics/specific_data_modeling/time_series_panel_data/structural_break_tests.py +87 -0
- econometrics/specific_data_modeling/time_series_panel_data/time_varying_parameter_models.py +106 -0
- econometrics/specific_data_modeling/time_series_panel_data/unit_root_tests.py +204 -0
- econometrics/specific_data_modeling/time_series_panel_data/var_svar_model.py +372 -0
- econometrics/statistical_inference/statistical_inference_techniques/__init__.py +0 -0
- econometrics/statistics/distribution_decomposition_methods/__init__.py +0 -0
- econometrics/tests/basic_parametric_estimation_tests/__init__.py +3 -0
- econometrics/tests/basic_parametric_estimation_tests/test_gmm.py +128 -0
- econometrics/tests/basic_parametric_estimation_tests/test_mle.py +127 -0
- econometrics/tests/basic_parametric_estimation_tests/test_ols.py +100 -0
- econometrics/tests/model_specification_diagnostics_tests/__init__.py +3 -0
- econometrics/tests/model_specification_diagnostics_tests/test_diagnostic_tests.py +86 -0
- econometrics/tests/model_specification_diagnostics_tests/test_robust_errors.py +89 -0
- econometrics/tests/specific_data_modeling_tests/__init__.py +3 -0
- econometrics/tests/specific_data_modeling_tests/test_arima.py +98 -0
- econometrics/tests/specific_data_modeling_tests/test_dynamic_panel.py +198 -0
- econometrics/tests/specific_data_modeling_tests/test_exponential_smoothing.py +105 -0
- econometrics/tests/specific_data_modeling_tests/test_garch.py +118 -0
- econometrics/tests/specific_data_modeling_tests/test_unit_root.py +156 -0
- econometrics/tests/specific_data_modeling_tests/test_var.py +124 -0
- prompts/__init__.py +0 -0
- prompts/analysis_guides.py +43 -0
- pyproject.toml +78 -0
- resources/MCP_MASTER_GUIDE.md +422 -0
- resources/MCP_TOOLS_DATA_FORMAT_GUIDE.md +185 -0
- resources/__init__.py +0 -0
- server.py +83 -0
- tools/README.md +88 -0
- tools/__init__.py +45 -0
- tools/data_loader.py +213 -0
- tools/decorators.py +38 -0
- tools/econometrics_adapter.py +286 -0
- tools/mcp_tool_groups/__init__.py +1 -0
- tools/mcp_tool_groups/basic_parametric_tools.py +173 -0
- tools/mcp_tool_groups/model_specification_tools.py +402 -0
- tools/mcp_tool_groups/time_series_tools.py +494 -0
- tools/mcp_tools_registry.py +114 -0
- tools/model_specification_adapter.py +369 -0
- tools/output_formatter.py +563 -0
- tools/time_series_panel_data_adapter.py +858 -0
- tools/time_series_panel_data_tools.py +65 -0
- aigroup_econ_mcp/__init__.py +0 -19
- aigroup_econ_mcp/cli.py +0 -82
- aigroup_econ_mcp/config.py +0 -561
- aigroup_econ_mcp/server.py +0 -452
- aigroup_econ_mcp/tools/__init__.py +0 -18
- aigroup_econ_mcp/tools/base.py +0 -470
- aigroup_econ_mcp/tools/cache.py +0 -533
- aigroup_econ_mcp/tools/data_loader.py +0 -171
- aigroup_econ_mcp/tools/file_parser.py +0 -829
- aigroup_econ_mcp/tools/machine_learning.py +0 -60
- aigroup_econ_mcp/tools/ml_ensemble.py +0 -210
- aigroup_econ_mcp/tools/ml_evaluation.py +0 -272
- aigroup_econ_mcp/tools/ml_models.py +0 -54
- aigroup_econ_mcp/tools/ml_regularization.py +0 -172
- aigroup_econ_mcp/tools/monitoring.py +0 -555
- aigroup_econ_mcp/tools/optimized_example.py +0 -229
- aigroup_econ_mcp/tools/panel_data.py +0 -553
- aigroup_econ_mcp/tools/regression.py +0 -214
- aigroup_econ_mcp/tools/statistics.py +0 -154
- aigroup_econ_mcp/tools/time_series.py +0 -667
- aigroup_econ_mcp/tools/timeout.py +0 -283
- aigroup_econ_mcp/tools/tool_handlers.py +0 -378
- aigroup_econ_mcp/tools/tool_registry.py +0 -170
- aigroup_econ_mcp/tools/validation.py +0 -482
- aigroup_econ_mcp-0.4.2.dist-info/METADATA +0 -360
- aigroup_econ_mcp-0.4.2.dist-info/RECORD +0 -29
- aigroup_econ_mcp-0.4.2.dist-info/entry_points.txt +0 -2
- /aigroup_econ_mcp-0.4.2.dist-info/licenses/LICENSE → /LICENSE +0 -0
- {aigroup_econ_mcp-0.4.2.dist-info → aigroup_econ_mcp-1.4.3.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}"
|