cross-market-strategy
What it does
This skill explains how to build one strategy across markets with different trading hours, currencies and volatility. It is for traders who want a single backtest covering stocks and crypto or forex together.
When to use it
- ✓When a backtest includes symbols from more than one market, such as stocks and crypto.
- ✓When different markets need different indicator settings because their volatility differs.
- ✓When you want volatility-adjusted position sizes across markets.
Skill link
https://github.com/HKUDS/Vibe-Trading/blob/main/agent/src/skills/cross-market-strategy/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agent’s skills folder.
Example of what to ask your AI
“Write a backtest strategy that trades A-shares and Bitcoin together, using settings suited to each market.”
5 new skills a week. 1 minute to read.
How it works
The agent groups each symbol by its market and applies that market's parameter set. It produces a signal for each symbol, then relies on the multi-market backtest engine to align calendars and share capital between them.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
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:
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.
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())
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
- Momentum spillover: BTC 7-day momentum as overlay for A-share tech sectors
- Risk-on/Risk-off: USD/CNH rate + VIX proxy to reduce equity exposure
- Hedging: Long A-shares + short crypto delta as tail hedge
- 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
{
"source": "auto",
"codes": ["000001.SZ", "BTC-USDT"],
"start_date": "2024-01-01",
"end_date": "2025-03-31",
"interval": "1D",
"initial_cash": 1000000,
"engine": "daily"
}
sourcemust be"auto"for cross-market (routes each symbol to its loader)extra_fieldsshould benull(not all markets support fundamentals)leveragedefaults 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 |
TD.TO, PNG.V |
Canada equity (TSX / TSXV) |
BTC-USDT |
Crypto |
IF2406.CFFEX |
China futures |
ESZ4 |
Global futures |
EUR/USD |
Forex |
Supporting Files
- example_signal_engine.py — complete cross-market strategy example
FAQ
Why not use one set of settings for all markets?
Markets differ a lot in volatility and rhythm, so one set of settings usually performs poorly.
Who handles the calendar alignment?
The multi-market backtest engine does, so the strategy only outputs signals per symbol.
Why adjust position size by volatility?
A very volatile asset such as Bitcoin would otherwise dominate the portfolio if every position were the same size.
Details
Original description by the author
Write signal_engine.py for portfolios spanning multiple markets (A-shares + crypto, equity + forex, etc.)
repo: HKUDS/Vibe-Trading
Popularity
- GitHub stars
- 37k
- Ranking position
- #7507
- License
- MIT
- Updated
- 11/1/2026
Comments
- …
More skills from this repository
vibe-trading
37kGives your agent a full finance research toolkit, covering backtests, factor analysis, options pricing and market data across many markets.
adr-hshare
37kShows your agent how to compare the price of a Chinese company listed in several markets, such as a US ADR and a Hong Kong share.
akshare
37kLets your agent pull free market data for Chinese and global stocks, futures, forex and economic indicators, with no API key needed.
alpha-zoo
37kLets your agent browse a library of ready-made stock factors and test how well a whole set of them predicts returns on a chosen market.
Similar skills
gitcrawl
394kLets your agent search a saved archive of GitHub issues and pull requests, group duplicates, and check their current status on GitHub.
slacrawl
394kLets your agent search and count messages in a local Slack archive, check how fresh that archive is, and refresh it when needed.
goplaces
394kHelps your agent search for places, get their details and reviews, and resolve place names using Google Places, with JSON output for scripts.