Skip to content

Latest commit

 

History

17 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Algo Trading System

A comprehensive algorithmic trading system in Python that generates buy/sell signals based on market regimes and technical/volatility strategies, sending notifications directly to a Telegram bot.

Features

  • Data Fetching: Robust downloading and local caching of stock data using yfinance.
  • Regime Detection: Combines Hidden Markov Models (HMM) and GARCH volatility forecasting to classify the market as TRENDING, RANGING, or VOLATILE.
  • Strategies:
    • Trend Following: EMA Crossover, SuperTrend, MACD, Price Breakout.
    • Mean Reversion: RSI Extremes, Bollinger Bands, Z-Score Deviation.
    • Volatility: GARCH Vol Forecast, ATR Expansion, Volatility Mean Reversion.
  • Risk Management: Position sizing based on Kelly Criterion and fractional risk, along with ATR/trailing stop losses.
  • Backtesting Engine: Vectorized backtesting for fast optimization and Walk-Forward Analysis (WFA) to ensure out-of-sample robustness.
  • Signal Delivery: Asynchronous Telegram bot integration to receive daily summaries and actionable trade alerts.

Installation

  1. Clone the repository (if applicable) and navigate to the directory:

    cd algo-trading
  2. Install dependencies:

    pip install -r requirements.txt

    (Note: TA-Lib is required by pandas-ta for some indicators. You may need to install the TA-Lib C library on your system first. On Mac: brew install ta-lib)

  3. Configure Environment: Copy the example environment file and fill in your details:

    cp .env.example .env

    Edit .env to add your Telegram bot token and chat ID.

Setup Telegram Bot

  1. Open Telegram and search for @BotFather.
  2. Send /newbot and follow the prompts to create a new bot.
  3. Copy the bot token (e.g., 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11) and add it to your .env file as TELEGRAM_BOT_TOKEN.
  4. To get your Chat ID:
    • Send any message to your new bot.
    • Visit: https://api.telegram.org/bot<YOUR_TOKEN>/getUpdates
    • Find "chat":{"id": YOUR_CHAT_ID} in the JSON response.
    • Add it to your .env file as TELEGRAM_CHAT_ID.

Usage

The system is controlled via the main.py CLI.

1. Fetch Data Fetch historical data for the US market (or specify tickers):

python main.py fetch
python main.py fetch --market ID
python main.py fetch --tickers AAPL MSFT TSLA

2. Detect Regime Analyze the current market regime for a specific stock:

python main.py regime --ticker AAPL

3. Generate Signals Run the full pipeline (data -> regime -> strategy -> risk) and generate signals based on your risk profile:

python main.py signal --profile aggressive
python main.py signal --profile conservative --notify

(Use --notify to send the generated signals to your configured Telegram bot).

Exploration

A set of Jupyter notebooks is provided in the exploration/ directory to help you understand the components, visualize data, build strategies, and run detailed backtests.

Project Structure

  • config/: System settings, risk profiles, and universes.
  • data/: Data fetching and caching layer.
  • indicators/: Technical and fundamental indicators using pandas-ta.
  • regime/: Statistical tests, HMM, and GARCH models.
  • strategies/: Implementation of all trading strategies.
  • risk/: Position sizing, stop loss, and portfolio tracking.
  • backtesting/: Backtest engine, WFA, and metrics.
  • signals/: Signal orchestrator and Telegram bot delivery.
  • exploration/: Jupyter notebooks for research.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages