ワンクリックで
strategy-generate
Create, modify, and optimize quantitative trading strategies, then backtest and evaluate them.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Create, modify, and optimize quantitative trading strategies, then backtest and evaluate them.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
| name | strategy-generate |
| description | Create, modify, and optimize quantitative trading strategies, then backtest and evaluate them. |
| category | strategy |
config.jsoncode/signal_engine.py (following the SignalEngine contract)bash("python -c \"import ast; ast.parse(open('code/signal_engine.py').read()); print('OK')\"")backtest tool (built into the engine; no need to write run_backtest.py)artifacts/metrics.csv and judge by the review criteriaedit_file → run backtest → re-evaluateYou only need to write signal_engine.py and config.json. The backtest tool automatically handles data loading and backtest execution.
Extract the following from the user's description:
2026-03-18, then start_date=2016-03-18, end_date=2026-03-18)If critical information is missing, you must ask the user instead of guessing:
Write config.json first, then write code. config.json must be placed in the root of run_dir.
Before writing code, think through these 5 questions:
pe/pb/roe as well?), data frequency (daily), and market (which determines the data source)There is no need to output a JSON design document. Express these design decisions directly in code.
SignalEngine Contractclass SignalEngine:
def generate(self, data_map: Dict[str, pd.DataFrame]) -> Dict[str, pd.Series]:
"""
Args:
data_map: code -> DataFrame (columns: open, high, low, close, volume, DatetimeIndex)
If config.extra_fields is specified, pe, pb, roe, and similar columns will also be present.
Returns:
code -> signal Series, value range [-1.0, 1.0]
1.0 = fully long, 0.5 = half position, 0.0 = flat, -1.0 = fully short
Portfolio strategy: selected stocks split weights equally (for example top 10 -> each 0.1)
Legacy integer signals {-1, 0, 1} remain compatible (treated as -100% / 0% / 100%)
"""
Hard constraints:
Series index must align exactly with the input DataFrame indexnumpy, pandas, and so on)config.json)if __name__ == "__main__" blockSelf-check after writing signal_engine.py:
numpy, pandas, typing, and so on)fillna(0) or skip[-1.0, 1.0]600/601/603 → .SH, all others → .SZ.US, such as AAPL.US (yfinance converts automatically).HK, such as 700.HK (yfinance converts automatically)BTC-USDT format (OKX spot pairs, must use the hyphen -, not slash /)
BTC/USDT, but config.json must use "BTC-USDT"XXX-USDT (uppercase + hyphen), such as BTC-USDT and ETH-USDT"okx"null (OKX does not support fundamentals)DataLoader has already normalized the output to match China A-shares exactly: open, high, low, close, volume + DatetimeIndexsignal_engine.py should be written the same way as for China A-shares; do not add extra data conversion for OKX| Pattern | Market | source | Extra Fields |
|---|---|---|---|
^\d{6}\.(SZ|SH|BJ)$ | China A-shares | tushare | pe, pb, pe_ttm, ps_ttm, dv_ttm, total_mv, circ_mv, roe |
^[A-Z]+\.US$ | US stocks | yfinance | - |
^\d{3,5}\.HK$ | Hong Kong stocks | yfinance | - |
^[A-Z]+-USDT$ | Cryptocurrency | okx | - |
extra_fields selection logic: only China A-shares (tushare) support fundamentals. If the strategy needs PE/PB/ROE and similar fields, specify them in config.json.extra_fields and DataLoader will retrieve them automatically. Hong Kong stocks, US stocks, and crypto do not support extra_fields.
config.json Format{
"source": "auto",
"codes": ["000001.SZ"],
"start_date": "2016-03-18",
"end_date": "2026-03-18",
"interval": "1D",
"initial_cash": 1000000,
"commission": 0.001,
"extra_fields": null,
"optimizer": null,
"optimizer_params": {},
"engine": "daily",
"validation": null
}
source: "auto" (recommended, auto-select by code format) / "tushare" / "yfinance" / "okx" / "akshare" / "ccxt"
"auto" supports mixed instruments. For example, ["000001.SZ", "BTC-USDT"] will be automatically routed to tushare and okx"IF2406.CFFEX", "ESZ4") and forex pairs (e.g. "EUR/USD") are also auto-routedinterval: candlestick interval, default "1D". Supported values: "1m" / "5m" / "15m" / "30m" / "1H" / "4H" / "1D"
source (252 trading days for China A-shares, 365 calendar days for crypto)1m, or 1 year for 1Hextra_fields: China A-shares can use values such as ["pe", "pb", "roe"]; other markets should use nulloptimizer: optional, one of "equal_volatility" / "risk_parity" / "mean_variance" / "max_diversification" / null (equal-weight by default)optimizer_params: optimizer parameters, such as {"lookback": 60}. mean_variance additionally supports {"risk_free": 0.0}engine: backtest engine, default "daily". For options strategies, set "options" (requires OptionsSignalEngine)initial_cash: default 1,000,000commission: default 0.1%validation: optional statistical validation after backtest completes. Omit to skip. Example:
"validation": {
"monte_carlo": {"n_simulations": 1000},
"bootstrap": {"n_bootstrap": 1000, "confidence": 0.95},
"walk_forward": {"n_windows": 5}
}
monte_carlo: permutation test — shuffles trade order to compute p-value (is Sharpe significantly better than random?)bootstrap: resamples daily returns to compute Sharpe 95% confidence intervalwalk_forward: splits equity curve into N windows, checks performance consistencypython -m backtest.validation <run_dir>passed=false)artifacts/metrics.csv exists and is non-emptyartifacts/equity.csv exists and is non-emptyexit_code == 0 (backtest exits normally)equity column in equity.csv contains no NaN valuestrade_count > 0 (zero trades = signal bug)score ≥ 60 → passedscore ≥ 60 = passed=truetrade_count=0): signal-logic bug, conditions may be too strictaction_items FormatIf improvements are needed after evaluation, write action_items:
"Change X from A to B" or "Add X logic in signal_engine.py""Change short MA from 5 to 10 days to reduce whipsaw signals""Add stop-loss: force close when loss exceeds 5%""Add volume filter in signal_engine.py: only trigger buy on high volume"When the user requests a backtest with codes from different markets (e.g. ["000001.SZ", "BTC-USDT"]):
source: "auto" in config.jsonCompositeEngine handles calendar alignment, shared capital, and per-market rules automatically券商研报分析助手,聚焦"研报获取→结构化提取→多机构观点对比→风险识别→决策辅助"。使用时机:汇总个股券商研报、追踪行业研报、对比多机构观点、识别卖方利益冲突、验证研报时效性。默认数据源为东方财富研报中心公开接口(无需 API Key)。
Asset allocation theory and optimizer usage — MPT / Black-Litterman / risk budgeting / all-weather strategy, including guides for 4 optimizers and rebalancing rules.
Correlation and cointegration analysis — co-movement discovery, deep return-correlation analysis, sector clustering, realized correlation, Engle-Granger / Johansen cointegration, half-life, Kalman dynamic hedge ratio, cross-market linkage analysis, and pair-trading signal generation
Data source selection decision tree. Load this skill BEFORE any backtest or data-fetching task to choose the best available data source.
Event-driven strategy based on sentiment-scored signals from news, announcements, and macro events. The LLM acts as the NLP engine, and event data follows a CSV schema.
Factor research framework with IC/IR analysis, quantile backtesting, and factor combination. Suitable for cross-sectional factor evaluation across multiple instruments.