$npx -y skills add agiprolabs/claude-trading-skills --skill feature-engineeringFeature construction from market data for ML trading models including price, volume, on-chain, and microstructure features
| 1 | # Feature Engineering for Trading ML |
| 2 | |
| 3 | Feature engineering is the single highest-leverage activity in building ML trading |
| 4 | models. Model selection (XGBoost vs. neural net vs. logistic regression) matters far |
| 5 | less than the quality and diversity of input features. A simple model on great |
| 6 | features will outperform a complex model on raw prices every time. |
| 7 | |
| 8 | This skill covers constructing, validating, and selecting features from market data |
| 9 | for use in classification (signal-classification) and regression models targeting |
| 10 | crypto/Solana token trading. |
| 11 | |
| 12 | ## Why Features Beat Models |
| 13 | |
| 14 | Raw OHLCV data is non-stationary, noisy, and high-dimensional. Models trained |
| 15 | directly on price series will overfit. Feature engineering transforms raw data into |
| 16 | stationary, informative signals that capture distinct aspects of market behavior: |
| 17 | |
| 18 | - **Compression**: Reduce thousands of price bars to dozens of descriptive statistics |
| 19 | - **Stationarity**: Convert non-stationary prices into stationary returns and ratios |
| 20 | - **Domain knowledge**: Encode trader intuition (support/resistance, volume climax) |
| 21 | as computable quantities |
| 22 | - **Regime awareness**: Features that behave differently in trending vs. ranging |
| 23 | markets help models adapt |
| 24 | |
| 25 | ## Feature Categories |
| 26 | |
| 27 | ### 1. Price Features |
| 28 | |
| 29 | Derived purely from OHLCV price columns. These capture trend, momentum, and |
| 30 | volatility from the price series itself. |
| 31 | |
| 32 | | Feature | Formula | Lookback | |
| 33 | |---------|---------|----------| |
| 34 | | `log_return` | `ln(close_t / close_{t-1})` | 1 bar | |
| 35 | | `abs_return` | `abs(log_return)` | 1 bar | |
| 36 | | `return_volatility` | `std(log_return, N)` | 20 bars | |
| 37 | | `momentum_N` | `close_t / close_{t-N} - 1` | 5, 10, 20 | |
| 38 | | `acceleration` | `momentum_5 - momentum_5[5]` | 10 bars | |
| 39 | | `high_low_range` | `(high - low) / close` | 1 bar | |
| 40 | | `close_position` | `(close - low) / (high - low)` | 1 bar | |
| 41 | | `gap` | `open_t / close_{t-1} - 1` | 1 bar | |
| 42 | | `rolling_skew` | `skew(log_return, N)` | 20 bars | |
| 43 | | `rolling_kurtosis` | `kurtosis(log_return, N)` | 20 bars | |
| 44 | |
| 45 | ### 2. Volume Features |
| 46 | |
| 47 | Volume confirms or contradicts price movements. Divergences between price and |
| 48 | volume are among the most reliable signals in short-term trading. |
| 49 | |
| 50 | | Feature | Formula | Lookback | |
| 51 | |---------|---------|----------| |
| 52 | | `volume_ratio` | `volume_t / mean(volume, N)` | 20 bars | |
| 53 | | `volume_ma_ratio` | `sma(volume, 5) / sma(volume, 20)` | 20 bars | |
| 54 | | `obv_slope` | `slope(OBV, N)` | 10 bars | |
| 55 | | `vwap_deviation` | `(close - VWAP) / VWAP` | intraday | |
| 56 | | `volume_acceleration` | `volume_ratio_t - volume_ratio_{t-1}` | 21 bars | |
| 57 | | `buy_volume_ratio` | `buy_volume / total_volume` | 1 bar | |
| 58 | | `dollar_volume` | `close * volume` | 1 bar | |
| 59 | | `volume_cv` | `std(volume, N) / mean(volume, N)` | 20 bars | |
| 60 | |
| 61 | ### 3. Technical Features |
| 62 | |
| 63 | Standard technical indicators computed via `pandas-ta`. Use the `pandas-ta` skill |
| 64 | for full parameter documentation. |
| 65 | |
| 66 | | Feature | Source | Lookback | |
| 67 | |---------|--------|----------| |
| 68 | | `rsi` | RSI(14) | 14 bars | |
| 69 | | `macd_histogram` | MACD(12,26,9) histogram | 33 bars | |
| 70 | | `bb_position` | `(close - BB_lower) / (BB_upper - BB_lower)` | 20 bars | |
| 71 | | `bb_width` | `(BB_upper - BB_lower) / BB_mid` | 20 bars | |
| 72 | | `atr_ratio` | `ATR(14) / close` | 14 bars | |
| 73 | | `adx` | ADX(14) | 14 bars | |
| 74 | | `stoch_k` | Stochastic %K(14,3) | 14 bars | |
| 75 | | `cci` | CCI(20) | 20 bars | |
| 76 | | `mfi` | MFI(14) | 14 bars | |
| 77 | | `supertrend_direction` | Supertrend direction (+1/-1) | 10 bars | |
| 78 | |
| 79 | ### 4. Microstructure Features |
| 80 | |
| 81 | Derived from trade-level data (individual swaps/transactions). Require on-chain |
| 82 | or DEX API data. |
| 83 | |
| 84 | | Feature | Description | |
| 85 | |---------|-------------| |
| 86 | | `trade_count_ratio` | Trades this bar / avg trades per bar | |
| 87 | | `avg_trade_size` | Mean trade size in USD | |
| 88 | | `large_trade_pct` | % of volume from trades > $10k | |
| 89 | | `unique_traders` | Count of distinct wallet addresses | |
| 90 | | `buy_count_ratio` | Buy trades / total trades | |
| 91 | | `trade_size_entropy` | Shannon entropy of trade size distribution | |
| 92 | |
| 93 | ### 5. On-Chain Features |
| 94 | |
| 95 | Derived from blockchain state changes. Require Helius or Solana RPC data. |
| 96 | |
| 97 | | Feature | Description | |
| 98 | |---------|-------------| |
| 99 | | `holder_count_change` | Change in unique holders over N periods | |
| 100 | | `whale_net_flow` | Net tokens moved by top-10 holders | |
| 101 | | `token_velocity` | Transfer volume / circulating supply | |
| 102 | | `liquidity_change` | Change in DEX liquidity pool TVL | |
| 103 | |
| 104 | ### 6. Cross-Asset Features |
| 105 | |
| 106 | Capture relationships between the target token and broader market. |
| 107 | |
| 108 | | Feature | Description | |
| 109 | |---------|-------------| |
| 110 | | `sol_correlation` | Rolling correlation with SOL price | |
| 111 | | `btc_beta` | Rolling beta to BTC returns | |
| 112 | | `sector_momentum` | Average return of tokens in same sector | |
| 113 | |
| 114 | ### 7. Time Features |
| 115 | |
| 116 | Cyclical encoding of calendar time. Use sin/cos encoding to preserve cyclical |
| 117 | continuity (hour 23 is close to hour 0). |
| 118 | |
| 119 | ```python |
| 120 | import numpy as np |
| 121 | |
| 122 | hour_sin = np.sin(2 * |