Skip to content
cccskills
FreePublished on GitHub

cross-market-strategy

Write signal generation code for backtests combining stocks, crypto, forex, and other markets. Apply market-specific indicator settings and volatility-adjusted weights, while the existing CompositeEngine handles trading calendars, shared capital, and each market's rules.

OriginalShow the original description

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

Run score Not tested

See how to install

Good for

  • Building a backtest combining stocks and crypto
  • Applying different indicator settings to each market
  • Adjusting portfolio weights for differences in volatility
  • Testing exposure changes based on cross-market correlations

Files included (2)

  • SKILL.md3.8 KB
  • example_signal_engine.py2.9 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

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.

ParameterA-ShareCryptoUS EquityForex
MA fast571010
MA slow20255030
RSI period14101414
Vol lookback20142020
Typical daily vol1-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

PatternMarket
000001.SZ, 600519.SHA-share
AAPL.USUS equity
700.HKHK equity
TD.TO, PNG.VCanada equity (TSX / TSXV)
BTC-USDTCrypto
IF2406.CFFEXChina futures
ESZ4Global futures
EUR/USDForex

Supporting Files

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

adr-hshare

FreeSummary

Compare a Chinese company's US depositary receipts, Hong Kong shares, and mainland shares after adjusting for exchange rates and share ratios. Analyze pricing gaps, valuation differences, and delisting risks to support research into its different listings.

  • Compare A-share and H-share pricing gaps
  • Measure ADR premiums against Hong Kong shares
  • Review US delisting risks and Hong Kong listing alternatives
HKUDS/Vibe-Trading36.5KUpdated Oct 23, 2026

akshare

FreeSummary

Retrieve stock prices, futures quotes, exchange rates, and economic indicators with the free Python library AKShare. The skill explains market-specific functions, symbol formats, and data preparation for analysis and testing strategies against historical data.

  • Retrieve historical prices for Chinese, US, and Hong Kong stocks
  • Collect Chinese GDP and consumer price data
  • Check futures quotes and foreign exchange rates
HKUDS/Vibe-Trading36.5KUpdated Oct 23, 2026

alpha-zoo

FreeSummary

Explore bundled libraries of investment factors, signals used to compare securities, and inspect individual formulas and metadata. Evaluate a factor or an entire library across a chosen universe and period, producing aggregate performance statistics and an HTML report.

  • Find bundled momentum or reversal factors
  • Inspect a named factor's formula and metadata
  • Compare a factor library across a chosen universe and period
HKUDS/Vibe-Trading36.5KUpdated Oct 23, 2026

Assess whether a Chinese A-share company may receive ST or *ST risk warnings next financial year. Review financial forecasts, dividends, audit opinions, and regulatory penalties, then report risk severity separately from confidence in the prediction.

  • Reviewing a Chinese A-share company's future ST risk
  • Assessing escalation risk for an existing ST or *ST stock
  • Checking revenue, equity, and dividend warning signs
HKUDS/Vibe-Trading36.5KUpdated Oct 23, 2026

asset-allocation

FreeSummary

Plan portfolio allocations across assets using risk, correlations, return forecasts, and trading costs. Compare five optimization methods, produce settings for config.json, and define rebalancing rules that adjust holdings back toward their target weights.

  • Comparing allocations across stocks, bonds, and gold
  • Choosing an optimizer based on return forecasts and correlations
  • Preparing portfolio settings for config.json
HKUDS/Vibe-Trading36.5KUpdated Oct 23, 2026

Diagnose failed or abnormal backtests, which test trading strategies on historical data. Inspect result files, strategy code, and configuration to identify bugs, make targeted repairs, rerun tests, and verify the updated metrics.

  • Investigating backtest execution errors
  • Finding why a strategy produces no trades
  • Checking delayed trades or low capital usage
HKUDS/Vibe-Trading36.5KUpdated Oct 23, 2026

See all skills by HKUDS

Report a problem with this skill