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:
- Collect: pull market data with
httpx. - Analyse: compute technical indicators and fundamental ratios for each stock.
- Model: train an ensemble of classic ML models, plus an LSTM that looks at price sequences.
- Rank: combine the signals into a recommendation with a target and a stop-loss.
- 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.
Keep reading
All postsRebuilding my portfolio on Next.js 16: what broke and what I learned
· 2 min read
Cache Components, a GitHub API that rate-limits you, a hydration bug in next/image, and the uncomfortable discovery that most of my demo links were dead.
Designing an escrow flow for AssignMate
· 2 min read
How I think about money moving between two strangers: a strict assignment lifecycle, a server that owns every transition, and payment callbacks that can arrive twice.