A beginner-friendly machine learning project that predicts stock market trends using technical indicators and advanced ML algorithms.
π Project Report: View Report
π Live Dashboard: Launch Dashboard
π₯ Video Demo & Presentation: Watch Demo
- Overview
- Features
- Quick Start
- Project Structure
- Installation
- Model Performance
- Technical Details
- Disclaimer
This project demonstrates how to build an end-to-end AI system for stock market trend prediction. It's designed for beginners but includes advanced techniques that make it suitable for learning and real-world applications.
What it does:
- Collects real-time stock data from Yahoo Finance
- Engineers 40+ technical indicators (RSI, MACD, Bollinger Bands, etc.)
- Trains multiple ML models (Random Forest, XGBoost, Logistic Regression)
- Provides an interactive web dashboard for predictions
- Achieves 60%+ accuracy on market trend prediction
Target Audience: Students, beginners in ML/Finance, and anyone interested in algorithmic trading
- Real-time data from Yahoo Finance API
- Multiple stocks support (AAPL, GOOGL, MSFT, AMZN, TSLA)
- Flexible time periods (1Y, 2Y, 5Y, Max)
- Automatic data cleaning and validation
- 40+ Technical Indicators:
- Moving Averages (SMA, EMA)
- Momentum (RSI, ROC, Stochastic)
- Volatility (Bollinger Bands, ATR)
- Volume (OBV, VPT, PVT)
- Price Action patterns
- Multiple Models: Random Forest, XGBoost, Logistic Regression
- Automatic Model Selection: Best model chosen by cross-validation
- Class Balancing: Handles imbalanced market data
- Feature Importance: Understand which indicators matter most
- Real-time Predictions: Live market trend forecasting
- Beautiful Visualizations: Interactive charts with Plotly
- Model Insights: Feature importance and performance metrics
- User-friendly Interface: Built with Streamlit
git clone https://github.com/23f2000792/ai-market-trend-analysis
cd ai-market-trend-analysis
python -m venv venv
venv\Scripts\activate
pip install -r requirements.txtpython data_collector.pyThis downloads 5 years of stock data for major tech companies.
python feature_engineer.pyCreates 40+ technical indicators from raw price data.
python model_trainer.pyTrains and evaluates multiple ML models, saves the best one.
streamlit run streamlit_app/app.pyOpens interactive web dashboard at http://localhost:8501
ai-market-trend-analysis/
β
βββ π data/
β βββ raw/ # Raw stock data (CSV files)
β βββ features/ # Processed data with technical indicators
β
βββ π models/
β βββ *.pkl # Trained ML models
β βββ scaler.pkl # Feature scaler
β βββ model_metadata.json # Model performance info
β βββ feature_importance.csv
β
βββ π notebooks/ # Jupyter notebooks for exploration
β βββ 01_data_exploration.ipynb
β
βββ π streamlit_app/ # Interactive dashboard
β βββ app.py
β
βββ π src/ # Core modules
β βββ data_collector.py # Stock data collection
β βββ feature_engineer.py # Technical indicators
β βββ model_trainer.py # ML model training
β
βββ π requirements.txt # Python dependencies
βββ π README.md # This file
βββ π setup.py # Installation script
- Python 3.8+ (recommended: 3.9 or 3.10)
- Git
- Internet connection (for data fetching)
- Clone the repository
git clone https://github.com/23f2000792/ai-market-trend-analysis
cd ai-market-trend-analysis- Create virtual environment
python -m venv venv- Activate virtual environment
# On Windows
venv\Scripts\activate
# On macOS/Linux
source venv/bin/activate- Install dependencies
pip install -r requirements.txt| Model | Accuracy | F1-Score | Training Time | Notes |
|---|---|---|---|---|
| Random Forest | 64.2% | 0.639 | 2.3s | Most balanced performance |
| XGBoost | 66.1% | 0.658 | 5.7s | Highest accuracy |
| Logistic Regression | 61.8% | 0.612 | 0.8s | Fastest training |
- Precision: 62-68% across all classes
- Recall: 58-71% (varies by market condition)
- Cross-validation: 5-fold CV with stratified sampling
- Class Balance: Down(35%), Stable(30%), Up(35%)
- RSI_14 (0.124) - Momentum indicator
- SMA_Ratio_5_20 (0.089) - Trend strength
- MACD_Histogram (0.076) - Momentum divergence
- BB_Position (0.071) - Volatility position
- Volume_Ratio (0.068) - Volume confirmation
- Price_to_SMA50 (0.063) - Long-term trend
- ATR (0.059) - Volatility measure
- Stoch_K (0.057) - Overbought/oversold
- ROC_10 (0.054) - Price momentum
- EMA_12 (0.051) - Short-term trend
- Collection: Yahoo Finance API β Raw OHLCV data
- Cleaning: Handle missing values, outliers, stock splits
- Feature Engineering: Create 40+ technical indicators
- Preprocessing: Scale features, encode targets
- Training: Multiple models with cross-validation
- Evaluation: Comprehensive metrics and validation
- Simple Moving Average (SMA): 5, 10, 20, 50, 200 periods
- Exponential Moving Average (EMA): 12, 26, 50 periods
- Moving Average Ratios and Cross-overs
- Relative Strength Index (RSI): 14-period
- Rate of Change (ROC): 5, 10, 20 periods
- MACD: Standard 12-26-9 configuration
- Stochastic Oscillator: %K and %D
- Bollinger Bands: 20-period with 2 standard deviations
- Average True Range (ATR): 14-period
- Historical Volatility: 10 and 30-day annualized
- On Balance Volume (OBV)
- Volume Price Trend (VPT)
- Price Volume Trend (PVT)
- Volume Moving Averages and Ratios
RandomForestClassifier(
n_estimators=100,
max_depth=10,
min_samples_split=5,
min_samples_leaf=2,
random_state=42
)XGBClassifier(
n_estimators=100,
max_depth=6,
learning_rate=0.1,
random_state=42
)IMPORTANT: This project is for educational purposes only.
- π Educational Tool: Designed for learning ML and financial analysis
- β Not Financial Advice: Do not use for actual trading decisions
- π Historical Performance: Past results don't guarantee future performance
- π― Accuracy Limitations: 60-70% accuracy is good for education, not trading
- π° Risk Warning: Financial markets involve substantial risk of loss
- π¨βπΌ Professional Advice: Consult qualified financial advisors for investment decisions
The authors and contributors are not responsible for any financial losses incurred from using this software. Always perform your own research and risk assessment before making investment decisions.
This project is licensed under the MIT License - see the LICENSE file for details.
- Yahoo Finance for free financial data API
- Streamlit for making beautiful web apps simple
- scikit-learn for excellent ML library
- Plotly for interactive visualizations
- pandas-ta for technical analysis indicators
- π§ Contact: raushanmahto999@gmail.com