<essential_principles>
<principle name="two_state_model">
**Core of Two-State Switching Model**
The Zeberg–Salomon model simplifies the market into two states:
- RISK_ON: Hold equities (SPY), business cycle expansion phase
- RISK_OFF: Hold long-term bonds (TLT), business cycle contraction phase
The switching logic is based on the business cycle rule that "leading indicators weaken first, followed by confirmation from coincident indicators."
</principle>
<principle name="leading_coincident">
**Leading vs Coincident Indicators**
| Type | Function | Typical Components | Lead Time |
|---|
| Leading | Early Warning | Yield curve, new orders, housing permits | 6-12 months |
| Coincident | Confirmation | Employment, industrial production, real income | Synchronous |
Synthesis Method:
- Transform each series (yoy/mom/diff)
- Unify direction (+1/-1)
- Rolling z-score standardization
- EMA smoothing
- Weighted synthesis
</principle>
<principle name="iceberg_sinking">
**Iceberg Event vs Sinking Event**
Iceberg Event: LeadingIndex < iceberg_threshold
→ 預警:景氣開始轉弱
→ 搭配「領先指標下降」+ 可選「市場亢奮」濾鏡
Sinking Event: CoincidentIndex < sinking_threshold
→ 確認:實體經濟收縮
→ 通常在 Iceberg 之後數月發生
State Machine Logic:
- RISK_ON → RISK_OFF: Iceberg Event confirmed consecutively + negative slope
- RISK_OFF → RISK_ON: Leading indicator rebounds above (threshold + hysteresis)
</principle>
<principle name="data_access">
**Data Acquisition Methods**
This skill uses data sources that do not require an API key:
- FRED CSV:
https://fred.stlouisfed.org/graph/fredgraph.csv?id={SERIES_ID}
- Yahoo Finance: Fetch SPY, TLT, VIX using the package
Scripts are located in the
directory and can be executed directly.
</principle>
</essential_principles>
<objective>
Implement the Zeberg–Salomon two-state rotation strategy:
- Construct Indicators: Synthesize LeadingIndex and CoincidentIndex from FRED data
- Detect Events: Identify "Iceberg" (leading indicator weakening) and "Sinking" (coincident indicator confirmation) events
- Generate Switch Signals: Produce RISK_ON ↔ RISK_OFF switch events
- Backtest Performance: Calculate cumulative returns, MaxDD, CAGR, and compare with benchmarks
Outputs: List of switch events, indicator time series, backtest summary, diagnostic information.
</objective>
<quick_start>
Fastest Way: Run Default Backtest
bash
cd skills/zeberg-salomon-rotator
pip install pandas numpy yfinance pandas-datareader # First-time use
python scripts/rotator.py --quick
Sample Output:
json
{
"state": "RISK_ON",
"latest_indices": {"LeadingIndex": 0.41, "CoincidentIndex": 0.22},
"iceberg_event": false,
"sinking_event": false,
"last_switch": {"date": "2023-06-30", "action": "EXIT_LONG_BOND_ENTER_EQUITY"}
}
Full Backtest:
bash
python scripts/rotator.py --start 2000-01-01 --end 2026-01-01 --output result.json
</quick_start>
<intake>
What operation do you need to perform?
- Quick Check - View current business cycle state and latest indicators
- Full Backtest - Perform complete historical backtest and performance analysis
- Visualization Charts - Generate multi-panel backtest result charts
- Monitoring Mode - Set up continuous monitoring and switch alerts
- Methodology Learning - Understand the logic of the Zeberg-Salomon model
Please select or provide analysis parameters directly.
</intake>
<routing>
| Response | Action |
|-------------------------------|---------------------------------------------|
| 1, "quick", "check" | Execute `python scripts/rotator.py --quick` |
| 2, "backtest", "full" | Read `workflows/backtest.md` and execute |
| 3, "chart", "plot" | Read `workflows/visualize.md` and execute |
| 4, "monitor", "alert" | Read `workflows/monitor.md` and execute |
| 5, "learn", "methodology", "why" | Read `references/methodology.md` |
| Provide parameters (e.g., date range) | Read `workflows/backtest.md` and execute with parameters |
After routing, read the corresponding document and execute.
</routing>
<directory_structure>
zeberg-salomon-rotator/
├── SKILL.md # 本文件(路由器)
├── skill.yaml # 前端展示元數據
├── manifest.json # 技能元數據
├── workflows/
│ ├── backtest.md # 完整回測工作流
│ ├── visualize.md # 視覺化工作流
│ ├── monitor.md # 持續監控工作流
│ └── analyze.md # 深度分析工作流
├── references/
│ ├── data-sources.md # FRED 系列代碼與資料來源
│ ├── methodology.md # Zeberg-Salomon 方法論解析
│ └── input-schema.md # 完整輸入參數定義
├── templates/
│ ├── output-json.md # JSON 輸出模板
│ └── output-markdown.md # Markdown 報告模板
└── scripts/
├── rotator.py # 主輪動腳本
├── visualize.py # 視覺化繪圖工具
└── fetch_data.py # 數據抓取工具
</directory_structure>
<reference_index>
Methodology: references/methodology.md
- Zeberg-Salomon model concepts
- Definitions of Iceberg/Sinking events
- Two-state switching logic
Data Sources: references/data-sources.md
- FRED series codes (leading/coincident)
- Yahoo Finance asset codes
- Data frequency and alignment
Input Parameters: references/input-schema.md
- Complete parameter definitions
- Default values and recommended ranges
</reference_index>
<workflows_index>
| Workflow | Purpose | Usage Scenario |
|---|
| backtest.md | Complete historical backtest | When performance analysis is needed |
| visualize.md | Generate visualization charts | When chart presentation is needed |
| monitor.md | Continuous state monitoring | For daily monitoring or alerts |
| analyze.md | In-depth indicator analysis | To understand current market conditions |
| </workflows_index> | | |
<templates_index>
| Template | Purpose |
|---|
| output-json.md | JSON output structure definition |
| output-markdown.md | Markdown report template |
| </templates_index> | |
<scripts_index>
| Script | Command | Purpose |
|---|
| rotator.py | | Quick check of current state |
| rotator.py | | Complete backtest |
| visualize.py | -i result.json -o chart.png
| Generate visualization charts |
| fetch_data.py | | Fetch FRED data |
| </scripts_index> | | |
<input_schema_summary>
Core Parameters
| Parameter | Type | Default Value | Description |
|---|
| start_date | string | 2000-01-01 | Backtest start date |
| end_date | string | today | Backtest end date |
| freq | string | M | Frequency (M=Monthly) |
| equity_proxy | string | SPY | Risk asset proxy |
| bond_proxy | string | TLT | Long-term bond proxy |
Threshold Parameters
| Parameter | Type | Default Value | Description |
|---|
| iceberg_threshold | number | -0.3 | Leading indicator threshold |
| sinking_threshold | number | -0.5 | Coincident indicator threshold |
| confirm_periods | int | 2 | Number of consecutive confirmation periods |
| hysteresis | number | 0.15 | Entry/exit gap |
Complete parameter definitions can be found in
references/input-schema.md
.
</input_schema_summary>
<output_schema_summary>
json
{
"skill": "zeberg-salomon-rotator",
"as_of": "2026-01-14",
"state": "RISK_ON",
"latest_indices": {
"LeadingIndex": 0.41,
"CoincidentIndex": 0.22,
"iceberg_event": false,
"sinking_event": false
},
"switch_events": [...],
"backtest_summary": {
"cagr": 0.123,
"max_drawdown": -0.27,
"turnovers": 10
}
}
Complete output structure is available in
.
</output_schema_summary>
<success_criteria>
When execution is successful, the following should be produced: