Skip to main content
Glama

backtest_forecast

Run rolling-window backtests on time series data to compute MAE, RMSE, and MAPE, validating forecast accuracy before trusting predictions.

Instructions

backtest_forecast —— 时序组 · 滚动回测(工具 29,v1.2.0 新增)。

time_series_forecast 的可信度自评:滚动窗口回测输出 MAE/RMSE/MAPE, 让预测结论自带"历史表现"背书。前置处理与 forecast 完全同口径 (_prepare_series 五项统一前置),逐窗独立重放以杜绝真值泄漏 (验证窗不含任何由未来观测构造的插值点——design/06 防泄漏节)。

docstring = agent 使用说明书,与 statlab_mcp/docs/design/06_timeseries.md 同步维护。

参数: file_path (str): 本地数据文件(csv/tsv/xlsx/json),仅接受本地路径 date_col (str): 日期列;value_col (str): 数值值列(语义与 time_series_forecast 一致) horizon (int): 每窗验证段长度,1 <= horizon <= 有效样本×50%(E1001) windows (int, 3): 回测窗口数,1..10(auto_arima 每窗一次拟合,防耗时爆炸;E1001) method (str, "auto_arima"): auto_arima / naive / seasonal_naive (两个 naive 基线为封闭公式,用于对照;seasonal_naive 的周期逐窗取 _estimate_period,不可估或 > 训练段长时退化为 naive 并记 period_used_fallback)

门槛链(校验顺序红线 D9): 参数合法 → n>=30(低于报错 E1010)→ n >= horizon*(windows+1) 且 train_min = n - windowshorizon >= max(15, 2period_full_est)(E1010 带调参建议) → n<=100000(E1005 防大表卡顿)→ 逐窗计算。

指标: 每窗口逐点 pred/actual/abs_err + 汇总 MAE/RMSE/MAPE; 真实值含 |actual|<=1e-12 时该窗口 MAPE=null 并注明 zero_note(禁止除零假值)。 明细总量上限 10000 点,超出截断最旧窗并记 truncated=true(汇总永不截断)。

局限声明(固定附于 summary 末尾):回测表现不代表未来;未做外部验证。

示例: backtest_forecast("samples/clean.csv", "date", "score", horizon=3) backtest_forecast("samples/clean.csv", "date", "score", horizon=2, windows=2, method="naive") inline 数据: 本工具支持可选 inline_data 参数(v1.2.0 起):与 file_path 二选一, 支持 records 数组或 {"header": [...], "rows": [[...], ...]} 对象两种形态; 规模上限/类型域/data_source 来源标注见 statlab_mcp/docs/SPEC.md 第 12 节。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
methodNoauto_arima
horizonNo
windowsNo
date_colNo
file_pathNo
value_colNo
inline_dataNo

Schema Changelog

Changes observed during successful MCP inspections. Dates show when Glama detected each change.

  1. First observedv1.2.0

TDQS

A4.8/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It discloses that the tool performs multiple model fits, has a 10000-point result cap with truncation, reports MAPE=null for near-zero actuals, and appends a limitations disclaimer. It also reveals internal details like _prepare_series and leakage prevention. This is exceptional transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is long but densely packed with valuable information, organized with clear headers (参数, 门槛链, 指标, 局限声明, 示例). It front-loads the core purpose before diving into details. Some redundancy exists (e.g., E1001 mentioned twice), and the docstring maintenance note is meta-information that could be trimmed, but every section earns its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given 7 parameters, no output schema, no annotations, and a complex statistical tool, this description covers validation rules, output metrics, error codes, edge cases, and usage examples. It even addresses potential concerns like computational cost and data leakage. This is as complete as a text description can reasonably be.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It explains each parameter with types, defaults, constraints, and semantic alignment with time_series_forecast. For method, it enumerates all three options and their behaviors. The only minor gap is that inline_data's exact shape is deferred to SPEC.md, but the description gives enough context to use it.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description begins with a clear statement: '时序组 · 滚动回测' and immediately explains it is a rolling-window backtest for time_series_forecast, computing MAE/RMSE/MAPE. It distinguishes itself from the sibling time_series_forecast by emphasizing it provides '历史表现' credibility. The purpose is specific and unmistakable.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly states this tool is for validating time_series_forecast, and notes it shares preprocessing with forecast. It provides parameter constraints, validation thresholds (E1010, E1005), and even notes inline_data is an alternative to file_path. It gives explicit examples and explains fallback behavior for seasonal_naive. This is comprehensive usage guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/good-boy4069/statlab-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server