backtest
Create a catquant backtest script.
Arguments
Parse $ARGUMENTS as: strategy symbol interval
$0= strategy (ema-crossover, rsi, macd, kdj, boll). Default: ema-crossover$1= symbol (e.g., SH600000, SZ000001). Default: SH600000$2= interval (D, 5m, 1m). Default: D
If no arguments, ask the user.
Instructions
- Read catquant-expert for workflow, API, and strategy patterns
- Create script at
backtesting/{strategy_name}/{symbol}_{strategy}_backtest.py - The script must: load data, compute signals, run backtest, export JSON, render charts, print metrics
- Explain the backtest report in plain language
Chart Rendering
Always render charts with the strategy's indicator lines. Use overlays for lines on the price chart and panels for separate indicator subplots. Pick the configuration matching the strategy:
| Strategy | overlays (on price) | panels (subplots) |
|---|---|---|
| EMA Cross | EMA fast + EMA slow lines | MACD panel (DIF/DEA lines + MACD bars + zero_line) |
| MACD | EMA(12) + EMA(26) lines | MACD panel (DIF/DEA lines + MACD bars + zero_line) |
| RSI | EMA(14) line | RSI panel (RSI line + overbought/oversold hlines) |
| KDJ | -- | KDJ panel (K/D/J lines) |
| BOLL | Upper + Mid + Lower lines + fill between upper/lower | -- |
| Custom | Any indicator lines used in signals | Relevant oscillator if applicable |
Example (EMA crossover):
ema5 = ema_series(close, 5)
ema20 = ema_series(close, 20)
dif, dea, macd = getMACDData(close)
render(result, bars, outdir, "kline",
overlays=[
{"data": ema5, "label": "EMA5", "color": "#ff9800"},
{"data": ema20, "label": "EMA20", "color": "#2196f3"},
],
panels=[{
"title": "MACD",
"lines": [
{"data": dif, "label": "DIF", "color": "#2962ff"},
{"data": dea, "label": "DEA", "color": "#ff6d00"},
],
"bars": [{"data": macd, "label": "MACD"}],
"zero_line": True,
}])
render(result, bars, outdir, "equity")
Color palette: #ff9800 (orange), #2196f3 (blue), #e040fb (purple), #00bcd4 (cyan), #8bc34a (green).
Lines: #2962ff (DIF), #ff6d00 (DEA), #e040fb (J line). Bars auto-colored red/green by sign.
Example
/backtest ema-crossover SH600000 D
/backtest macd SZ300750 5m
More from fidingks/mao-quant
maoquant
A-share quantitative backtesting skill system.
9scan
Full-market A-share stock screening.
2data
Data engine reference. Unified SecurityData from FaceCat API, TDX binary, and user CSV.
1catquant-expert
CatQuant A-share backtesting API reference and knowledge base. The single source of truth for workflow, API signatures, metrics, indicators, and strategy patterns.
1