Skip to content

End-to-end trading bot with RSI, DMA, ML predictions, Google Sheets logging, Telegram alerts, and Groq AI commentary.

Notifications You must be signed in to change notification settings

Shrutakeerti/VolatilityVortex

Repository files navigation

πŸš€ Algo-Trading System with ML, Automation, and Live Alerts

An end-to-end algorithmic trading prototype built with Python, powered by RSI + DMA strategy, enhanced with ML predictions, Google Sheets P&L tracking, Groq commentary, and Telegram alerts β€” all wrapped in a stylish Flask UI.


πŸ”§ Tech Stack

Component Stack / Tool
Strategy Logic RSI + 20DMA / 50DMA Crossover
ML Model Scikit-Learn (Decision Tree)
Stock Data Yahoo Finance via yfinance
Automation Python + Flask
Logging & P&L Google Sheets API + GCP Service
Alerts Telegram Bot API
Commentary Groq API (LLaMA3-70B Instruct)
UI HTML5 + CSS3 (Glassmorphism style)

πŸ“ˆ Strategy Logic

This project implements a hybrid technical + rule-based strategy:

  • βœ… Buy Signal Conditions:

    • RSI < 30 (oversold)
    • 20DMA crosses above 50DMA
    • Optional relaxed condition: RSI < 50 + 20DMA > 50DMA (for testing)
  • βœ… Backtest Window:

    • Last 6 months (period='6mo') using daily candles (interval='1d')
  • βœ… Backtest Output:

    • Total Trades
    • Win Count / Loss Count
    • Win Ratio
    • Total P&L

πŸ€– Machine Learning Automation

  • Model: DecisionTreeClassifier
  • Features Used:
    • RSI
    • 20DMA
    • 50DMA
    • MACD
    • Volume
  • Target: Whether next-day close is higher than today’s close
  • Train/Test Split: 80/20
  • Accuracy Output is displayed on the UI

☁️ Google Sheets Logging (via GCP)

Trade and summary logs are stored live using:

  • πŸ” A creds.json file (GCP Service Account key)
  • πŸ“Š Trade logs go to Trade_Log sheet
  • πŸ“˜ Summary stats go to Summary tab with:
    • Date
    • Total Trades
    • Wins / Losses
    • Win Ratio
    • P&L

Libraries Used:

  • gspread
  • oauth2client

πŸ“¬ Telegram Alerts

Each trade signal is pushed via Telegram Bot API in real-time:

  • Uses: requests.post to the Telegram API
  • Requires:
    • TELEGRAM_BOT_TOKEN
    • TELEGRAM_CHAT_ID

You’ll get alerts like:
πŸ“’ RELIANCE.NS BUY at 2953.25


🧠 Groq AI Commentary

Each trading cycle ends with Groq LLaMA3-based summarization:

  • Model: llama3-70b-8192
  • API: https://api.groq.com/openai/v1/chat/completions
  • Output: Smart summary of the day’s trade signals

Example:

β€œToday, RELIANCE and TCS showed promising RSI-based buy signals supported by DMA crossovers. INFY remained neutral.”


πŸ’» Flask UI (Modern 3D-Styled)

βœ… Features:

  • Responsive, animated UI
  • Glassmorphism cards
  • Color-coded trade signals
  • Display of:
    • Trade Signal Table
    • ML Model Accuracy
    • Groq Commentary

πŸ“Έ Preview

![Dashboard Screenshot](Dashboard Screenshot )

UI styled using custom CSS with:

  • backdrop-filter + -webkit-backdrop-filter for Safari support
  • Neon headings
  • Card animations and hover effects

πŸ—‚οΈ Project Structure

β”‚ β”œβ”€β”€ app.py # Flask server β”œβ”€β”€ strategy.py # RSI + DMA logic β”œβ”€β”€ ml_model.py # Decision Tree model β”œβ”€β”€ data_fetcher.py # Yahoo Finance fetcher β”œβ”€β”€ telegram_alert.py # Sends alerts β”œβ”€β”€ groq_commentary.py # Groq LLM summary β”œβ”€β”€ google_sheets.py # Google Sheets logging via GCP

β”‚ β”œβ”€β”€ static/ β”‚ └── style.css # UI styling (glassmorphism) β”‚

β”œβ”€β”€ templates/ β”‚ └── index.html # Frontend dashboard β”‚

β”œβ”€β”€ creds.json # GCP service account key └── .env # Secrets (API keys, tokens)


πŸ”‘ Environment Setup

Create a .env file with:

GROQ_API_KEY=your_groq_api_key
GOOGLE_SHEET_NAME=YourSheetName
TELEGRAM_BOT_TOKEN=your_bot_token
TELEGRAM_CHAT_ID=your_chat_id

πŸš€ How to Run

# Step 1: Install dependencies
pip install -r requirements.txt

# Step 2: Run the Flask app
python app.py

# Visit the dashboard at:
http://localhost:5000

βœ… 10. Demo Videos Section

## πŸ“Ή Demo Videos

| Demo Type                | Link                         |
|--------------------------|------------------------------|
| πŸ“½οΈ Strategy & Code Flow | [Watch on Google Drive](#)   |
| πŸ“Š Output + Google Sheets | [Watch on Google Drive](#)  |

βœ… Deliverables Checklist

  • βœ… RSI + DMA strategy logic
  • βœ… 6-month backtesting
  • βœ… Decision Tree prediction
  • βœ… Google Sheets automation
  • βœ… Telegram alerts
  • βœ… Groq-generated insights
  • βœ… Modern web UI
  • βœ… Modular, well-documented code

πŸ™Œ Author

Shrutakeerti β€” For any updates please contract through the given links πŸ”— GitHub Β Β  πŸ“¬ Telegram Β Β  πŸ’Ό LinkedIn

πŸ“ƒ License

MIT License – use this as a template, study tool, or launchpad for your own bots.

β€œSystems trade logic. Traders trade emotion. Bots don’t care.”

About

End-to-end trading bot with RSI, DMA, ML predictions, Google Sheets logging, Telegram alerts, and Groq AI commentary.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published