跳到正文
Skillpedia
分析与电子表格37k · #7507

cross-market-strategy

它能做什么

这项技能说明如何为交易时间、货币和波动性各不相同的多个市场制定统一的策略。适合希望用一次回测同时覆盖股票与加密货币或外汇的交易者。

适用场景

  • ✓当一次回测包含来自多个市场的标的时,例如股票和加密货币的时候。
  • ✓当不同市场的波动性不同,需要不同的指标设置的时候。
  • ✓当你希望在各市场之间使用经过波动性调整的仓位规模的时候。

技能链接

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

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/HKUDS/Vibe-Trading/blob/main/agent/src/skills/cross-market-strategy/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请编写一个同时交易 A 股和比特币的回测策略,并为每个市场使用适合它的设置。”

每周 5 个新技能,1 分钟读完。

工作原理

智能体会按市场对每个标的进行分组,并应用该市场的参数集。它会为每个标的生成信号,然后依靠多市场回测引擎对齐交易日历,并在各市场之间分配资金。

技术内容(原始 SKILL.md)

作者在 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

  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

{
  "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
TD.TO, PNG.V Canada equity (TSX / TSXV)
BTC-USDT Crypto
IF2406.CFFEX China futures
ESZ4 Global futures
EUR/USD Forex

Supporting Files

常见问题

为什么不能对所有市场使用同一套设置?

各市场的波动性和节奏差异很大,一套设置通常表现不佳。

谁负责交易日历的对齐?

由多市场回测引擎负责,因此策略只需按标的输出信号。

为什么要按波动性调整仓位规模?

如果每个仓位大小都相同,比特币这类波动很大的资产会主导整个投资组合。

详情

作者的原始描述

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

repo: HKUDS/Vibe-Trading

热度

GitHub 星标
37k
排名
#7507
许可证
MIT
更新时间
2026/11/1

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能