Skip to main content
QUICK REVIEW

[Paper Review] Transformer-Based Deep Learning Model for Stock Price Prediction: A Case Study on Bangladesh Stock Market

Tashreef Muhammad, Anika Bintee Aftab|arXiv (Cornell University)|Aug 17, 2022
Stock Market Forecasting MethodsDecision Sciences9 citations
TL;DR

This paper proposes a Transformer-based deep learning model enhanced with Time2Vec positional encoding to predict stock prices on the Dhaka Stock Exchange (DSE), using historical daily and weekly data. The model achieves low RMSE and MAE across eight DSE-listed stocks, demonstrating strong performance and feasibility for both short- and long-term investment forecasting in emerging markets.

ABSTRACT

In modern capital market the price of a stock is often considered to be highly volatile and unpredictable because of various social, financial, political and other dynamic factors. With calculated and thoughtful investment, stock market can ensure a handsome profit with minimal capital investment, while incorrect prediction can easily bring catastrophic financial loss to the investors. This paper introduces the application of a recently introduced machine learning model - the Transformer model, to predict the future price of stocks of Dhaka Stock Exchange (DSE), the leading stock exchange in Bangladesh. The transformer model has been widely leveraged for natural language processing and computer vision tasks, but, to the best of our knowledge, has never been used for stock price prediction task at DSE. Recently the introduction of time2vec encoding to represent the time series features has made it possible to employ the transformer model for the stock price prediction. This paper concentrates on the application of transformer-based model to predict the price movement of eight specific stocks listed in DSE based on their historical daily and weekly data. Our experiments demonstrate promising results and acceptable root mean squared error on most of the stocks.

Motivation & Objective

  • To address the challenge of predicting highly volatile stock prices in the Dhaka Stock Exchange (DSE), a developing market with limited prior ML research.
  • To explore the applicability of the Transformer architecture—previously dominant in NLP and vision—to time series stock price prediction in emerging economies.
  • To integrate Time2Vec positional encoding to effectively represent temporal dependencies in sequential stock data.
  • To evaluate model performance on both daily and weekly historical data for robustness and scalability.
  • To demonstrate that attention-based models can yield reliable predictions in underexplored financial markets like Bangladesh’s.

Proposed method

  • The model employs a standard Transformer encoder architecture with multi-head self-attention to capture long-range dependencies in stock price sequences.
  • Time2Vec positional encoding is applied to inject temporal information into the input embeddings, enabling the model to learn temporal patterns without relying on absolute time indices.
  • The input data consists of historical daily and weekly closing prices for eight DSE-listed stocks, preprocessed via normalization and stationarity techniques.
  • The model is trained as a regression task to predict the next day’s or week’s closing price, using mean squared error (MSE) and mean absolute error (MAE) as loss functions.
  • The training pipeline includes separate splits for training, validation, and testing to ensure generalization, with hyperparameter tuning for optimal performance.
  • Model performance is evaluated using RMSE and MAE metrics on test sets, with visual comparisons between predicted and actual prices.
Figure 1: Distribution of the EOD closing price of a selected stock, namely AGRANINS
Figure 1: Distribution of the EOD closing price of a selected stock, namely AGRANINS

Experimental results

Research questions

  • RQ1Can a Transformer-based model with Time2Vec encoding effectively predict stock price movements in the Dhaka Stock Exchange?
  • RQ2How does the model’s performance vary between daily and weekly time granularities in the DSE context?
  • RQ3What is the impact of data characteristics such as spikes and volatility on training versus validation/test error divergence?
  • RQ4To what extent can attention mechanisms capture meaningful temporal patterns in low-frequency, emerging market stock data?
  • RQ5Can the model generalize well across diverse stocks with varying price behaviors and market capitalizations?

Key findings

  • The model achieved low RMSE values on test sets, with RMSE of 6.59×10⁻² for 1JANATAMF and 1.02×10⁻¹ for AAMRANET on daily data, indicating strong predictive accuracy.
  • For weekly data, the model maintained low error rates, with RMSE of 7.70×10⁻² for 1JANATAMF and 1.72×10⁻¹ for AAMRANET, showing consistent performance across time horizons.
  • Visual analysis revealed that predicted prices closely overlapped with actual prices for most stocks (e.g., ACI, ACIFORMULA, DELTALIFE), with minimal deviation in most cases.
  • The model showed higher training error than validation/test error for some stocks (e.g., DELTALIFE), attributed to the presence of extreme peaks and valleys in the training set not present in validation data.
  • The model demonstrated robustness and generalization, with predictions remaining close to actual values even during volatile market movements, as confirmed by zoomed visualizations.
  • The results suggest that the integration of Time2Vec with Transformers enables effective modeling of temporal dynamics in financial time series, even in data-scarce emerging markets.
Figure 2: Closing price of a selected Stock, namely AGRANINS over a time window of around eight years
Figure 2: Closing price of a selected Stock, namely AGRANINS over a time window of around eight years

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.