A complete end-to-end Machine Learning system that predicts whether a stock's closing price will go UP β or DOWN β the next trading day.
Status: β Production Ready | Version: 2.0 + Phase 1 | Last Updated: May 2026
This project combines real-world ML best practices with financial prediction to create an intelligent trading signal system:
- 10+ Production Modules: 5,600+ lines of production code
- 40+ Technical Indicators: Comprehensive market feature engineering
- Multiple ML Models: Logistic Regression, Random Forest, XGBoost, LSTM + Ensemble
- 11 Streamlit UI Tabs: Interactive web application for analysis and visualization
- Complete Backtesting: Historical performance validation with detailed metrics
- Smart Decision Making: BUY/SELL/NO TRADE with confidence scoring (0-100%)
- Multi-Channel Alerts: Email, SMS, console notifications
- Professional Exports: CSV, Excel, JSON, HTML reporting
- Market Intelligence: VIX awareness, earnings calendar, global market context
# Clone/navigate to project
cd c:\Projects\Stocks_predication
# Create virtual environment
python -m venv venv
venv\Scripts\activate
# Install dependencies
pip install -r requirements.txtstreamlit run app.pyThe app opens at http://localhost:8501
β Weighted ensemble model (XGBoost 50%, RF 20%, MLP 20%, LR 10%) β Dynamic confidence scoring (0-100%) β 23 optimized market-aware features β VIX-adjusted for market conditions β Earnings-aware to avoid high-risk dates
β Strong Buy (>75% confidence) β Buy (60-75% confidence) β No Trade (<60% confidence) β Risk levels: LOW / MEDIUM / HIGH β Position sizing recommendations
β Complete explanations (why the signal occurred) β Supporting indicators and evidence β Beginner-friendly & advanced analysis β Indicator tooltips and definitions
β Historical trade simulation β Win rate, P&L, Sharpe ratio, max drawdown β Trade-by-trade detailed analysis β Performance comparison across time periods
β Real-time console alerts β Email notifications (Gmail, custom SMTP) β SMS alerts (Twilio-ready) β Alert history tracking
β CSV (all data and results) β Excel workbooks (multi-sheet) β JSON (API-friendly) β HTML (client-ready reports)
Stocks_predication/
βββ README.md β Start here!
βββ PROJECT_INFORMATION.txt β Complete documentation
βββ requirements.txt β Python dependencies
βββ main_pipeline.py β Script-based interface
β
βββ π¨ USER INTERFACES
βββ app.py β Main Streamlit app (11 tabs)
βββ streamlit_app.py β Alternative UI
β
βββ π¦ SOURCE CODE (src/)
β βββ DATA PIPELINE
β βββ data_fetching.py β Yahoo Finance integration
β βββ preprocessing.py β Data cleaning
β βββ technical_indicators.py β 40+ indicators
β βββ candlestick_patterns.py β Pattern detection
β βββ sentiment_analysis.py β FinBERT sentiment
β β
β βββ MACHINE LEARNING
β βββ model.py β Baseline models
β βββ model_training_v2.py β v2.0 ensemble
β βββ lstm_neural_network.py β Deep learning
β βββ evaluation.py β Metrics & evaluation
β βββ ablation_study.py β Feature importance
β β
β βββ DECISION INTELLIGENCE
β βββ feature_optimization.py β 23 optimized features
β βββ decision_engine.py β Trading decisions
β βββ market_analysis.py β Market context
β βββ vix_analyzer.py β Volatility analysis
β βββ explanation_engine.py β Signal explanations
β β
β βββ EXECUTION & VALIDATION
β βββ backtester.py β Historical simulation
β βββ alerts_manager.py β Notifications
β βββ export_utils.py β Data exports
β βββ visualization.py β Interactive charts
β
βββ π NOTEBOOKS
βββ notebooks/stock_prediction_pipeline.ipynb
β
βββ π DATA & MODELS
βββ data/ β Data storage
βββ models/ β Saved models
βββ exports/ β Export outputs
-
Configure (left sidebar):
- Enter stock symbol (e.g.,
AAPL,RELIANCE.NS,TCS.NS) - Select date range (default: 3 years)
- Choose models to run
- Enter stock symbol (e.g.,
-
Analyze (click "π Fetch & Analyze"):
- Fetches historical data
- Calculates indicators
- Trains ML models
- Generates predictions
-
Explore Results (11 tabs):
- π Price Chart: Interactive candlestick
- π Technical Indicators: RSI, MACD, Bollinger Bands
- π― Predictions: UP/DOWN with confidence
- π Model Performance: Accuracy metrics
- π Feature Analysis: Feature importance
- π¬ Sentiment Analysis: News sentiment
- π―οΈ Candlestick Patterns: Pattern detection
- π₯ Export Results: CSV/Excel/JSON
- π Alerts: Set up notifications
- π Earnings Calendar: Risk awareness
- π VIX Analysis: Market volatility
from src.data_fetching import fetch_stock_data
from src.feature_engineering import add_technical_indicators, create_target
from src.model_training_v2 import WeightedEnsemble
# 1. Fetch data
df = fetch_stock_data('AAPL', '2023-01-01', '2024-01-01')
# 2. Add indicators
df = add_technical_indicators(df)
# 3. Create target
df = create_target(df)
# 4. Train model
model = WeightedEnsemble()
model.fit(X_train, y_train)
# 5. Predict
predictions = model.predict(X_test)
confidence = model.predict_proba(X_test)Raw Stock Data
β (fetch from Yahoo Finance)
Historical OHLCV Data
β (clean, handle missing values)
Preprocessing
β (add 40+ technical indicators)
Feature Engineering
β (create UP/DOWN target)
Target Generation
β (train-test split, normalize)
ML Training
β (XGBoost, RF, LSTM, LR ensemble)
Predictions & Signals
β (confidence scoring, decision making)
Trading Signals (BUY/SELL/HOLD)
Trend Analysis:
- Simple & Exponential Moving Averages (5, 10, 20 day)
- MACD (Moving Average Convergence Divergence)
- ADX (Average Directional Index)
Momentum:
- RSI (Relative Strength Index)
- Stochastic Oscillator
- Daily Returns
Volatility:
- Bollinger Bands (Upper, Lower, Width, Position)
- ATR (Average True Range)
- Standard Deviation
Volume:
- Volume Change %
- On-Balance Volume (OBV)
- Chaikin Money Flow (CMF)
Price Structure:
- Close-Open Difference
- Price vs Moving Average Distance
- High-Low Range
| Model | Type | Strengths | Use Case |
|---|---|---|---|
| Logistic Regression | Linear | Fast, interpretable, good baseline | Quick predictions, feature analysis |
| Random Forest | Ensemble | Non-linear, feature importance | General-purpose predictions |
| XGBoost | Boosting | State-of-the-art, handles complexity | High-accuracy predictions |
| LSTM | Deep Learning | Temporal dependencies | Complex pattern recognition |
| Ensemble (v2.0) | Combined | Best of all (weighted voting) | Final production predictions |
v2.0 Ensemble Weighting:
- XGBoost: 50% (primary model)
- Random Forest: 20%
- MLP/LSTM: 20%
- Logistic Regression: 10%
Classification Metrics:
- Accuracy, Precision, Recall, F1-Score
- ROC-AUC (Receiver Operating Characteristic)
- Confusion Matrix (TP, FP, TN, FN)
Business Metrics:
- Win Rate: % of profitable trades
- Sharpe Ratio: Risk-adjusted returns
- Max Drawdown: Largest peak-to-trough decline
- P&L: Total profit/loss
RELIANCE.NS, TCS.NS, INFY.NS, WIPRO.NS, HDFC.NS, ICICIBANK.NS, AXISBANK.NS, SBIN.NS, MARUTI.NS, BAJAJFINSV.NS
AAPL, MSFT, GOOGL, AMZN, TSLA, META, NVIDIA, JPM, V, WMT
Note: Any stock supported by Yahoo Finance can be used
| Metric | Before (v1.0) | After (v2.0) | Improvement |
|---|---|---|---|
| Overall Accuracy | 60% | 60-65% | β +5% |
| Precision | 54.8% | 65-70% | β +10-15% |
| False Positive Rate | ~50% | ~30% | β -40% |
| Features | 54 (noisy) | 23 (optimized) | β Better quality |
| Confidence Threshold | 0.5 | 0.6 | β Quality filter |
Data: pandas>=2.2.0, numpy>=2.0.0, scipy>=1.12.0
ML: scikit-learn>=1.4.0, xgboost>=2.0.0, tensorflow>=2.14.0
Finance: yfinance>=0.2.35, pandas-ta>=0.3.14b0
NLP: transformers>=4.36.0 (FinBERT)
Viz: matplotlib>=3.8.4, plotly>=5.18.0
Web: streamlit>=1.31.0
See requirements.txt for complete list.
- This is a PREDICTION tool, not financial advice
- Historical performance β Future results
- Always use proper risk management (stop losses, position sizing)
- Start with paper trading before real capital
- Monitor model performance continuously
- Be aware of earnings dates and major news events
- Combine signals with fundamental analysis
- PROJECT_INFORMATION.txt β Complete documentation (start here!)
- ARCHITECTURE.md β System design and data flow
- MODEL_AND_ALGORITHM_GUIDE.md β Detailed ML explanations
- API_REFERENCE.md β Function documentation
- QUICKSTART.md β Quick start guide
- TROUBLESHOOTING.md β Common issues
"No module named 'src'"
import sys
sys.path.insert(0, 'src')"yfinance: No data found"
- Check symbol format (e.g., RELIANCE.NS for NSE stocks)
"Streamlit connection reset"
- Clear browser cache or restart terminal
"Model accuracy is low"
- Check if market is sideways (low ADX)
- Verify feature scaling
See TROUBLESHOOTING.md for more solutions.
Phase 2: Multi-stock portfolio optimization, options strategies Phase 3: Deep reinforcement learning, sector rotation, crypto support Phase 4: Federated learning, advanced NLP, FastAPI deployment
- Time-Series Data: Never shuffle! Use TimeSeriesSplit for proper validation
- Feature Engineering: Quality over quantity (54 β 23 features improved accuracy)
- Ensemble Models: Different models excel in different market regimes
- Confidence Scoring: Threshold reduces false positives significantly
- Market Context: VIX integration and earnings awareness improve decisions
- Issues: Check TROUBLESHOOTING.md
- Questions: Review API_REFERENCE.md or ARCHITECTURE.md
- Examples: See
notebooks/stock_prediction_pipeline.ipynb