| name | code-review-finance |
| description | Reviews code with awareness of financial domain pitfalls: lookahead bias, data leakage, proper decimal handling, survivorship bias, overfitting, and correct backtesting methodology. Trigger when the user requests code review of trading or financial code. |
Code Review (Finance-Aware)
Reviews code for financial-domain-specific correctness issues beyond general code quality.
Real Code Reference
tradinglearn/strategies/macd_strategy.py — generate_signals() uses .shift() to prevent lookahead; verify this is correct
tradinglearn/backtest/backtester.py — run_backtest() iterates bars sequentially; verify order
tradinglearn/pytdx2/backtest.py — BacktestEngine has its own execution loop; check for data leakage between train/test
What to Check
- Lookahead bias: verify no future data used in signal calculation (
.shift(1) is correct, raw access is suspicious)
- Data leakage: train/test split must be temporal, not random —
data[:split_date] train, data[split_date:] test
- Decimal handling: prices in cents vs yuan — K-line returns /1000, quotes return /100
- Survivorship bias: delisted stocks must be in historical universes
- Overfitting: parameter count vs data points ratio, out-of-sample validation
- Transaction costs: commission rate, slippage assumptions must be realistic
- Bid/ask spread: execution at mid-price is unrealistic for illiquid stocks
- Dividend handling: total return should include dividends
Review Process
- Read strategy logic, understand the core idea
- Trace data flow from raw prices → indicators → signals → trades
- Check temporal integrity — no peeking into future at any step
- Verify metric formulas against standard definitions
- Assess overfitting risk from parameter count and search space
- Report findings: critical / warning / suggestion