Commodity analysis (oil supply-demand balance / gold pricing / copper as an economic predictor / inventory cycles / futures premium-discount structure / seasona
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-commodity-analysis-4827dbf61bba ,按照其中的说明把「commodity-analysis」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
Analyze commodities from four dimensions — supply-demand balance, pricing model, inventory cycle, and futures structure — and output directional signals suitable for backtesting. Focuses on crude oil (global pricing anchor), gold (safe haven + inflation hedge), and copper (economic barometer).
Key supply-side variables:
| Variable | Data Source | Frequency | Direction of Impact |
|---|---|---|---|
| OPEC production | OPEC monthly report | Monthly | Production cuts → oil price ↑ |
| US shale output | EIA weekly report | Weekly | Higher output → oil price ↓ |
| Rig count (Baker Hughes) | Baker Hughes | Weekly | Leads production by 3-6 months |
| Strategic Petroleum Reserve (SPR) | EIA | Weekly | SPR release → short-term oil price ↓ |
Key demand-side variables:
Supply-demand balance signals:
# Simplified supply-demand judgment
if opec_compliance > 90% and us_rig_count_declining:
supply_signal = "tight" # bullish for oil
elif opec_compliance < 80% and us_production_rising:
supply_signal = "loose" # bearish for oil
if global_pmi > 50 and china_import_yoy > 5%:
demand_signal = "strong" # bullish for oil
elif global_pmi < 48 and china_import_yoy < 0:
demand_signal = "weak" # bearish for oil
Four-factor model:
| Factor | Weight | Logic | Indicator |
|---|---|---|---|
| Real rates | 40% | Real rates ↓ → lower opportunity cost of holding gold → gold ↑ | 10Y TIPS yield |
| US dollar index | 25% | USD ↓ → gold becomes cheaper in pricing terms → gold ↑ | DXY |
| Safe-haven demand | 20% | Risk ↑ → safe-haven buying → gold ↑ | VIX + geopolitical risk index |
| Central-bank buying | 15% | Central-bank purchases → structural demand support | WGC quarterly report |
Practical rules:
Copper as a leading indicator:
r > 0.7)Copper fundamental tracking:
| Indicator | Data Source | Threshold |
|---|---|---|
| LME copper inventory | LME daily report | <150k tons = tight |
| SHFE copper inventory | SHFE weekly report | WoW decline >10% = tight |
| Copper concentrate TC/RC | SMM | TC < $30/ton = tight mining supply |
| China copper imports | Customs monthly report | YoY growth >10% = strong demand |
Visible inventory vs hidden inventory:
Four inventory-cycle stages (using copper as example):
Active restocking (price↑ volume↑) -> Passive restocking (price↓ volume↑) -> Active destocking (price↓ volume↓) -> Passive destocking (price↑ volume↓)
mid bull market late bull market mid bear market late bear / early bull market
Signal mapping:
| Stage | Inventory Direction | Price Direction | Trading Signal |
|---|---|---|---|
| Passive destocking | ↓ | ↑ | Long (best buying point) |
| Active restocking | ↑ | ↑ | Keep long positions |
| Passive restocking | ↑ | ↓ | Close longs (warning) |
| Active destocking | ↓ | ↓ | Short or stay neutral |
Contango (futures > spot, normal market):
roll yield < 0), unfavorable for long holdersfar month - near month > 5%) = severe oversupplyBackwardation (futures < spot, inverted market):
roll yield > 0), favorable for long holdersnear month - far month > 3%) = squeeze or extreme shortageTerm-structure signal:
# Spread ratio = (front month - second month) / front month
spread_ratio = (front_month - second_month) / front_month
if spread_ratio > 0.02: # backwardation > 2%
signal = "strongly bullish" # spot shortage
elif spread_ratio < -0.03: # contango > 3%
signal = "bearish" # oversupply
else:
signal = "neutral"
Oil seasonality:
Gold seasonality:
Copper seasonality:
commodity_score = {
"supply_demand": +1, # supply-demand is tight
"inventory_cycle": +2, # passive destocking (best stage)
"term_structure": +1, # mild backwardation
"seasonality": 0, # neutral seasonality
"macro_env": -1, # stronger dollar is a headwind
}
# Total score = +3/5 = +0.6 -> bullish bias, but not a strong signal
## Commodity Analysis Report — [Commodity Name]
### Supply-Demand Structure
- Supply side: [surplus / balanced / shortage] — [specific data]
- Demand side: [strong / stable / weak] — [specific data]
- Balance table: [inventory build X tons / drawdown X tons]
### Inventory Cycle
- Current stage: [active restocking / passive restocking / active destocking / passive destocking]
- Visible inventory: [LME X tons, SHFE X tons, WoW change]
### Term Structure
- Front-back spread: [contango X% / backwardation X%]
- Roll yield: [positive / negative]
### Composite Score
| Dimension | Score(-2~+2) | Basis |
|------|------------|------|
| Supply-demand | +1 | OPEC compliance rate 92% |
| Inventory | +2 | LME inventory hit 18-month low |
### Trading Direction
- Direction: [bullish / bearish / neutral]
- Confidence: [high / medium / low]
- Risk points: [specific risks]
web-reader or entered manually