Skip to content
forecast-sector-relative-return-from-yield-spread logo

Forecast Sector Relative Return From Yield Spread

forecast-sector-relative-return-from-yield-spread

用美債殖利率曲線利差(如 2Y-10Y)建立「領先關係」,推估未來一段時間內成長股(Nasdaq 100)相對防禦股(Healthcare/XLV)的相對績效方向與幅度。

SKILL.md

Full skill instructions

<essential_principles>

<principle name="lead_lag_definition"> **領先落後關係定義**

殖利率利差(Yield Spread)作為領先指標:

spread_t = short_yield_t - long_yield_t
         = US02Y_t - US10Y_t

spread 越高:短端相對更高(曲線更倒掛/更緊) spread 越低(或從負回到 0、轉正):曲線「回正/變陡」

此 spread 被認為領先反映:

  • 經濟週期預期(倒掛 → 衰退預期)
  • 風險偏好轉換(曲線變陡 → 風險偏好回升) </​principle>
<principle name="relative_return_definition"> **相對報酬定義**

相對強弱比率(Ratio):

ratio_t = risk_asset_t / defensive_asset_t
        = QQQ_t / XLV_t

ratio 上升:成長股(Nasdaq)相對更強 ratio 下降:防禦股(Healthcare)相對更強(XLV 跑贏)

預測目標為「未來 H 個月的對數相對報酬」:

future_rel_return = log(ratio(t+H) / ratio(t))

正值 → Nasdaq 跑贏,負值 → XLV 跑贏 </​principle>

<principle name="advance_alignment"> **「2 Years in Advance」的真正含義**

圖表的時間對齊邏輯:

  • 把 spread 往前平移 lead_months 個月
  • 目標是檢查:spread(t) 是否能解釋 ratio(t + H)

工程化寫法:

X = spread(t)
Y = future_rel_return(t, H) = log(ratio(t+H) / ratio(t))

然後做相關性/迴歸/交叉相關掃描來找「最佳領先期」。

避免直接用 ratio 水平做迴歸(有趨勢/非平穩問題),改用對數報酬。 </​principle>

<principle name="validation_framework"> **領先關係驗證框架**

需回答三件事:

  1. 是否真的存在穩定領先關係?

    • 掃描多個 lead(6, 12, 18, 24, 30 個月)
    • 看哪個 lead 下 corr(spread, future_rel_return) 最穩、顯著
    • 跨子樣本驗證(前半段 vs 後半段)
  2. 目前情境對應的預測方向

    • 最近 spread 水準、變化率
    • 模型預測 E[future_rel_return]
    • 分位數區間(如 80% 信心區間)
  3. 把預測翻譯成直覺語句

    • 由 future_rel_return 轉回百分比:exp(future_rel_return) - 1
    • 「未來 24 個月 XLV 相對 QQQ 勝率 X%、中位數報酬 Y%」 </​principle>
<principle name="data_alignment"> **數據對齊原則**
  • 頻率選擇:週頻(weekly)降低雜訊,建議 1wk
  • 平滑視窗:可選 13 週或 26 週移動平均
  • 回測長度:至少涵蓋 1-2 次完整景氣循環(如 2007-present)

殖利率來源:FRED(DGS2, DGS10) 資產價格來源:Yahoo Finance(QQQ, XLV) </​principle>

</​essential_principles>

<objective> 實作「殖利率利差 → 板塊相對報酬」領先關係分析:
  1. 數據整合:取得殖利率(FRED)與資產價格(yfinance)
  2. 利差計算:計算 spread = short_yield - long_yield
  3. 相對報酬計算:計算 future_rel_return = log(ratio(t+H) / ratio(t))
  4. 領先關係驗證:掃描多個 lead 找最佳相關性與穩定性
  5. 情境預測:基於當前 spread 產出未來相對報酬預測區間
  6. 輸出報告:驗證結論、預測方向、風險提示

輸出:領先關係驗證、當前預測、區間估計、歷史類比、風險提示。 </​objective>

<quick_start>

最快的方式:執行預設情境分析

