This project is a complete, production-quality web application designed for predicting stock market prices using an Artificial Neural Network (ANN) trained on live data fetched from yfinance. It is built as an industrial-grade system suitable for academic research and portfolio showcase.
- Frontend: HTML5, CSS3 (Bootstrap 5, Glassmorphism design), Vanilla JS, Chart.js for interactive visualizations.
- Backend: FastAPI for robust, high-performance REST APIs.
- Database: SQLite for storing historical predictions, metrics, and training logs.
- Machine Learning Pipeline:
- Data Source: Live data fetched from Yahoo Finance (
yfinance). - Preprocessing: Handles missing values, performs sliding window sequence generation, computes 15+ technical indicators (RSI, MACD, Bollinger Bands, EMA), and applies MinMaxScaler.
- Model: Multi-layer Feedforward Neural Network using
TensorFlow/Kerasoptimized with Adam and dropout layers to prevent overfitting. - Evaluation: Computes RMSE, MAE, MAPE, R² Score, and Directional Accuracy.
- Data Source: Live data fetched from Yahoo Finance (
- Reporting: Automated PDF and CSV report generation using
fpdf2and Pythoncsv.
Ensure you have Python 3.12+ installed. Install the requirements using:
pip install -r requirements.txtTo run the application locally:
python run.pyThis script will automatically start the Uvicorn server and open the web dashboard in your default browser at http://127.0.0.1:8000.
POST /api/train: Triggers asynchronous model training for a given ticker.POST /api/predict: Generates the next price prediction using the trained model.GET /api/history/{ticker}: Retrieves the historical predictions stored in the database.GET /api/live/{ticker}: Fetches the current real-time market data.GET /api/metrics/{ticker}: Returns the evaluation metrics for the latest trained model.GET /api/training-logs/{ticker}: Returns epoch-by-epoch training logs.POST /api/download-report: Generates and downloads a comprehensive PDF evaluation report.POST /api/download-csv: Generates and downloads the prediction history as a CSV file.
- Enter any valid Yahoo Finance ticker (e.g.,
AAPL,NVDA,RELIANCE.NS) in the web interface. - Click Train Model. This will fetch up to 5 years of historical data, compute indicators, split chronologically, and train the ANN.
- Click Predict to forecast the next closing price. The dashboard will automatically update with charts comparing historical actual prices with the predicted trajectory.
- Export PDF or CSV reports directly from the sidebar.
- Toggle "Auto Refresh" on the dashboard to automatically poll yfinance and generate new predictions every minute.
- Integration with Celery/Redis for distributed training queues.
- Support for LSTM/GRU advanced architectures alongside the Feedforward ANN.
- Real-time WebSocket streaming for millisecond tick data.