Next Article in Journal
A Blockchain-Based Machine Learning Approach for Authentic Healthcare Support Information Systems
Previous Article in Journal
A Multiscale Convolutional Neural Network Framework for Automated Segmentation and Pattern Mapping of Psoriatic Lesions
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Proceeding Paper

Machine Learning Framework for Algorithmic Trading †

by
Krishnamurthy Nayak
1,
Supreetha Balavalikar Shivaram
1,* and
Sumukha K. Nayak
2
1
Department of Electronics and Communication Engineering, Manipal Institute of Technology, Manipal Academy of Higer Education, Manipal 576104, Karnataka, India
2
Birla Institute of Technology & Science (BITS Pilani), Pilani Campus, Pilani 333031, Rajasthan, India
*
Author to whom correspondence should be addressed.
Presented at the First International Conference on Computational Intelligence and Soft Computing (CISCom 2025), Melaka, Malaysia, 26–27 November 2025.
Comput. Sci. Math. Forum 2025, 12(1), 12; https://doi.org/10.3390/cmsf2025012012
Published: 22 December 2025

Abstract

Present financial markets are characterized by great volatility and nonlinear dynamics since they are driven by both quantitative forces and qualitative mood. Traditional trading practices cannot capture such nuance. This study proposes an automated trading system based on machine learning that uses technical analysis as well as sentiment factors for better decision-making. Historical OHLCV stock price data from 2000 to 2025 was augmented with financial indicators such as SMA, EMA, RSI, and Bollinger Bands, as well as sentiment scores based on real-time news via natural language processing. LightGBM regression for predicting the price range and Histogram-Based Gradient Boosting classification for directional prediction were employed. Signals were generated with volatility-adjusted thresholds and classifier confirmation, and a risk management layer enforced position sizing, stop-loss triggering, and drawdown constraint. Back testing demonstrated improved Sharpe ratio, Sortino ratio, and win rates versus baseline strategies. The findings emphasize that the combination of machine learning and sentiment analysis with risk-conscious design improves predictive accuracy, dependability, and preservation of capital in automated trading systems.

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 l a b e l = {   1   i f   C l o s e t + 1 >   C l o s e t   ,   0   o t h e r w i s e } . 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:
[ P p o s i t i v e ,   P N e u t r a l ,   P N e g a t i v e ] .
The sentiment score was then computed as follows:
S = P p o s i t i v e   P N e g a t i v e
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.
S ( t ) = i = 1 N S i . e x p ( λ ( t t i ) )
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 ( y t + 1 ) 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 z t є {0,1}, the loss function is minimized as
£ θ = t = 1 T z t log ( p t ) + ( 1 z t ) log ( 1 p t )
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:
θ + = µ Δ + k · σ Δ   θ = µ Δ k · σ Δ
Then, the signal is defined as follows:
s i g n a l = B u y   i f   Δ y > θ +   s e l l   i f   Δ y < θ   H o l d   o t h e r w i s e
where k is the hyperparameter calibrated via backtesting.
To control trade size dynamically, we define the confidence score as follows:
c o n f i d e n c e t =   α · Δ y t + β · P t 0.5
The trade volume is then proportional to this confidence score.
The   position   size = c o n f i d a n c e   s c o r e   v o l a t i l i t y * R i s k   F a c t o r
A hard stop-loss mechanism is used to cap per-trade losses, which monitored the maximum drawdown (MDD), defined as follows:
M D D = max t€ 0 , T ( P p e a k P t P p e a k )
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.

4. Results

It is the process of analyzing the performance of the system via back tests applied to large-cap stocks (MSFT, AAPL) that encapsulates the performance and efficacy of the machine learning-based trading system implemented. It is centered on the model’s capacity to forecast stock price movements and considers the outcome based on visual accuracy and readability.

4.1. Predicted vs. Actual Close Prices

To test the reliability of the trading system, we cross-checked forecasted close prices with real market data for two blue-chip stocks: Microsoft Corporation (MSFT) and Apple Inc. (AAPL). These comparisons provide us with an idea of the model’s capacity to learn significant patterns from past data, technical indicators, and sentiment-augmented signals.

4.1.1. Dataset 1: MSFT (Microsoft Corporation)

