longbridge-ml-strategy
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chineselongbridge-ml-strategy
longbridge-ml-strategy
Walk-forward machine-learning framework for stock direction prediction. Fetches historical OHLCV data, engineers technical features, trains a rolling classifier (Random Forest or Gradient Boosting), generates probabilistic buy/sell signals, and evaluates backtest performance.
Response language: match the user's input language — Simplified Chinese / Traditional Chinese / English.
用于股票走势预测的滚动向前机器学习框架。获取历史OHLCV数据,构建技术特征,训练滚动分类器(Random Forest或Gradient Boosting),生成概率性买卖信号,并评估回测表现。
响应语言:匹配用户输入语言——简体中文 / 繁体中文 / 英文。
Dependencies
依赖项
Requires: , , (usually pre-installed).
Optional: or for gradient-boosting models.
If unavailable, fall back to a simpler logistic-regression model.
scikit-learnpandasnumpyxgboostlightgbm需要:、、(通常已预装)。
可选:用于梯度提升模型的或。
若上述可选依赖不可用,则退回到更简单的逻辑回归模型。
scikit-learnpandasnumpyxgboostlightgbmWhen to use
使用场景
- User asks for ML-based prediction, rolling model training, feature-importance analysis, or AI-driven entry/exit signals for a single stock.
- Triggers: "用机器学习预测 TSLA 涨跌", "NVDA random forest strategy", "walk-forward backtest AAPL".
- 用户询问基于机器学习的预测、滚动模型训练、特征重要性分析,或单只股票的AI驱动买卖信号。
- 触发示例:"用机器学习预测TSLA涨跌"、"NVDA random forest strategy"、"walk-forward backtest AAPL"。
Workflow
工作流程
-
Fetch 504 daily candles (≈ 2 years):
longbridge kline <SYMBOL> --period day --count 504 --format json -
Feature engineering (compute on rolling windows):
- MACD line and signal (EMA12 − EMA26, signal EMA9)
- RSI-14
- Bollinger Band width: (upper − lower) / mid, window 20
- Volume change rate: (vol_t − vol_{t-5}) / vol_{t-5}
- 5-day price momentum: (close_t / close_{t-5}) − 1
- Label: 1 if close_{t+5} > close_t × 1.01, 0 if < close_t × 0.99, else drop
-
Walk-forward training:
- Training window: 252 days; retrain every 60 days
- Model: or
RandomForestClassifier(n_estimators=100)GradientBoostingClassifier - Predict probability for the current bar
-
Signal generation:
- prob > 0.60 → Buy signal
- prob < 0.40 → Sell/Short signal
- Otherwise → Hold / neutral
-
Backtest metrics (on out-of-sample predictions):
- Win rate (% correct directional calls)
- Profit factor (gross profit / gross loss)
- Annualised Sharpe ratio (assuming daily rebalance)
- Max drawdown
-
Feature importance: rank top-5 features by mean decrease in impurity.
Run to confirm flag names before calling.
longbridge kline --help-
获取504根日K线(约2年数据):
longbridge kline <SYMBOL> --period day --count 504 --format json -
特征工程(基于滚动窗口计算):
- MACD线与信号线(EMA12 − EMA26,信号线为EMA9)
- RSI-14
- 布林带宽度:(上轨 − 下轨) / 中轨,窗口为20
- 成交量变化率:(vol_t − vol_{t-5}) / vol_{t-5}
- 5日价格动量:(close_t / close_{t-5}) − 1
- 标签:若close_{t+5} > close_t × 1.01则标记为1,若< close_t × 0.99则标记为0,其余情况丢弃
-
滚动向前训练:
- 训练窗口:252天;每60天重新训练一次
- 模型:或
RandomForestClassifier(n_estimators=100)GradientBoostingClassifier - 预测当前K线的走势概率
-
信号生成:
- prob > 0.60 → 买入信号
- prob < 0.40 → 卖出/做空信号
- 其他情况 → 持有 / 中性
-
回测指标(基于样本外预测):
- 胜率(方向判断正确的比例)
- 盈亏比(总盈利 / 总亏损)
- 年化夏普比率(假设每日调仓)
- 最大回撤
-
特征重要性:按杂质减少均值排序前5位特征。
调用前请运行确认参数名称。
longbridge kline --helpCLI
命令行界面(CLI)
bash
longbridge kline --help
longbridge kline <SYMBOL> --period day --count 504 --format jsonbash
longbridge kline --help
longbridge kline <SYMBOL> --period day --count 504 --format jsonOutput
输出
| Metric | 简体 | 繁體 | English |
|---|---|---|---|
| Current signal | 当前信号 | 當前訊號 | Current signal |
| Signal probability | 预测概率 | 預測概率 | Signal probability |
| Win rate | 胜率 | 勝率 | Win rate |
| Profit factor | 盈亏比 | 盈虧比 | Profit factor |
| Sharpe ratio | 夏普比率 | 夏普比率 | Sharpe ratio |
| Max drawdown | 最大回撤 | 最大回撤 | Max drawdown |
| Top features | 重要特征 | 重要特徵 | Top features |
Output: current signal box → backtest summary table → feature importance list → caveats (past performance, data snooping). Cite Longbridge Securities / 数据来源:长桥证券 / 數據來源:長橋證券.
| 指标 | 简体 | 繁体 | English |
|---|---|---|---|
| Current signal | 当前信号 | 當前訊號 | Current signal |
| Signal probability | 预测概率 | 預測概率 | Signal probability |
| Win rate | 胜率 | 勝率 | Win rate |
| Profit factor | 盈亏比 | 盈虧比 | Profit factor |
| Sharpe ratio | 夏普比率 | 夏普比率 | Sharpe ratio |
| Max drawdown | 最大回撤 | 最大回撤 | Max drawdown |
| Top features | 重要特征 | 重要特徵 | Top features |
输出顺序:当前信号卡片 → 回测汇总表格 → 特征重要性列表 → 提示说明(过往表现、数据窥探偏差)。标注Longbridge Securities / 数据来源:长桥证券 / 數據來源:長橋證券。
Error handling
错误处理
| Situation | 简体回复 | 繁體回復 | English reply |
|---|---|---|---|
| 回退到 MCP 或提示安装 longbridge-terminal | 回退到 MCP 或提示安裝 longbridge-terminal | Fall back to MCP or install longbridge-terminal |
| 请运行 | 請執行 | Run |
| 提示 | 提示安裝,降級至邏輯回歸 | Prompt install; degrade to logistic regression |
| Fewer than 252 candles | 数据不足,无法完成 walk-forward 训练 | 數據不足 | Insufficient data for walk-forward |
| Other stderr | 直接显示原始错误 | 直接顯示原始錯誤 | Surface verbatim |
| 场景 | 简体回复 | 繁体回复 | English reply |
|---|---|---|---|
| 回退到MCP或提示安装longbridge-terminal | 回退到MCP或提示安裝longbridge-terminal | Fall back to MCP or install longbridge-terminal |
| 请运行 | 請執行 | Run |
| 提示 | 提示安裝,降級至邏輯回歸 | Prompt install; degrade to logistic regression |
| K线数量不足252根 | 数据不足,无法完成walk-forward训练 | 數據不足 | Insufficient data for walk-forward |
| 其他标准错误输出 | 直接显示原始错误 | 直接顯示原始錯誤 | Surface verbatim |
MCP fallback
MCP回退方案
Use with , when CLI is unavailable.
mcp__longbridge__candlesticksperiod=Daycount=504当CLI不可用时,使用,参数设置为、。
mcp__longbridge__candlesticksperiod=Daycount=504Related skills
相关技能
- — OHLCV data source
longbridge-kline - — vol regime as an additional feature
longbridge-volatility-strategy - — cross-sectional factor signals complement
longbridge-multifactor
- — OHLCV数据源
longbridge-kline - — 将波动率状态作为额外特征
longbridge-volatility-strategy - — 横截面因子信号补充
longbridge-multifactor
File layout
文件结构
longbridge-ml-strategy/
└── SKILL.mdlongbridge-ml-strategy/
└── SKILL.md