← 返回 Skills 市场
wu-uk

timeseries-detrending

作者 wu-uk · GitHub ↗ · v0.1.0 · MIT-0
cross-platform ✓ 安全检测通过
76
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install econ-detrending-correlation-timeseries-detrending
功能描述
Tools and techniques for detrending time series data in macroeconomic analysis. Use when working with economic time series that need to be decomposed into tr...
使用说明 (SKILL.md)

Time Series Detrending for Macroeconomic Analysis

This skill provides guidance on decomposing economic time series into trend and cyclical components, a fundamental technique in business cycle analysis.

Overview

Economic time series like GDP, consumption, and investment contain both long-term trends and short-term fluctuations (business cycles). Separating these components is essential for:

  • Analyzing business cycle correlations
  • Comparing volatility across variables
  • Identifying leading/lagging indicators

The Hodrick-Prescott (HP) Filter

The HP filter is the most widely used method for detrending macroeconomic data. It decomposes a time series into a trend component and a cyclical component.

Mathematical Foundation

Given a time series $y_t$, the HP filter finds the trend $ au_t$ that minimizes:

$$\sum_{t=1}^{T}(y_t - au_t)^2 + \lambda \sum_{t=2}^{T-1}[( au_{t+1} - au_t) - ( au_t - au_{t-1})]^2$$

Where:

  • First term: Minimizes deviation of data from trend
  • Second term: Penalizes changes in the trend's growth rate
  • $\lambda$: Smoothing parameter controlling the trade-off

Choosing Lambda (λ)

Critical: The choice of λ depends on data frequency:

Data Frequency Recommended λ Rationale
Annual 100 Standard for yearly data
Quarterly 1600 Hodrick-Prescott (1997) recommendation
Monthly 14400 Ravn-Uhlig (2002) adjustment

Common mistake: Using λ=1600 (quarterly default) for annual data produces an overly smooth trend that misses important cyclical dynamics.

Python Implementation

from statsmodels.tsa.filters.hp_filter import hpfilter
import numpy as np

# Apply HP filter
# Returns: (cyclical_component, trend_component)
cycle, trend = hpfilter(data, lamb=100)  # For annual data

# For quarterly data
cycle_q, trend_q = hpfilter(quarterly_data, lamb=1600)

Important: The function parameter is lamb (not lambda, which is a Python keyword).

Log Transformation for Growth Series

Why Use Logs?

For most macroeconomic aggregates (GDP, consumption, investment), you should apply the natural logarithm before filtering:

  1. Multiplicative to Additive: Converts percentage changes to log differences
  2. Stabilizes Variance: Growth rates become comparable across time
  3. Economic Interpretation: Cyclical component represents percentage deviations from trend
  4. Standard Practice: Required for business cycle statistics that compare volatilities
import numpy as np

# Apply log transformation BEFORE HP filtering
log_series = np.log(real_series)
cycle, trend = hpfilter(log_series, lamb=100)

# The cycle now represents percentage deviations from trend
# e.g., cycle = 0.02 means 2% above trend

When NOT to Use Logs

  • Series that can be negative (net exports, current account)
  • Series already expressed as rates or percentages
  • Series with zeros

Complete Workflow for Detrending

Step-by-Step Process

  1. Load and clean data: Handle missing values, ensure proper time ordering
  2. Convert to real terms: Deflate nominal values using appropriate price index
  3. Apply log transformation: For positive level variables
  4. Apply HP filter: Use appropriate λ for data frequency
  5. Analyze cyclical component: Compute correlations, volatilities, etc.

Example: Business Cycle Correlation

import pandas as pd
import numpy as np
from statsmodels.tsa.filters.hp_filter import hpfilter

# Load real (inflation-adjusted) data
real_consumption = pd.Series(...)  # Real consumption expenditure
real_investment = pd.Series(...)   # Real fixed investment

# Log transformation
ln_consumption = np.log(real_consumption)
ln_investment = np.log(real_investment)

# HP filter with λ=100 for annual data
cycle_c, trend_c = hpfilter(ln_consumption, lamb=100)
cycle_i, trend_i = hpfilter(ln_investment, lamb=100)

# Compute correlation of cyclical components
correlation = np.corrcoef(cycle_c, cycle_i)[0, 1]
print(f"Business cycle correlation: {correlation:.4f}")

Dependencies

Ensure these packages are installed:

pip install statsmodels pandas numpy

The HP filter is in statsmodels.tsa.filters.hp_filter.

安全使用建议
This skill is a plain guide—there's no code bundled and it doesn't request secrets. Before using, install the recommended Python packages in a virtual environment (pip install statsmodels pandas numpy). Be aware of HP-filter caveats (endpoint bias, choice of λ matters, and you should log-transform only strictly positive level series). Test on sample data and consider alternative detrending methods for robustness; verify package sources and versions before installing.
功能分析
Type: OpenClaw Skill Name: econ-detrending-correlation-timeseries-detrending Version: 0.1.0 The skill bundle provides legitimate educational content and code snippets for macroeconomic time series analysis, specifically focusing on the Hodrick-Prescott (HP) filter. The Python code uses standard libraries (statsmodels, pandas, numpy) for data processing without any signs of malicious intent, data exfiltration, or prompt injection.
能力评估
Purpose & Capability
The name and description (detrending macroeconomic time series) match the SKILL.md content (HP filter, log transforms, correlation analysis). No unrelated binaries, credentials, or config paths are requested.
Instruction Scope
The runtime instructions stay on-topic: data cleaning, log transformation, HP filtering, and computing correlations. They do not ask the agent to read arbitrary files, environment variables, or send data to external endpoints.
Install Mechanism
This is instruction-only (no install spec or code files). The SKILL.md suggests installing standard Python packages via pip (statsmodels, pandas, numpy), which is appropriate and expected for the described tasks.
Credentials
No environment variables, credentials, or config paths are requested. The skill does not ask for secrets or unrelated service access.
Persistence & Privilege
The skill is not marked always:true and is user-invocable. It does not request persistent or elevated privileges and does not modify other skills or system-wide settings.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install econ-detrending-correlation-timeseries-detrending
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /econ-detrending-correlation-timeseries-detrending 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v0.1.0
Bulk publish from all-task-skills-dedup
元数据
Slug econ-detrending-correlation-timeseries-detrending
版本 0.1.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

timeseries-detrending 是什么?

Tools and techniques for detrending time series data in macroeconomic analysis. Use when working with economic time series that need to be decomposed into tr... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 76 次。

如何安装 timeseries-detrending?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install econ-detrending-correlation-timeseries-detrending」即可一键安装,无需额外配置。

timeseries-detrending 是免费的吗?

是的,timeseries-detrending 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

timeseries-detrending 支持哪些平台?

timeseries-detrending 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 timeseries-detrending?

由 wu-uk(@wu-uk)开发并维护,当前版本 v0.1.0。

💬 留言讨论