Figure 3 shows the predicted versus actual close prices for Microsoft. The model’s forecast is very close along the actual price path over a multi-month period. The model picks up both the long-term trends and short-term reversals nicely. The sudden spike in prices throughout the early stages of May is accurately forecast, and the subsequent plateau stage is modeled highly stably.
The proximity of the predicted and actual lines in this plot indicates the generalizability of the model from its training set. This performance also demonstrates the usefulness of technical features in detecting local minima and breakout areas, which is critical in automated trading strategies.

4.1.2. Case Study 2: AAPL (Apple Inc.)

Figure 4 illustrates Apple’s comparison. The model tracks price movements quite well, particularly in calm market areas. In periods of volatile segments, though there are small discrepancies, the forecast retains overall directional correctness. For example, the sudden dip towards the end of March is partially reflected, which means that the model reacts to powerful trends but filters noise.
The outcomes confirm the use of technical indicators (MACD, RSI, SMA) and sentiment-based signals from FinBERT. The FinBERT sentiment engine with exponential weighting decay provided greater emphasis on recent news, without loss of generality with respect to steep market changes and making the model sensitive to changing investor attitudes.
The error plot histograms for MSFT and AAPL are presented in Figure 5a,b, respectively.
The distribution of residuals from the model approximates the normal distribution centered around zero, indicating that the model predictions are unbiased. This suggests that the model’s errors are random, with small errors occurring frequently and large errors being rare.
The confusion matrix and ROC for the classification model are given in Figure 6 and Figure 7, respectively.
Based on the confusion matrix, the model demonstrates a strong ability to correctly predict stock price movements, with a high proportion of true positives and true negatives. This indicates that the classifier is effective at identifying both up and down days.
The ROC curve shown above depicts the diagnostic ability of a binary classifier as its discrimination threshold is varied. The main inference from an ROC curve is the trade-off between correctly identifying positive cases and avoiding false alarms. The area under the curve (AUC) of 1 depicts the perfect classifier, and the AUC of 0.5 represents the classifier that performs no better than random guessing. Based on the analysis, the classifier for AAPL demonstrates superior predictive performance with an AUC of 0.79, outperforming the MSFT classifier with an AUC of 0.69.

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.

Author Contributions

Study conception and design, financial strategy, and data processing: S.K.N.; acquisition, analysis, implementation, and interpretation of data: S.K.N. and S.B.S.; drafting of manuscript and machine learning: S.B.S.; risk management: K.N. and S.K.N.; critical revision: K.N. All authors have read and agreed to the published version of the manuscript.

Funding

This research received no external funding.

Institutional Review Board Statement

Not applicable.

Informed Consent Statement

Not applicable.

Data Availability Statement

The data was sourced from Yahoo Finance comprising historical data dating from 1998 to 2024.

Conflicts of Interest

The authors declare no conflicts of interest.

References

  1. Mostafavi, S.M.; Hooman, A.R. Key technical indicators for stock market prediction. Mach. Learn. Appl. 2025, 20, 100631. [Google Scholar] [CrossRef]
  2. Guo, K.; Xie, H. Deep learning in finance assessing twitter sentiment impact and prediction on stocks. Per Comput. Sci. 2024, 10, e2018. [Google Scholar] [CrossRef] [PubMed]
  3. Liu, H.; Lin, Z.; Rojas, R.R. Enhancing Trading Performance Through Sentiment Analysis with Large Language Models: Evidence from the S&P 500, Trading and Market Microstructure. arXiv 2025, arXiv:2507.09739. [Google Scholar] [CrossRef]
  4. Rather, A.M. LSTM-based Deep Learning Model for Stock Prediction and Predictive Optimization Model. EURO J. Decis. Process. 2021, 9, 100001. [Google Scholar] [CrossRef]
  5. Murphy, J.J. Technical Analysis of the Financial Markets; New York Institute of Finance: New York, NY, USA, 1999. [Google Scholar]
  6. Hull, J.C. Options, Futures, and Other Derivatives, 10th ed.; Pearson Education: New York, NY, USA, 2018. [Google Scholar]
  7. Pedregosa, F.; Varoquaux, G.; Gramfort, A.; Michel, V.; Thirion, B.; Grisel, O.; Blondel, M.; Prettenhofer, P.; Weiss, R.; Dubourg, V.; et al. Scikit-learn: Machine learning in Python. J. Mach. Learn. Res. 2011, 12, 2825–2830. [Google Scholar]
  8. Goodfellow, I.; Bengio, Y.; Courville, A. Deep Learning; MIT Press: Cambridge, MA, USA, 2016. [Google Scholar]
  9. Ke, G.; Meng, Q.; Finley, T.; Wang, T.; Chen, W.; Ma, W.; Liu, T.-Y. LightGBM: A highly efficient gradient boosting decision tree. NeurIPS 2017, 30, 3146–3154. [Google Scholar]
  10. Araci, D. FinBERT: Financial sentiment analysis with pre-trained language models. arXiv 2019, arXiv:2006.00695. [Google Scholar]
  11. Dietterich, T.G. Ensemble methods in machine learning. In International Workshop on Multiple Classifier Systems; Springer: Berlin/Heidelberg, Germany, 2000. [Google Scholar]
  12. Goyal, A.; Welch, I. A comprehensive look at the empirical performance of equity premium prediction. Rev. Financ. Stud. 2008, 21, 1455–1508. [Google Scholar]
  13. Sharpe, W.F. The Sharpe ratio. J. Portf. Manag. 1994, 21, 49–58. [Google Scholar] [CrossRef]
  14. Grinold, R.C.; Kahn, R.N. Active Portfolio Management; McGraw Hill: Columbus, OH, USA, 2000. [Google Scholar]
  15. Chan, E. Algorithmic Trading: Winning Strategies and Their Rationale; Wiley: Hoboken, NJ, USA, 2013. [Google Scholar]
  16. Adams, T.; Ajello, A.; Silva, D.; Francisco Vazquez-Grande, F. More than Words: Twitter Chatter and Financial Market Sentiment. Available online: https://www.federalreserve.gov/econres/feds/files/2023034pap.pdf (accessed on 1 December 2025).
