Write signal_engine.py for portfolios spanning multiple markets (A-shares + crypto, equity + forex, etc.)
The canonical home for this skill is cross-market-strategy in HKUDS/Vibe-Trading
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.
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 signalsDifferent 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% |
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().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{
"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)| 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 |
b612402
Canonical home
since Jul 24, 2026
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.