Skip to content

umanggkhhatri/Pathway_InterIIT

Repository files navigation

Cryptocurrency Trading Analysis Project

A comprehensive cryptocurrency trading analysis project that combines AI-powered price prediction with hybrid trading strategies for Bitcoin (BTC-USD).

📋 Project Overview

This project consists of two main components:

  1. AI Predictor (prediction.py) - Uses XGBoost machine learning to predict cryptocurrency price movements
  2. Hybrid Trading Strategy (strategy.py) - Implements a sophisticated trading strategy combining technical indicators

🚀 Features

AI Predictor (prediction.py)

  • Machine Learning Model: XGBoost Regressor with early stopping for robust predictions
  • Feature Engineering: Creates lagged return features for time series prediction
  • Model Evaluation: Calculates directional accuracy and generates prediction vs actual price plots
  • Visualization: Generates comprehensive charts showing predicted vs actual prices

Hybrid Trading Strategy (strategy.py)

  • Multi-Indicator Approach: Combines Moving Averages, Bollinger Bands, and RSI
  • Trend Following: Uses 200-day MA for macro trend identification
  • Mean Reversion: Bollinger Bands for entry/exit signals
  • Momentum Confirmation: RSI for trade confirmation
  • Risk Management: Built-in stop-loss and profit-taking mechanisms

🛠️ Technical Indicators Used

AI Predictor

  • Lookback Period: 14 days of historical returns
  • Target: Next day's return prediction
  • Model: XGBoost with early stopping (200 estimators, learning rate 0.05)

Trading Strategy

  • Moving Average: 200-day MA for trend identification
  • Bollinger Bands: 20-period with 1.9 standard deviations
  • RSI: 14-period with buy/sell levels at 45/55
  • Position Sizing: Full portfolio allocation

📊 Strategy Logic

Long Positions (Bull Market)

  • Entry: Price > MA200 AND Price hits Lower Bollinger Band AND RSI < 45
  • Exit: Price hits Middle Bollinger Band (profit) OR Price breaks below MA200 (stop-loss)

Short Positions (Bear Market)

  • Entry: Price < MA200 AND Price hits Upper Bollinger Band AND RSI > 55
  • Exit: Price hits Middle Bollinger Band (profit) OR Price breaks above MA200 (stop-loss)

📈 Performance Metrics

The strategy provides comprehensive performance analysis including:

  • Total Return
  • Sharpe Ratio (Annualized)
  • Maximum Drawdown
  • Daily Win Rate
  • Portfolio Value Tracking
  • Trade Distribution Analysis

🎯 Key Features

AI Predictor

  • Early Stopping: Prevents overfitting with validation-based stopping
  • Directional Accuracy: Measures how often the model correctly predicts price direction
  • Visual Analysis: Side-by-side comparison of predicted vs actual prices

Trading Strategy

  • Regime-Aware: Different strategies for bull/bear markets
  • Risk Management: Automatic stop-losses and profit-taking
  • Comprehensive Visualization: 6-panel analysis dashboard
  • Trade Tracking: Detailed trade log with entry/exit reasons

📦 Dependencies

pip install pandas numpy matplotlib yfinance xgboost scikit-learn

Required packages:

  • pandas - Data manipulation
  • numpy - Numerical computations
  • matplotlib - Plotting and visualization
  • yfinance - Yahoo Finance data
  • xgboost - Machine learning model
  • scikit-learn - Model evaluation metrics

🚀 Usage

Running the AI Predictor

from prediction import AIPredictor

# Initialize with default parameters
predictor = AIPredictor(
    symbol='BTC-USD',
    lookback_period=14,
    test_size=0.2
)

# Run complete analysis
predictor.run_full_process()

Running the Trading Strategy

from strategy import HybridStrategy

# Initialize strategy
strategy = HybridStrategy(
    symbol='BTC-USD',
    initial_capital=10000,
    ma_slow=200,
    bb_period=20,
    bb_std=1.9,
    rsi_period=14,
    rsi_buy_level=45,
    rsi_sell_level=55
)

# Run complete analysis
results = strategy.run_complete_analysis()

📁 Output Files

The project generates several output files:

  • predicted_vs_actual_price_xgboost.png - AI prediction visualization
  • final_strategy_analysis.png - Comprehensive trading strategy dashboard

⚙️ Configuration

AI Predictor Parameters

  • symbol: Cryptocurrency symbol (default: 'BTC-USD')
  • lookback_period: Number of historical days for features (default: 14)
  • test_size: Fraction of data for testing (default: 0.2)

Trading Strategy Parameters

  • initial_capital: Starting capital (default: $10,000)
  • ma_slow: Moving average period (default: 200)
  • bb_period: Bollinger Bands period (default: 20)
  • bb_std: Bollinger Bands standard deviation (default: 1.9)
  • rsi_period: RSI calculation period (default: 14)
  • rsi_buy_level: RSI threshold for buy signals (default: 45)
  • rsi_sell_level: RSI threshold for sell signals (default: 55)

🔧 Customization

Both components are highly customizable:

  • Change cryptocurrency symbols
  • Adjust technical indicator parameters
  • Modify risk management rules
  • Customize visualization settings

📊 Analysis Output

The project provides:

  • Performance Metrics: Returns, Sharpe ratio, drawdown analysis
  • Trade Analysis: Entry/exit points, trade frequency, win rates
  • Visual Dashboards: Comprehensive 6-panel analysis charts
  • Risk Assessment: Maximum drawdown and volatility metrics

⚠️ Disclaimer

This project is for educational and research purposes only. Cryptocurrency trading involves significant risk, and past performance does not guarantee future results. Always conduct your own research and consider consulting with financial advisors before making investment decisions.

📝 Notes

  • The AI predictor uses early stopping to prevent overfitting
  • The trading strategy includes both long and short positions
  • All visualizations are saved as high-resolution PNG files
  • The code includes comprehensive error handling and data validation

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published