Figure 1. Block diagram of proposed model.
Figure 1. Block diagram of proposed model.
Csmf 12 00012 g001
Figure 2. Model Interpretability plot: (a) Apple; (b) Microsoft.
Figure 2. Model Interpretability plot: (a) Apple; (b) Microsoft.
Csmf 12 00012 g002aCsmf 12 00012 g002b
Figure 3. Actual vs. predicted closing prices (MSFT).
Figure 3. Actual vs. predicted closing prices (MSFT).
Csmf 12 00012 g003
Figure 4. Actual vs. predicted closing prices (AAPL).
Figure 4. Actual vs. predicted closing prices (AAPL).
Csmf 12 00012 g004
Figure 5. Error plot histogram for (a) MSFT and (b) AAPL.
Figure 5. Error plot histogram for (a) MSFT and (b) AAPL.
Csmf 12 00012 g005
Figure 6. Confusion matrix for MSFT and AAPL.
Figure 6. Confusion matrix for MSFT and AAPL.
Csmf 12 00012 g006
Figure 7. ROC curve for MSFT and AAPL.
Figure 7. ROC curve for MSFT and AAPL.
Csmf 12 00012 g007
Table 1. Table of feature indicators and their importance.
Table 1. Table of feature indicators and their importance.
Financial Indicator Importance
SMA, EMATrend detection
RSIOverbought/oversold Signals
MACDMomentum/trend reversal
Bollinger BandsVolatility and price extremes
MACE Buy/sell Logic
Sentiment ScorePrice variation due to news
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Share and Cite

MDPI and ACS Style

Nayak, K.; Balavalikar Shivaram, S.; Nayak, S.K. Machine Learning Framework for Algorithmic Trading. Comput. Sci. Math. Forum 2025, 12, 12. https://doi.org/10.3390/cmsf2025012012

AMA Style

Nayak K, Balavalikar Shivaram S, Nayak SK. Machine Learning Framework for Algorithmic Trading. Computer Sciences & Mathematics Forum. 2025; 12(1):12. https://doi.org/10.3390/cmsf2025012012

Chicago/Turabian Style

Nayak, Krishnamurthy, Supreetha Balavalikar Shivaram, and Sumukha K. Nayak. 2025. "Machine Learning Framework for Algorithmic Trading" Computer Sciences & Mathematics Forum 12, no. 1: 12. https://doi.org/10.3390/cmsf2025012012

APA Style

Nayak, K., Balavalikar Shivaram, S., & Nayak, S. K. (2025). Machine Learning Framework for Algorithmic Trading. Computer Sciences & Mathematics Forum, 12(1), 12. https://doi.org/10.3390/cmsf2025012012

Article Metrics

Back to TopTop