A sophisticated machine learning application for predicting stock prices using Random Forest algorithm, advanced feature engineering, and real-time market data visualization.
- Algorithm: Random Forest Regressor
- Implementation: scikit-learn's RandomForestRegressor
- Parameters:
- n_estimators: 100
- max_depth: 10
- random_state: 42
- n_jobs: -1 (parallel processing)
-
Price Features:
- Open, High, Low, Close prices
- Daily Volume
- Price Changes
-
Technical Indicators:
- Moving Averages (MA_20, MA_50)
- Relative Strength Index (RSI)
- Volume Moving Average
- Price Change Percentage
-
Lag Features:
- Previous 1, 2, 3, and 5-day closing prices
- Historical price patterns
- RMSE (Root Mean Square Error): Measures prediction accuracy
- MAE (Mean Absolute Error): Average absolute difference
- RΒ² Score: Model's explanatory power
- Feature Importance Analysis: Identifies most influential factors
- Real-time Stock Data: Fetch live data from Alpha Vantage
- AI-Powered Predictions: Advanced Random Forest ML algorithm with feature engineering
- Multiple Markets: Support for Indian (NSE) and US stocks
- Technical Analysis: Moving averages, volatility, and technical indicators
- Multi-day Forecasting: Predict up to 30 days ahead
- Interactive Dashboard: Beautiful visualizations with Plotly
- Model Performance: Detailed accuracy metrics and feature importance analysis
- Data Export: Download historical data as CSV
market-forecast-app/
β
βββ app.py # Main Streamlit application
βββ y-test.py # Test your alpha vantage APi key
βββ requirements.txt # Python dependencies
βββ README.md # Project documentation
β
βββ models/ # Directory for saved models (auto-created)
β βββ RELIANCE_model_*.pkl
β βββ RELIANCE_scaler_*.pkl
β
βββ data/ # Directory for data files (optional)
βββ *.csv
-
Clone or Download the Project
mkdir market-forecast-app cd market-forecast-app -
Create Virtual Environment (Recommended)
python -m venv venv # On Windows venv\Scripts\activate # On macOS/Linux source venv/bin/activate
-
Install Dependencies
pip install -r requirements.txt
-
Run the Application
streamlit run app.py
-
Open in Browser
- The app will automatically open at
http://localhost:8501
- The app will automatically open at
-
Fork the Repository
# Fork from GitHub https://github.com/techiepookie/StockAI-predictor-pro -
Clone Your Fork
git clone https://github.com/YOUR_USERNAME/StockAI-predictor-pro.git cd StockAI-predictor-pro -
Set Up Environment Variables
- Go to Streamlit Cloud Dashboard
- Navigate to App Settings > Secrets
- Add your Alpha Vantage API key:
ALPHA_VANTAGE_API_KEY = "your_api_key_here"
-
Deploy on Streamlit Cloud
- Visit share.streamlit.io
- Sign in with GitHub
- Click "New app"
- Select your forked repository
- Configure deployment:
- Main file path:
app.py - Branch:
main - Python version: 3.8+
- Main file path:
- Click "Deploy!"
-
Access Your App
- URL format:
https://YOUR_USERNAME-stockai-predictor-pro.streamlit.app - Share with your users!
- URL format:
- Indian Stocks: Choose from popular NSE stocks like RELIANCE.NS, TCS.NS
- US Stocks: Select from NASDAQ/NYSE stocks like AAPL, GOOGL
- Custom Ticker: Enter any valid stock ticker symbol
- Time Period: Select data range (1 month to 5 years)
- Prediction Days: Choose how many days to forecast (1-30)
- Model Settings: Enable/disable model retraining
- Stock Analysis: View current metrics and company information
- Predictions: See AI-generated price forecasts
- Charts: Interactive price and volume visualizations
- Model Performance: Detailed accuracy metrics
- Data Table: Historical data with download option
- Random Forest Regressor: Ensemble method for robust predictions
- Feature Engineering: Technical indicators, lag features, and temporal features
- Cross-validation: Time-series aware splitting to prevent data leakage
- Price Data: Open, High, Low, Close, Volume
- Technical Indicators: Moving averages (5, 10, 20 days)
- Lag Features: Previous day values (1, 2, 3 days)
- Volatility Measures: Price changes and high-low percentages
- Temporal Features: Day of week, month
- RΒ² Score: Coefficient of determination
- RMSE: Root Mean Square Error
- MAE: Mean Absolute Error
- Feature Importance: Most influential factors
RELIANCE.NS - Reliance Industries
TCS.NS - Tata Consultancy Services
INFY.NS - Infosys
HDFCBANK.NS - HDFC Bank
ICICIBANK.NS - ICICI Bank
HINDUNILVR.NS - Hindustan Unilever
ITC.NS - ITC Limited
KOTAKBANK.NS - Kotak Mahindra Bank
LT.NS - Larsen & Toubro
AXISBANK.NS - Axis Bank
AAPL - Apple Inc.
GOOGL - Alphabet Inc.
MSFT - Microsoft Corporation
AMZN - Amazon.com Inc.
TSLA - Tesla Inc.
META - Meta Platforms Inc.
NVDA - NVIDIA Corporation
NFLX - Netflix Inc.
AMD - Advanced Micro Devices
INTC - Intel Corporation
-
Root Mean Square Error (RMSE)
- Measures prediction accuracy
- Lower values indicate better performance
- Calculated as: sqrt(mean((actual - predicted)Β²))
-
Mean Absolute Error (MAE)
- Average absolute difference between predictions and actual values
- More robust to outliers than RMSE
- Calculated as: mean(|actual - predicted|)
-
RΒ² Score (Coefficient of Determination)
- Indicates the proportion of variance explained by the model
- Range: 0 to 1 (higher is better)
- Calculated using scikit-learn's r2_score
- Random Forest provides built-in feature importance scores
- Higher scores indicate more influential features
- Top features typically include:
- Recent closing prices (Close_Lag_1)
- Volume indicators
- Technical indicators (RSI, MA)
- Time series split to prevent data leakage
- 80-20 train-test split
- No shuffle to maintain temporal order
- Validation on most recent data
- Python: 3.8 or higher
- Memory: Minimum 512MB RAM
- Internet: Required for fetching real-time stock data
- Browser: Modern web browser (Chrome, Firefox, Safari, Edge)
- Storage: ~100MB for application and dependencies
- streamlit: Web app framework
- pandas: Data manipulation and analysis
- numpy: Numerical computing
- scikit-learn: Machine learning algorithms
- joblib: Model serialization
- plotly: Interactive visualizations
- matplotlib: Additional plotting capabilities
-
"Invalid ticker" Error
- Ensure ticker symbol is correct
- For Indian stocks, add
.NSsuffix (e.g.,RELIANCE.NS) - For US stocks, use standard symbols (e.g.,
AAPL)
-
"No data found" Error
- Check internet connection
- Verify stock ticker exists
- Try different time period
-
Model Training Failed
- Ensure sufficient data (minimum 50 data points)
- Try longer time period
- Check for data quality issues
-
Slow Performance
- Reduce prediction days for faster processing
- Use shorter time periods for training
- Ensure stable internet connection
- Start with 1-year data for balanced accuracy and speed
- Use 7-day predictions for optimal performance
- Retrain model weekly for best accuracy
- Educational Purpose: This application is for educational and research purposes only
- Not Financial Advice: Predictions should not be used as sole basis for investment decisions
- Market Risks: Stock markets are inherently unpredictable and risky
- Consult Professionals: Always consult with qualified financial advisors
- Do Your Research: Conduct thorough analysis before making investment decisions
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create a feature branch:
git checkout -b new-feature - Make your changes
- Commit changes:
git commit -am 'Add new feature' - Push to branch:
git push origin new-feature - Submit pull request
- Add more ML algorithms (LSTM, ARIMA, Prophet)
- Implement portfolio analysis
- Add real-time alerts and notifications
- Include fundamental analysis data
- Add backtesting capabilities
This project is open source and available under the MIT License.
If you encounter any issues or have questions:
- Check the troubleshooting section above
- Review the documentation thoroughly
- Create an issue on GitHub with detailed information
- Include error messages and steps to reproduce
- LSTM Neural Networks: Deep learning for time series
- Sentiment Analysis: Social media and news sentiment
- Portfolio Optimization: Multi-stock portfolio analysis
- Real-time Alerts: Price target notifications
- Mobile App: React Native mobile version
- API Integration: RESTful API for developers
- Backtesting: Historical strategy performance testing
Built with β€οΈ using Streamlit, scikit-learn, and Alpha Vantage API
Last updated: August 2025