cd skills/​forecast-sector-relative-return-from-yield-spread
pip install pandas numpy yfinance matplotlib statsmodels requests  # 首次使用
python scripts/​spread_forecaster.py --quick

完整分析(含領先掃描與穩定性驗證)

python scripts/​spread_forecaster.py \
  --risk-ticker QQQ \
  --defensive-ticker XLV \
  --lead-months 24 \
  --lookback-years 12 \
  --output result.json

生成視覺化圖表

python scripts/​spread_plotter.py --quick --output-dir ../​../​output

輸出範例:

{
  "skill": "forecast_sector_relative_return_from_yield_spread",
  "signal_name": "US02Y_minus_US10Y_leads_QQQ_over_XLV",
  "lead_months": 24,
  "current_spread": -0.35,
  "model": {
    "type": "lagged_regression",
    "alpha": 0.02,
    "beta": -0.45,
    "corr_x_y": -0.32
  },
  "forecast": {
    "future_24m_relative_return_pct": -0.077,
    "interval_pct_80": [-0.22, 0.04],
    "interpretation": "若此關係維持,未來24個月QQQ相對XLV期望報酬為-7.7%,XLV較可能跑贏。"
  }
}

</​quick_start>

<intake> 需要進行什麼操作?
  1. 快速分析 - 使用預設參數(QQQ/​XLV, 24 個月領先)計算當前預測
  2. 完整分析 - 自訂參數進行領先關係驗證與情境預測
  3. 領先掃描 - 掃描多個領先期(6-30 個月)找最佳相關性
  4. 視覺化圖表 - 生成利差與相對報酬對齊圖
  5. 穩定性驗證 - 檢查領先關係在不同子樣本的一致性
  6. 方法論學習 - 了解領先關係邏輯與計算方式

請選擇或直接提供分析參數。 </​intake>

<routing> | Response | Action | |--------------------------------|---------------------------------------------------------------------| | 1, "快速", "quick", "分析" | 執行 `python scripts/​spread_forecaster.py --quick` | | 2, "完整", "full", "自訂" | 閱讀 `workflows/​analyze.md` 並執行 | | 3, "掃描", "scan", "領先" | 閱讀 `workflows/​analyze.md` 並聚焦 lead_scan | | 4, "圖表", "chart", "視覺化" | 執行 `python scripts/​spread_plotter.py --quick --output-dir output/`| | 5, "驗證", "穩定", "stability" | 閱讀 `workflows/​analyze.md` 並聚焦穩定性驗證 | | 6, "學習", "方法論", "why" | 閱讀 `references/​methodology.md` | | 提供參數 (如 ticker, lead) | 閱讀 `workflows/​analyze.md` 並使用參數執行 |

路由後,閱讀對應文件並執行。 </​routing>

<directory_structure>

forecast-sector-relative-return-from-yield-spread/
├── SKILL.md                           # 本文件(路由器)
├── skill.yaml                         # 前端展示元數據
├── manifest.json                      # 技能元數據
├── workflows/
│   ├── analyze.md                     # 完整分析工作流
│   └── data-research.md               # 數據源研究與替代方案
├── references/
│   ├── methodology.md                 # 方法論與計算邏輯
│   ├── input-schema.md                # 完整輸入參數定義
│   └── data-sources.md                # 數據來源與獲取方式
├── templates/
│   ├── output-json.md                 # JSON 輸出模板
│   └── output-markdown.md             # Markdown 報告模板
├── scripts/
│   ├── spread_forecaster.py           # 主計算腳本
│   └── spread_plotter.py              # 視覺化圖表腳本
└── examples/
    └── sample-output.json             # 範例輸出

</​directory_structure>

<reference_index>

方法論: references/​methodology.md

  • 領先落後關係定義
  • 相對報酬計算
  • 迴歸模型設定
  • 區間估計方法
  • 穩定性驗證

資料來源: references/​data-sources.md

  • 殖利率代理(FRED DGS2/​DGS10)
  • 資產價格代理(QQQ/​XLV)
  • 數據對齊原則

輸入參數: references/​input-schema.md

  • 完整參數定義
  • 預設值與建議範圍

