Skip to main content
ClaudeWave
Skill12k estrellas del repoactualizado today

cross-market-strategy

This Claude Code skill generates a signal_engine.py module for multi-market portfolio strategies that span different asset classes like A-shares, cryptocurrencies, equities, and forex. Use it when backtesting portfolios with symbols from multiple markets that have distinct volatility profiles and require market-specific indicator parameters. The module automates market classification, applies tailored technical parameters per asset class, adjusts position sizing by inverse volatility to prevent volatile assets from dominating portfolio risk, and implements cross-market signal patterns like momentum spillover and risk-regime detection.

Instalar en Claude Code
Copiar
git clone --depth 1 https://github.com/HKUDS/Vibe-Trading /tmp/cross-market-strategy && cp -r /tmp/cross-market-strategy/agent/src/skills/cross-market-strategy ~/.claude/skills/cross-market-strategy
Después abre una sesión nueva de Claude Code; el skill carga automáticamente.

SKILL.md

## When to Use

When the user requests a backtest with codes from **different markets** — e.g. `["000001.SZ", "BTC-USDT"]` or `["AAPL.US", "EUR/USD", "600519.SH"]`.

The `CompositeEngine` handles calendar alignment, shared capital, and market rules automatically. The strategy only needs to output per-symbol signals.

## Key Concepts

### 1. Market Classification in generate()

Group symbols by market type and apply market-specific indicator parameters:

```python
def generate(self, data_map):
    groups = {}
    for code, df in data_map.items():
        market = self._detect_market(code)
        groups.setdefault(market, {})[code] = df

    signals = {}
    for market, market_data in groups.items():
        params = MARKET_PARAMS[market]
        for code, df in market_data.items():
            signals[code] = self._market_signal(df, params)
    return signals
```

### 2. Per-Market Parameter Tables

Different markets have very different dynamics. Using the same parameters everywhere produces poor results.

| Parameter | A-Share | Crypto | US Equity | Forex |
|-----------|---------|--------|-----------|-------|
| MA fast | 5 | 7 | 10 | 10 |
| MA slow | 20 | 25 | 50 | 30 |
| RSI period | 14 | 10 | 14 | 14 |
| Vol lookback | 20 | 14 | 20 | 20 |
| Typical daily vol | 1-2% | 3-8% | 1-2% | 0.3-0.8% |

### 3. Volatility-Adjusted Weights (Critical)

BTC daily vol ~ 5%, A-share daily vol ~ 1.5%. Without vol-adjustment, crypto eats the entire risk budget.

```python
def _vol_adjust(self, signals, data_map):
    vols = {}
    for code, df in data_map.items():
        ret = df["close"].pct_change().dropna()
        vols[code] = ret.rolling(20).std().iloc[-1] if len(ret) > 20 else ret.std()

    inv_vols = {c: 1.0 / (v + 1e-10) for c, v in vols.items()}
    total_inv = sum(inv_vols.values())

    adjusted = {}
    for code, sig in signals.items():
        weight = inv_vols[code] / total_inv * len(signals)
        adjusted[code] = (sig * weight).clip(-1.0, 1.0)
    return adjusted
```

### 4. Cross-Market Signal Patterns

1. **Momentum spillover**: BTC 7-day momentum as overlay for A-share tech sectors
2. **Risk-on/Risk-off**: USD/CNH rate + VIX proxy to reduce equity exposure
3. **Hedging**: Long A-shares + short crypto delta as tail hedge
4. **Correlation regime**: When rolling correlation > 0.6, reduce to single-market exposure; when < 0.2, maximize diversification

### 5. What the Engine Handles (Don't Worry About)

- **Trading calendar alignment**: signals are shifted on each symbol's own calendar, then ffill'd to unified dates
- **Market rules**: T+1 for A-shares, funding fees for crypto, swap for forex — all per-symbol
- **Capital allocation**: shared pool, strategy just sets target weights via signals
- **Commission/slippage**: dispatched to correct sub-engine per symbol

## config.json for Cross-Market

```json
{
  "source": "auto",
  "codes": ["000001.SZ", "BTC-USDT"],
  "start_date": "2024-01-01",
  "end_date": "2025-03-31",
  "interval": "1D",
  "initial_cash": 1000000,
  "engine": "daily"
}
```

- `source` **must** be `"auto"` for cross-market (routes each symbol to its loader)
- `extra_fields` should be `null` (not all markets support fundamentals)
- `leverage` defaults to 1.0 (CompositeEngine inherits from config)

## Market Detection Heuristics

| Pattern | Market |
|---------|--------|
| `000001.SZ`, `600519.SH` | A-share |
| `AAPL.US` | US equity |
| `700.HK` | HK equity |
| `BTC-USDT` | Crypto |
| `IF2406.CFFEX` | China futures |
| `ESZ4` | Global futures |
| `EUR/USD` | Forex |

## Supporting Files

- [example_signal_engine.py](example_signal_engine.py) — complete cross-market strategy example
vibe-tradingSkill

Professional finance research toolkit — backtesting (7 engines + benchmark comparison panel), factor analysis, Alpha Zoo (452 pre-built alphas across qlib158/alpha101/gtja191/academic), options pricing, 77 finance skills, 29 multi-agent swarm teams, Trade Journal analyzer, and Shadow Account (extract → backtest → render) across 7 data sources (tushare, yfinance, okx, akshare, mootdx, ccxt, futu).

adr-hshareSkill

ADR/H-share/A-share cross-listing premium analysis — track pricing gaps between US-listed ADRs, HK-listed H-shares, and A-shares for arbitrage signals, dual-listing valuation, and delisting risk assessment.

akshareSkill

AKShare financial data aggregator (18k+ stars). Free, no API key. Covers A-shares, US, HK, futures, macro, forex. Primary fallback for tushare and yfinance.

alpha-zooSkill

Browse and bench the bundled alpha zoos — prebuilt cross-sectional factor libraries (Kakushadze 101, GTJA 191, Qlib 158, Fama-French / Carhart). Use when the user asks "which alphas exist", wants metadata on a named alpha, or wants to run IC/IR on a whole zoo over a universe.

ashare-pre-st-filterSkill

A 股 ST/*ST 风险预测框架 — 基于最新中报/三季报或业绩预告/快报,预测下一财年是否会因营收、利润、净资产、分红不达标而被风险警示,并将新浪监管处罚记录作为独立证据面纳入风险等级。仅适用于 A 股,不预测财务造假。

asset-allocationSkill

Asset allocation theory and optimizer usage — MPT / Black-Litterman / risk budgeting / all-weather strategy, including guides for 4 optimizers and rebalancing rules.

backtest-diagnoseSkill

Diagnose failed or underperforming backtests, locate the root cause, and fix the issue

behavioral-financeSkill

Behavioral finance applications: theories of overreaction and underreaction, behavioral explanations for momentum and reversal, investor sentiment cycles, cognitive-bias checklists, and debiasing quantitative strategies.