← Blog

DeepDse: Predicting the Dhaka Stock Exchange with Transformers, LSTMs and GRUs

How we combined a Transformer encoder with LSTM and GRU layers, added gold, oil and USD prices as inputs, and got the lowest error on all 11 DSE stocks we tested.

0
Table of contents

Our first Dhaka Stock Exchange paper combined an LSTM, GARCH and linear regression, and it clearly beat each of them on its own. It still only looked at the stock’s own price history, though. Bangladesh’s market also moves with things outside any one ticker: the taka against the dollar, fuel prices, and gold as a safe haven. DeepDse, published at IEEE CCWC 2023, was our attempt to give a deep model that wider view.

What “multi-modal” means here

In this paper, multi-modal means several kinds of time series that share one timeline. Next to each stock’s daily open, high, low, close and volume, we added:

  • Commodity prices: the buying price of gold, silver and oil.
  • Currency: the buying and selling price of the US dollar.
  • Technical indicators: EMAs of the high and low, VWAP, MACD, Supertrend, RSI, AROON and the accumulation/distribution index (ADI).
  • Simple moving averages over 7, 10, 15, 20 and 30 days, plus log and percentage returns.

We extended the DSE data to cover 2007 to 2022 and merged it with the commodity and currency data. That gave almost 2 million rows, a much larger dataset than earlier DSE forecasting work had used.

Workflow diagram: raw data, preprocessing, feature extraction, scaling, train/test separation, model training and test accuracy
The end-to-end pipeline, from raw CSV files to test-set accuracy.
Bank sector closing price from 2007 to 2021, peaking around 2011 and again in 2018
The bank sector over 15 years: a bubble in 2010–11, a long decline, and a smaller rally in 2018.

Why Transformer, LSTM and GRU together

Each block in the network handles a different part of the job:

  • The Transformer encoder uses self-attention to look at the whole input window at once. It can connect today to any earlier day without passing information through every step in between.
  • The LSTM carries a memory cell with gates, which suits slow, long-running trends.
  • The GRU does similar work with fewer parameters. It trains faster and adds temporal modelling without much extra cost.
DeepDse architecture: processed data flows through a Transformer encoder layer, an LSTM layer, two GRU layers with dropout and dense layers, global average pooling, and dense output layers
DeepDse: Transformer encoder (512) → LSTM (1000) → GRU (500) → GRU (100) → pooling and dense layers.
Stack of layers inside the transformer encoder block: normalization, attention, dropout, LSTM, dense, GRU, Conv1D
Inside one Transformer encoder block.

The Transformer encoder is a custom block. It applies layer normalisation and multi-head self-attention with dropout, then LSTM, GRU and dense layers, and finally two 1D convolutions. A residual connection adds the block’s input back to its output, so it can refine the signal without losing it. We stack several of these blocks before the recurrent layers.

Training details that mattered

  • A 70/30 train/test split, MinMax scaling to 0–1, and windows built with TimeseriesGenerator.
  • A learning-rate warm-up: the rate climbs from 1e-6 to 1e-3 over 30 epochs, then decays linearly to 5e-5 over the next 100. Attention layers are unstable early in training, and the warm-up keeps them steady.
  • MSE loss, batch size 20, 20% of the training data held out for validation, and a 1,000-epoch limit with early stopping to end training once validation loss stopped improving.
  • Global average pooling before the dense head, so the output doesn’t overfit to particular timesteps.

Results

We tested on the same 11 stocks as our first paper and compared DeepDse against a stacked Transformer, a GRU and an LSTM on their own. RMSE here is on the 0–1 scaled prices, so these numbers can’t be compared directly with the first paper’s.

Test-set RMSE per stock on scaled prices. Lower is better; the best score in each row is bold.
StockTransformerGRULSTMDeepDse
AB Bank0.04650.05770.06590.0458
AMCL (PRAN)0.01520.06820.07710.0112
Apex Tannery0.06310.06970.08890.0195
BD Finance0.02620.04100.04630.0183
Grameenphone0.03380.04260.09420.0233
Padma Oil0.03390.06440.07290.0137
Popular Life0.02430.05280.08470.0231
Samorita0.02050.02450.02750.0140
RAK Ceramics0.01850.03190.06620.0176
GBB Power0.01340.01670.06210.0133
Beximco0.02290.03360.04310.0228
Mean0.02890.04570.06630.0202

DeepDse had the lowest RMSE on all 11 stocks. The size of the gain varied a lot. On Apex Tannery it cut the Transformer’s error by about two thirds (0.0631 → 0.0195), and on Padma Oil by more than half. On GBB Power and Beximco the stacked Transformer was already almost as good, and the hybrid improved it only in the fourth decimal place.

The ranking of the single models was consistent too: the Transformer beat GRU, and GRU beat LSTM, on every stock. Attention clearly helps on this data. Adding the recurrent layers on top of it helped more.

Padma Oil actual versus predicted closing price, the two lines almost overlapping
Padma Oil
Beximco actual versus predicted closing price, including a sharp late-2020 rally
Beximco
Popular Life actual versus predicted closing price
Popular Life
AB Bank actual versus predicted closing price
AB Bank

Actual and predicted closing prices on the test set. The model even follows Beximco’s sharp late-2020 rally, though with a day-ahead target it is reacting to the move more than calling it in advance.

Limitations and next steps

  • Ablations. We didn’t isolate how much of the gain comes from the commodity and currency data versus the architecture. Training the same model on price-only data would answer that.
  • Baselines and validation. A naive "tomorrow equals today" baseline and walk-forward testing across market regimes would make the gains more convincing.
  • Richer inputs. Company fundamentals (P/E, earnings, market cap relative to peers), price-action patterns and news sentiment are all natural next inputs.

Takeaways

  • Attention plus recurrence did better than either one alone on every stock we tested.
  • Putting macro signals like gold, oil and the dollar on the same timeline as prices is cheap to do, and it gives the model context no single ticker has.
  • For attention-based models, a learning-rate warm-up and early stopping are needed, not optional.

Newsletter

Enjoyed this? Get the next one by email

A short email when I publish something new on AI agents, ERP automation or research. No spam; unsubscribe in one click.

Comments (0)

You’ll sign in when you post. Only your name and photo are shown.

Comments are checked by AI before they appear. Read the rules
  • Be respectful: no insults, harassment, hate or threats. Disagreeing is fine.
  • No spam: no ads, self-promotion, SEO or affiliate links, crypto or gambling.
  • Nothing sexual, violent or illegal, and no scams or malware.
  • Don't share anyone's personal details (phone numbers, addresses, private emails).
  • Keep it a real comment: no gibberish, test text or messages aimed at the AI.

Loading comments…

More from Omor Al Tanim

See all posts →