</​reference_index>

<workflows_index>

WorkflowPurpose使用時機
analyze.md完整情境分析需要自訂參數驗證領先關係與預測
data-research.md數據源研究了解如何獲取或替代殖利率/資產數據
</​workflows_index>

<templates_index>

TemplatePurpose
output-json.mdJSON 輸出結構定義
output-markdown.mdMarkdown 報告模板
</​templates_index>

<scripts_index>

ScriptCommandPurpose
spread_forecaster.py--quick快速分析 QQQ/​XLV, 24m lead
spread_forecaster.py--lead-months 12 --lookback-years 15自訂領先期與回測長度
spread_forecaster.py--lead-scan --scan-range 6,12,18,24,30領先期掃描
spread_plotter.py--quick --output-dir ../​../​output快速生成基本版圖表
spread_plotter.py--comprehensive --start-date 2007-01-01完整版圖表(含領先對齊)
</​scripts_index>

<input_schema_summary>

核心參數

參數類型預設值說明
risk_tickerstringQQQ代表成長股的標的
defensive_tickerstringXLV代表防禦股的標的
short_tenorstring2Y短端殖利率期限
long_tenorstring10Y長端殖利率期限
lead_monthsint24領先期(月)
lookback_yearsint12回測/估計歷史年數

進階參數

參數類型預設值說明
freqstringweekly資料頻率(daily/​weekly/​monthly)
smoothing_windowint13平滑視窗(週數)
return_horizon_monthsint24預測的相對報酬視窗
model_typestringlagged_regression模型類型
confidence_levelfloat0.80區間估計信心水準

完整參數定義見 references/​input-schema.md。

</​input_schema_summary>

<output_schema_summary>

{
  "skill": "forecast_sector_relative_return_from_yield_spread",
  "inputs": {
    "risk_ticker": "QQQ",
    "defensive_ticker": "XLV",
    "lead_months": 24,
    "lookback_years": 12
  },
  "signal_name": "US02Y_minus_US10Y_leads_QQQ_over_XLV",
  "lead_months": 24,
  "current_spread": -0.35,
  "model": {
    "type": "lagged_regression",
    "alpha": 0.02,
    "beta": -0.45,
    "fit_quality": {
      "corr_x_y": -0.32,
      "r_squared": 0.10,
      "notes": "負 beta 意味歷史上倒掛/緊縮的 spread 對應未來 QQQ 相對走弱"
    }
  },
  "forecast": {
    "future_24m_relative_return_log": -0.08,
    "future_24m_relative_return_pct": -0.077,
    "interval_pct_80": [-0.22, 0.04],
    "interpretation": "若此關係維持,未來24個月QQQ相對XLV期望報酬為-7.7%,XLV較可能跑贏;但區間仍含正值,需搭配其他條件確認。"
  },
  "diagnostics": {
    "lead_scan": {
      "best_lead_months": 24,
      "correlation_by_lead": {"6": -0.15, "12": -0.22, "18": -0.28, "24": -0.32, "30": -0.30}
    },
    "stability_checks": {
      "first_half_corr": -0.30,
      "second_half_corr": -0.34,
      "consistency": "medium-high"
    }
  },
  "summary": "殖利率利差(2Y-10Y)對 QQQ/​XLV 相對報酬有約 24 個月的領先性...",
  "notes": [
    "領先關係反映的是『歷史統計規律』,不保證未來成立。",
    "當前 spread 水準與變化率皆需考慮。",
    "建議搭配:景氣指標、估值分位、資金流向做交叉驗證。"
  ]
}

完整輸出結構見 templates/​output-json.md。 </​output_schema_summary>

<success_criteria> 執行成功時應產出:

  • 當前殖利率利差水準
  • 領先關係相關性與迴歸係數
  • 未來相對報酬預測(點估計與區間)
  • 領先期掃描結果(若執行)
  • 穩定性驗證(子樣本一致性)
  • 結果輸出為指定格式(JSON 或 Markdown)
  • 視覺化圖表輸出(若需要)
  • 風險提示與後續研究建議 </​success_criteria>

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View