Skip to content
All posts

Python · Machine learning · LSTM

Building a stock signal engine for the Dhaka Stock Exchange

Kamruzzaman Akash · · 2 min read

DSE AI Trader is a quantitative analysis engine for the Dhaka Stock Exchange. Every day it produces a ranked list of BUY, SELL and HOLD recommendations, each with a target, a stop-loss and a risk note, exported as HTML, Excel and CSV.

It's also the project that taught me the most about being skeptical of my own results.

This is a learning project, not financial advice. Markets are noisy, and no model removes risk.

The pipeline

The engine runs in stages:

  1. Collect: pull market data with httpx.
  2. Analyse: compute technical indicators and fundamental ratios for each stock.
  3. Model: train an ensemble of classic ML models, plus an LSTM that looks at price sequences.
  4. Rank: combine the signals into a recommendation with a target and a stop-loss.
  5. Report: write the daily report in three formats.

Keeping the stages separate made everything easier to test and debug. When a recommendation looks strange, I can see exactly which stage produced it.

Why an ensemble and an LSTM

Tree-based models are good at tabular features like ratios and indicator values. An LSTM is built for sequences, so it can pick up patterns in how prices move over time. Using both, and comparing where they disagree, is more informative than trusting either one alone.

The traps I watch for

Machine learning on prices makes it very easy to fool yourself:

  • Look-ahead leakage. If any feature accidentally uses tomorrow's data, the model looks brilliant in testing and useless in reality. Every feature must only use information available at that moment.
  • Overfitting to one period. A model that fits one market phase perfectly often fails in the next.
  • Ignoring costs. A signal that wins on paper can lose once fees and slippage are counted.

What I'd change next

More honest backtesting across different market periods, clearer confidence scores in the report, and simpler explanations of why each stock was flagged. A recommendation you can't explain is one you shouldn't act on.

The real lesson

Building the model was the easy part. The valuable skill was learning to distrust a good-looking result until I understood where it came from.