1. Introduction
The economic markets are ever more dominated by systematic and data-driven decision-making. Rule-based or discretionary approaches are usually incapable of encompassing the sophistication of contemporary markets, which are shaped by not just price and volume but also macroeconomic indicators and the sentiment of investors. This work introduces the design and implementation of a machine learning-based trading system that combines both technical indicators and natural language sentiment features into actionable trading signals. The suggested system illustrates the architecture of utilizing a modular pipeline involving data ingestion, feature engineering, model training, signal generation, and risk management. By combining Histogram-Based Gradient Boosting classification for direction prediction and LightGBM regression for price prediction, the framework attains higher accuracy in both trend and magnitude estimation. Crucially, this research work focuses on risk-aware design with volatility-based position sizing, stop-loss, and portfolio-level drawdown controls integrated to preserve capital. The importance of this research lies in the fact that it is an interdisciplinary integration of machine learning, natural language processing, financial modeling, and risk theory, and thus it presents a deployable system that is theoretically valid and practically applicable.
2. Literature Review
Many recent studies in algorithmic trading have adopted machine learning and deep learning approaches but failed to conduct comprehensive time series analysis, limiting the ability to select appropriate models. Research into algorithmic trading has increasingly moved beyond purely price-based models to multimodal systems that combine numerical technical signals with textual sentiment extracted from news and social media. The rationale is that market prices embed both quantitative patterns; combining them can improve predictive performance and robustness under regime shifts. Classical machine learning and deep learning models have long used engineered technical indicators (moving averages, RSI, Bollinger Bands, MACD, etc.) as primary inputs. Studies show that augmenting raw price/time series with indicator features often improves in-sample predictive power for classification/regression tasks (directional movement or returns), and modern work explores which indicator sets add value for different frequency horizons. However, recent evaluations warn that indicator-augmented models can overfit and show weak out-of-sample generalization unless careful regularization, realistic walk-forward validation, and transaction cost modeling are used [
1].
Textual sentiment extracted from standalone news, company filings, Twitter/Stock Twits, and professional commentary has been demonstrated to carry a predictive signal for asset returns and volatility in many settings. Large-scale empirical analyses indicate that social media sentiment indices can lead to returns on certain horizons and are sensitive to macro shocks; however, predictive power varies by source, filtering, and time, and attention/volume metrics sometimes behave differently than polarity measures. Robustness depends strongly on data cleaning, domain-adapted language models, and avoiding look-ahead leakage in labeling [
2].
A growing body of literature explicitly integrates technical indicators with sentimental features. Hybrid models typically (a) compute technical features from historical price ticks/candles, (b) produce daily/intraday sentiment scores using lexicon-based or learned NLP models (including LSTM and more recently transformer variants), and (c) feed the concatenated feature vector into an ML predictor (random forest, XGBoost, LSTM, or feed-forward nets) or into an RL agent that issues portfolio actions. Empirical work generally reports improved risk-adjusted returns and better drawdown control versus single-modality baselines, particularly around news events and high-volatility periods, but the results are sensitive to dataset choice and evaluation protocols [
3]. Time series deep models such as LSTM and GRU have been widely used to capture temporal dependencies in price and sentiment streams; several recent studies have demonstrated that LSTM architectures combining news/sentiment channels and price channels produce gains over classical ML. With the rise in large language models (LLMs) and transformer architectures, newer work uses pretrained transformers or fine-tuned transformers to extract richer sentiment/contextual embeddings from news and filings, improving signal quality compared to simple lexicons or bag-of-words [
4].
Research on quantitative trading has evolved through multiple strands. Murphy (1999) and Hull (2018) [
5,
6], using a technical analysis approach, investigated traditional market indicators such as moving averages, RSI, and Bollinger Bands, which form the foundation of quantitative strategies. Pedregosa et al. (2011) [
7] introduced Scikit-learn, an open-source Python library that has become one of the most widely used frameworks for implementing machine learning algorithms. The key contribution of this work lies in providing a unified, accessible, and efficient interface for supervised and unsupervised learning methods, including regression, classification, clustering, dimensionality reduction, and model selection.
Goodfellow et al. (2016) [
8] discussed machine learning in finance and highlighted the adaptability of ML to nonlinear, high-dimensional problems. Gradient boosting methods, particularly LightGBM, as demonstrated by Ke et al. (2017) [
9], have been shown to achieve state-of-the-art performance in financial prediction due to their speed and handling of sparse features. Araci (2019) [
10], using sentiment analysis, introduced FinBERT, a transformer-based NLP model fine-tuned on financial corpora, demonstrating that textual features can meaningfully capture investor sentiment and market psychology. Dietterich (2000) [
11] and Goyal & Welch (2008) [
12], studying ensemble and hybrid approaches, argued that combining multiple models and signals yields better generalization in noisy financial environments. Grinold & Kahn (2000) [
13] and Sharpe (1994) [
14] investigated risk management in algorithmic trading to underscore the importance of integrating portfolio theory and performance measures like Sharpe and Sortino ratios to control downside risks. Chan [
15] emphasizes that systematic, algorithmic approaches outperform discretionary trading because they remove human bias, allow for reproducibility, and can be rigorously back tested.
Adams et al. [
16] built and investigated a new measure of credit and financial market sentiment using NLP on Twitter data. They found that the Twitter Fund Sentiment Index (TFWI) correlates highly with credit bond spread and other conditions [
16]. From these works, it is evident that while machine learning models improve predictive power, global optimization requires combining technical, textual, and risk-aware strategies to achieve real-world robustness.
3. Materials and Methods
This study uses a structured, modular design; key steps include data collection and processing, feature engineering, machine learning models, and trading strategy and risk management. The block diagram of the proposed model is shown in
Figure 1.
3.1. Data Ingestion and Feature Engineering
In the domain of quantitative finance and algorithmic trading, robust and clean data is the backbone of any predictive modeling system. The quality and preprocessing of input data directly influence the reliability of predictions and strategies. The model pipeline begins with acquiring historical OHLCV stock data and relevant financial indicators using technical analysis, preparing it for ingestion into machine earning models. The raw data was collected for multiple stocks from the S&P 100 index, covering the period from 2000 to 2025 via Yahoo Finance. Macroeconomic indicators like GDP growth rates, interest rates, and inflation metrics were also considered input features to make sure that the model understood the existing economic conditions. The macroeconomic data was sourced from publicly available data sets provided by FRED (Federal Reserve Economic Data) and IMF repositories. The textual data (news headlines) was scraped via NewsAPI, GoogleNews, and RSS feeds for sentiment scoring.
To extract actionable insights into raw numeric data, several technical indicators known to capture trends, momentum, and volatility characteristics were computed. The table of feature indicators and their importance is presented in
Table 1.
These indicators were appended as new features to the daily dataset; each feature was lagged appropriately to prevent lookahead bias in training. Z-score normalization was applied to continuous features to stabilize the distribution across time. For regression modeling, the target variable was taken as the future close price. For classification, the label was given by
. The binary setup supports the directional decision-making required in trading. The model interpretability plot for both datasets is presented in
Figure 2a,b, respectively.
3.2. Sentiment Analysis
Sentiment analysis is an important component of modern quantitative finance. The financial markets are not only driven by technical factors but also by human psychology, emotion, news cycles, and socioeconomic developments. Natural language processing (NLP) techniques were adopted with time series analysis to create a more robust forecasting framework that captures both behavioral and numerical signals. A large portion of market volatility is driven by speculative sentiment and news events. The NewsAPI endpoints were used for filtering high-quality sources like Bloomberg and market watch. Each headline was mapped to company and timestamped. The multistep preprocessing pipeline was applied to eliminate heavy noise signals from the data.
FinBERT (a transformer dash-based model) was used to extract sentiment from the clean headlines. For each headline, FinBERT produces a probability triplet:
The sentiment score was then computed as follows:
The scalar is continuous and lies in the range [−1, +1], where the positive value reflects optimism and the negative value indicates pessimism. To reduce noise and prioritize recent sentiment, a temporal decay function was implemented. The temporal decay function is as shown below.
This formulation ensures that recent news has more influence than older headlines, and the decay rate λ was tuned empirically.
3.3. Machine Learning Models
Modern financial markets are characterized by volatility, noise, and a high degree of interdependency between macroeconomic signals and investor behavior. In such environments, traditional time series models like ARIMA or exponential smoothing fall short due to their assumptions of linearity and stationery. The core objective is to design a trading system that emulates the decision-making architecture of quantitative hedge funds. These funds rely on predictive analysis, probabilistic reasoning, and strict management to achieve market outperformance. The system is modular, data-driven, and designed to accommodate extensions such as reinforcement learning, live trading integration, or portfolio optimization in the future.
The system solves two key machine learning problems:
Regression using LightGBM: Forecasting the future close price of a stock () based on features at time t.
Classification using HistGradientBoostingClassifier: Predicts price direction (up/down).
The model outputs are then transformed into concrete trading signals based on a volatility adjusted threshold and model confidence.
LightGBM is a gradient boosting framework that uses decision-making trees, and it uses leaf-wise tree growth for more optimal splits and faster convergence than level-wise approaches like XGBoost. At each iteration, it selects the leaf with the highest loss and splits it, which results in deeper trees but significantly better loss reduction.
Given binary labels
є {0,1}, the loss function is minimized as
where
pt is the probability output while classifying for price going up.
3.4. Trading Strategy and Risk Management
The predictions from both models are transformed into actionable signals through thresholding and consensus logic. Given predicted price change ∆^, the thresholds are defined as below:
Then, the signal is defined as follows:
where
k is the hyperparameter calibrated via backtesting.
To control trade size dynamically, we define the confidence score as follows:
The trade volume is then proportional to this confidence score.
A hard stop-loss mechanism is used to cap per-trade losses, which monitored the maximum drawdown (MDD), defined as follows:
However, the system halts new trades and enters recovery mode if the MDD exceeds the threshold value. This approach protects capital during extreme down trends or model regime failures.
5. Conclusions
It is inferred that across both stocks, the predicted prices track the actual closing prices with reasonable accuracy, especially in non-extreme market phases. While the model does slightly underperform during highly volatile transitions (such as earning announcements or macroeconomic shocks), its ability to capture directionality and short-term trends makes it a practical decision-support tool for traders. The modularity of the system allows for retraining and scaling to other securities and asset classes with minimal friction. Future improvements may include using ensemble methods, retraining real-time streaming data, volatility conditioning, and integrating external macroeconomic indicators. Such enhancements can make the prediction engine even more resilient in uncertain market conditions. The main limitation of this study is that given the high volatility and inherent noise in financial markets, a primary limitation of ML model is their tendency to overfit to a non-repeating pattern. Consequently, while ML models may identify short-term signals, they are not always the best choice for long-term predictions, as market behavior follows a random work, which is the key assumption of stochastic models.