Skip to content
All library documents

Using XGBoost to Forecast Daily Stock Direction in R

Article QuantInsti blog

Summary

The document introduces XGBoost as a gradient boosting method that combines decision trees sequentially, with each new tree aimed at correcting earlier prediction errors. Its objective balances predictive loss against a regularization term that discourages overly complex trees. It then outlines an R example that uses RSI, ADX, and price relative to Parabolic SAR as features, with their values lagged to reduce look-ahead bias. The target labels whether the daily open-to-close price change is positive or not.

The example divides observations in time order into training and test sets, fits a binary logistic model, and shows how to turn predicted probabilities into labels using a threshold. It also demonstrates cross-validation, classification error, feature importance, and tree visualization. The document supplies a workflow rather than evidence of a profitable strategy: it reports no specific test results, and its sample evaluation is limited to classification error. The small feature set, threshold choice, data handling, and validation design would all need further scrutiny before trading; model accuracy alone does not establish net performance after trading costs.

Key ideas

  • XGBoost adds decision trees sequentially to improve on the errors made by earlier trees.
  • Its objective combines a predictive loss with regularization that penalizes model complexity.
  • The example predicts whether a stock’s daily open-to-close move is positive using lagged technical indicators.
  • Predicted probabilities can be converted to binary labels with a chosen threshold.
  • Cross-validation and held-out testing help assess a model, but predictive accuracy does not by itself demonstrate trading profitability.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.