Skip to content

Aryanonghub/algo-trading-system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

19 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“ˆ Algorithmic Trading System

Python Β· Streamlit Β· Event-Based ML Β· Telegram Integration


πŸ“Œ Project Overview

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.


🧠 What This System Does (In One Paragraph)

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.


πŸš€ Core Capabilities

πŸ“Š 1. Automated Data Pipeline

  • Daily OHLCV data via yfinance
  • Data sanitization & preprocessing
  • Multi-ticker support

πŸ“ˆ 2. Event-Based Strategy Engine

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.


πŸ€– 3. Machine Learning Layer

  • 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

πŸ“Š 4. Interactive Streamlit Dashboard

  • Multi-ticker selection
  • Backtesting over custom date ranges
  • Visualized SMA crossovers
  • Buy/Sell markers
  • ML accuracy display
  • Indicator overlays using Plotly

πŸ“„ 5. Google Sheets Logging

Not Working!

  • Signal snapshots
  • Model accuracy tracking
  • Optional trade journal logging

πŸ”” 6. Telegram Bot (Optional)

  • Query crossover events
  • View stock summaries
  • Get signal breakdowns
  • Designed for explainable outputs (not spam alerts)

🧩 Feature Groups Used for Prediction

Each trading day is treated as a market snapshot.

1️⃣ Trend & Structure

  • ma_crossover
  • strong_trend
  • ma_diff

2️⃣ Breakout & Price Action

  • breakout_20d
  • price_sma20_diff
  • price_sma50_diff

3️⃣ Volume Confirmation

  • volume_spike
  • volume_ma_ratio
  • volume_change
  • Normalized OBV

4️⃣ Momentum

  • momentum_5d
  • MACD
  • MACD_hist

5️⃣ Risk / Regime

  • volatility_5d

The model learns which combinations historically led to upward movement.


πŸ› οΈ Tech Stack

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

πŸ“‚ Project Structure

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

⚑ Quick Start

1️⃣ Clone the Repository

git clone https://github.com/Aryanonghub/algo-trading-system.git
cd algo-trading-system

2️⃣ Create Virtual Environment

python -m venv venv
source venv/bin/activate   # macOS/Linux
.\venv\Scripts\Activate.ps1  # Windows

3️⃣ Install Dependencies

pip install -r requirements.txt

πŸ’» Running the System

β–Ά Streamlit Dashboard (Recommended)

python -m streamlit run ui.py

β–Ά CLI Pipeline

python main.py

β–Ά Telegram Bot

python bot.py

Make sure to set:

export BOT_TOKEN=your_telegram_token

🧭 Conceptual Architecture

[Streamlit UI]
        |
        v
[Data Fetcher - yfinance]
        |
        v
[Feature Engineering Engine]
        |
        +--> Google Sheets Logging
        +--> Telegram Queries
        |
        v
[RandomForest Model]
        |
        v
[Probability Output + Visual Dashboard]

πŸ“Š Expected ML Accuracy

Financial prediction is inherently noisy.

Typical realistic accuracy:

55% – 65%

Anything consistently above this in live conditions is strong.


πŸ“… Roadmap

  • 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)

⚠️ Disclaimer

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.


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors