Python Β· Streamlit Β· Event-Based ML Β· Telegram Integration
This project is an event-driven algorithmic trading analysis system built using Python, Machine Learning, and Streamlit.
It analyzes NIFTY 50 equity data, transforms raw OHLCV market data into interpretable trading events, and uses a RandomForest classifier to estimate the probability of next-day price movement.
Unlike black-box trading systems, this project prioritizes:
- β Explainability
- β Feature transparency
- β Modular architecture
- β Production-safe data handling
Outputs are visualized through an interactive Streamlit dashboard, logged to Google Sheets, and optionally accessible via a Telegram bot interface.
The system ingests daily stock data, engineers event-based features (trend shifts, breakouts, volume confirmation, momentum, volatility), and trains a RandomForest model to predict the probability that tomorrowβs closing price will be higher than todayβs.
The model does not auto-trade. It provides probabilistic decision support to help evaluate favorable market conditions.
- Daily OHLCV data via
yfinance - Data sanitization & preprocessing
- Multi-ticker support
Signals are derived from structural market conditions:
- SMA (20/50) crossover detection
- 20-day breakout logic
- Volume spike & trend confirmation
- Momentum & volatility regime detection
No fragile RSI-based heuristics.
- Model: RandomForestClassifier
- Problem Type: Supervised classification
- Target Variable:
1 β Tomorrowβs Close > Todayβs Close
0 β Otherwise
Why RandomForest?
- Handles non-linear interactions
- No feature scaling required
- Stable on tabular financial data
- Produces reliable probability estimates
- Multi-ticker selection
- Backtesting over custom date ranges
- Visualized SMA crossovers
- Buy/Sell markers
- ML accuracy display
- Indicator overlays using Plotly
Not Working!
- Signal snapshots
- Model accuracy tracking
- Optional trade journal logging
- Query crossover events
- View stock summaries
- Get signal breakdowns
- Designed for explainable outputs (not spam alerts)
Each trading day is treated as a market snapshot.
ma_crossoverstrong_trendma_diff
breakout_20dprice_sma20_diffprice_sma50_diff
volume_spikevolume_ma_ratiovolume_change- Normalized OBV
momentum_5dMACDMACD_hist
volatility_5d
The model learns which combinations historically led to upward movement.
| Layer | Technology |
|---|---|
| Language | Python β₯ 3.10 |
| Data | yfinance |
| ML | scikit-learn (RandomForest) |
| UI | Streamlit + Plotly |
| Logging | Google Sheets (gspread) |
| Alerts | Telegram Bot API |
Design Choices:
- β No
pandas-ta - β No RSI
- β Stable dependency structure
- β Fully modular architecture
algo-trading-system/
β
βββ main.py # End-to-end pipeline
βββ ui.py # Streamlit dashboard
βββ strategy.py # Event-based signal logic
βββ ml_model.py # Feature engineering + ML model
βββ sheets.py # Google Sheets logging
βββ bot.py # Telegram bot integration
βββ utils.py # Logging utilities
βββ requirements.txt
βββ .gitignore
git clone https://github.com/Aryanonghub/algo-trading-system.git
cd algo-trading-systempython -m venv venv
source venv/bin/activate # macOS/Linux
.\venv\Scripts\Activate.ps1 # Windowspip install -r requirements.txtpython -m streamlit run ui.pypython main.pypython bot.pyMake sure to set:
export BOT_TOKEN=your_telegram_token
[Streamlit UI]
|
v
[Data Fetcher - yfinance]
|
v
[Feature Engineering Engine]
|
+--> Google Sheets Logging
+--> Telegram Queries
|
v
[RandomForest Model]
|
v
[Probability Output + Visual Dashboard]
Financial prediction is inherently noisy.
Typical realistic accuracy:
55% β 65%
Anything consistently above this in live conditions is strong.
- Walk-forward validation
- Feature importance export
- Full backtesting engine (PnL, drawdown)
- Position sizing logic
- Risk management module
- Dockerization
- Unit testing
- Broker API integration (Zerodha / Upstox)
This project is for educational and research purposes only.
It does not constitute financial advice. Trading involves risk. Past performance does not guarantee future results.