feature-engineering
Feature construction from market data for ML trading models including price, volume, on-chain, and microstructure features
By agiprolabs · 408 installs
npx skills add agiprolabs/claude-trading-skills --skill feature-engineering
Source repository · Upstream listing
Feature Engineering for Trading ML
Feature engineering is the single highest leverage activity in building ML trading
models. Model selection (XGBoost vs. neural net vs. logistic regression) matters far
less than the quality and diversity of input features. A simple model on great
features will outperform a complex model on raw prices every time.
This skill covers constructing, validating, and selecting features from market data
for use in classification (signal classification) and regression models targeting
crypto/Solana token trading.
Why Features Beat Models
Raw OHLCV data is non stationary, noisy, and high dimensional. Models trained
directly on price series will overfit. Feature engineering transforms raw data into
stationary, informative signals that capture distinct aspects of market behavior:
Compression : Reduce thousands of price bars to dozens of descriptive statistics
Stationarity : Convert non stationary prices into stationary returns and ratios
Domain knowledge : Encode trader intuition (support/resistance, volume climax)
as computable quantities
Regime awareness : Features that behave differently in trending vs. ranging
markets help models adapt
Feature Categories
1. Price Features
Derived purely from OHLCV price columns. These capture trend, momentum, and
volatility from the price series itself.
Feature Formula Lookback
log return ln(close t / close {t 1}) 1 bar
abs return abs(log return) 1 bar
return volatility std(log return, N) 20 bars
momentum N close t / close {t N} 1 5, 10, 20
acceleration momentum 5 momentum 5[5] 10 bars
high low range (high low) / close 1 bar
close position (close low) / (high low) 1 bar
gap open t / close {t 1} 1 1 bar
rolling skew skew(log return, N) 20 bars
rolling kurtosis kurtosis(log return, N) 20 bars
2. Volume Features
Volume confirms or contradicts price movements. Divergences between price and
volume are among the most reliable signals in short term trading.
Feature Formula Lookback
volume ratio volume t / mean(volume, N) 20 bars
volume ma ratio sma(volume, 5) / sma(volume, 20) 20 bars
obv slope slope(OBV, N) 10 bars
vwap deviation (close VWAP) / VWAP intraday
volume acceleration volume ratio t volume ratio {t 1} 21 bars
buy volume ratio buy volume / total volume 1 bar
dollar volume close volume 1 bar
volume cv std(volume, N) / mean(volume, N) 20 bars
3. Technical Features
Standard technical indicators computed via pandas ta . Use the pandas ta skill
for full parameter documentation.
Feature Source Lookback
rsi RSI(14) 14 bars
macd histogram MACD(12,26,9) histogram 33 bars
bb position (close BB lower) / (BB upper BB lower) 20 bars
bb width (BB upper BB lower) / BB mid 20 bars
atr ratio ATR(14) / close 14 bars
adx ADX(14) 14 bars
stoch k Stochastic %K(14,3) 14 bars
cci CCI(20) 20 bars
mfi MFI(14) 14 bars
supertrend direction Supertrend direction (+1/ 1) 10 bars
4. Microstructure Features
Derived from trade level data (individual swaps/transactions). Require on chain
or DEX API data.
Feature Description
trade count ratio Trades this bar / avg trades per bar
avg trade size Mean trade size in USD
large trade pct % of volume from trades $10k
unique traders Count of distinct wallet addresses
buy count ratio Buy trades / total trades
trade size entropy Shannon entropy of trade size distribution
5. On Chain Features
Derived from blockchain state changes. Require Helius or Solana RPC data.
Feature Description
holder count change Change in unique holders over N periods
whale net flow Net tokens moved by top 10 holders
token velocity Transfer volume / circulating supply
liquidity change Change in DEX liquidity pool TVL
6. Cross Asset Features
Capture relationships between the target token and broader market.
Feature Description
sol correlation Rolling correlation with SOL price
btc beta Rolling beta to BTC returns
sector momentum Average return of tokens in same sector
7. Time Features
Cyclical encoding of calendar time. Use sin/cos encoding to preserve cyclical
continuity (hour 23 is close to hour 0).
Stationarity
Non stationary features will cause your model to fail on new data. A feature
is stationary if its statistical properties (mean, variance) don't change over time.
Testing for Stationarity
Use the Augmented Dickey Fuller (ADF) test:
Making Features Stationary
Non Stationary Stationary Transform
Price Log return
Volume Volume ratio (vol / avg vol)
OBV OBV slope (regression coefficient)
Holder count Holder count change
RSI Already stationary (bounded 0 100)
Dollar volume Dollar volume / rolling mean
Rule : If a feature trends upward or downward over time, it is non stationary.
Transform it into a ratio, difference, or rate of change.
Normalization
After computing features, normalize them so that all features have comparable
scales. This is critical for distance based models (KNN, SVM) and helpful for
tree models.
Method Formula When to Use
Z score (x mean) / std Gaussian like distributions
Min max (x min) / (max min) Bounded features (RSI, BB position)
Rank rank(x) / len(x) Heavy tailed distributions
Critical : Use rolling statistics for normalization. Never use full sample
mean/std — that introduces lookahead bias.
No Lookahead Guarantee
The most dangerous bug in trading ML is lookahead bias — using future information
to compute features or targets. Follow these rules absolutely:
1. Rolling calculations only : Never use .mean() or .std() on the full
series. Always use .rolling(N).mean() .
2. Shift targets forward, not features backward : The target is
close.shift( N) / close 1 (future return), not close / close.shift(N) 1
(past return used as target).
3. No future index alignment : When joining feature and target DataFrames,
verify that feature row t is paired with target row t (where target already
contains the forward shift).
4. Train/test split by time : Never random split. Always
train = data[:split idx] , test = data[split idx:] .
Feature Selection
After computing many features, select the most predictive and least redundant:
Step 1: Remove Low Variance Features
Step 2: Correlation Filter
Remove features with 0.9 correlation to another feature (keep the one with
higher target correlation):
Step 3: Feature Importance
Train a random forest and rank by importance:
Step 4: Mutual Information
Non linear alternative to correlation:
Label Creation
Labels (targets) define what the model learns to predict.
Binary Classification
Typical thresholds: 1% for 1h bars, 3% for 4h bars, 5% for daily bars.
Multi Class Classification
Regression
Binary classification is recommended for initial models — it's simpler and
more robust to noise.
Integration with Other Skills
pandas ta : Compute technical indicators that become features
birdeye api : Fetch OHLCV and trade data for feature computation
helius api : Fetch on chain data for holder/whale features
signal classification : Use engineered features as model inputs
regime detection : Regime labels as features or for regime conditional models
ohlcv processing : Clean and resample raw data before feature computation
Files
References
references/feature catalog.md — Complete catalog of ~40 features with formulas,
lookbacks, stationarity status, and interpretation notes
references/pitfalls.md — Common mistakes in trading feature engineering:
lookahead bias, overfitting, survivorship bias, data snooping, non stationarity
Scripts
scripts/build features.py — Compute 25+ features from OHLCV data with
stationarity testing and quality reporting. Supports demo mode with synthetic data
or live data via Birdeye API.
scripts/feature importance.py — Rank features by predictive power using
tree based importance and permutation importance. Identifies redundant features
via correlation analysis.