# Ml Strategy

Machine-learning predictive strategy based on sklearn walk-forward training, feature...

- Repository: https://github.com/HKUDS/Vibe-Trading (37375 stars)
- Category: Engineering
- License: MIT
- Last updated: 2026-11-01
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add HKUDS/Vibe-Trading --skill ml-strategy -g -a claude-code -y`
Codex: `npx skills add HKUDS/Vibe-Trading --skill ml-strategy -g -a codex -y`
Cursor: `npx skills add HKUDS/Vibe-Trading --skill ml-strategy -g -a cursor -y`
Gemini CLI: `npx skills add HKUDS/Vibe-Trading --skill ml-strategy -g -a gemini-cli -y`

## Description

Machine-learning predictive strategy based on sklearn walk-forward training, feature engineering, and signal generation. Suitable for any OHLCV data.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Machine-Learning Predictive Strategy

## Purpose

Use sklearn machine-learning models (`RandomForest` / `GradientBoosting` / `Ridge`) to predict the direction of future returns and generate trading signals. Walk-forward training is used to avoid future data leakage, and feature engineering extracts useful factors from OHLCV data.

## Signal Logic

1. **Validate input**: check OHLCV columns, minimum row count, NaN ratio, skip symbols that fail
2. **Feature engineering**: build multi-dimensional factors from raw OHLCV data (momentum, volatility, RSI, moving-average ratios, volume ratio, and more). All features are sanitized (inf removed, division-by-zero guarded)
3. **Label construction**: future N-day return > 0 is the positive class (`1`), < 0 is the negative class (`0`)
4. **Walk-forward training**: use an expanding or sliding window, train on historical data only, and roll forward day by day for prediction
5. **Signal generation**: map `predict_proba[:, 1]` to `[-1.0, 1.0]`, or use discrete signals from `predict` in `{-1, 0, 1}`. Output is guaranteed clean (no NaN, clipped to range)

## Complete SignalEngine Example

This is the recommended full pipeline. Copy and customise, safety is built in.

```python
import numpy as np
import pandas as pd
from sklearn.ensemble import RandomForestClassifier, GradientBoostingClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.preprocessing import StandardScaler


def validate_data(df: pd.DataFrame, min_rows: int = 300) -> bool:
    """Check that OHLCV data meets minimum quality for ML training.

    Args:
        df: DataFrame with DatetimeIndex.
        min_rows: Minimum number of rows required.

    Returns:
        True if data is usable.
    """
    required = {"open", "high", "low", "close", "volume"}
    if not required.issubset(df.columns):
        return False
    if len(df) < min_rows:
        return False
    if df["close"].isnull().mean() > 0.2:
        return False
    return True

The rest: https://github.com/HKUDS/Vibe-Trading/blob/HEAD/agent/src/skills/ml-strategy/SKILL.md
