TIN: TERAPAN INFORMATIKA NUSANTARA
Vol 6 No 12 (2026): May 2026

A Comparative Analysis of XGBoost and Random Forest for Time Series Based Stock Price Prediction with Directional Movement Evaluation

Fahmi, Andri (Unknown)
Rofiq, Nur (Unknown)



Article Info

Publish Date
10 May 2026

Abstract

Stock price prediction remains a complex task due to the dynamic nature of financial time series and the difficulty of extracting informative patterns from historical price movements. This study addresses the need to better understand whether the choice of model or the design of time series features plays a more dominant role in prediction performance. The objective of this research is to comparatively evaluate Extreme Gradient Boosting (XGBoost) and Random Forest for stock price prediction using engineered time series features, while also assessing their ability to capture directional price movements. The proposed approach applies a structured pipeline involving data preprocessing, extraction of time series features (lag, moving average, and volatility), and evaluation using a time-aware data split to preserve temporal order. Unlike conventional studies that focus solely on prediction accuracy, this research integrates both regression-based evaluation (RMSE, MAE, and R²) and directional movement analysis using confusion matrix, along with feature importance interpretation to understand model behavior. The experimental results, based on 1,258 daily stock price records, show that XGBoost achieved an RMSE of 457.97, MAE of 345.28, and R² of 0.884, while Random Forest obtained an RMSE of 462.01, MAE of 351.02, and R² of 0.882. The difference in R² (0.002 or 0.2%) indicates that both models perform comparably, with no substantial performance gap. Directional evaluation further reveals that both models are more accurate in predicting upward trends than downward movements. These findings suggest that feature engineering plays a more critical role than model selection in this context, providing a practical contribution to the development of stock prediction systems.

Copyrights © 2026