# Cross Market Strategy

Write signal_engine.py for portfolios spanning multiple markets (A-shares + crypto...

- Repository: https://github.com/HKUDS/Vibe-Trading (37375 stars)
- Category: Writing
- License: MIT
- Last updated: 2026-11-01
- Runs scripts: yes, review before use

## Install

Claude Code: `npx skills add HKUDS/Vibe-Trading --skill cross-market-strategy -g -a claude-code -y`
Codex: `npx skills add HKUDS/Vibe-Trading --skill cross-market-strategy -g -a codex -y`
Cursor: `npx skills add HKUDS/Vibe-Trading --skill cross-market-strategy -g -a cursor -y`
Gemini CLI: `npx skills add HKUDS/Vibe-Trading --skill cross-market-strategy -g -a gemini-cli -y`

## Description

Write signal_engine.py for portfolios spanning multiple markets (A-shares + crypto, equity + forex, etc.)

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

## When to Use

When the user requests a backtest with codes from **different markets**, e.g. `["000001.SZ", "BTC-USDT"]`, `["TD.TO", "PNG.V"]`, 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(fill_method=None).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())

The rest: https://github.com/HKUDS/Vibe-Trading/blob/HEAD/agent/src/skills/cross-market-strategy/SKILL.md
