A Flask-based web application for downloading stock data, performing exploratory data analysis (EDA), visualizing price trends (including candlestick charts and moving averages), and predicting future stock prices using LSTM (Long Short-Term Memory) neural networks.
This project demonstrates a full end-to-end pipeline for stock trend prediction:
- Data Acquisition: Download historical price data from Yahoo Finance using
yfinance
. - Exploratory Data Analysis: Display raw data, descriptive statistics, and visualize:
- Line charts of Open, High, Low, Close, Volume
- Candlestick plots
- Simple Moving Averages (SMA) and Exponential Moving Averages (EMA)
- Modeling: Prepare data with
MinMaxScaler
, split into training/testing sets, then train an LSTM model to forecast future prices. - Web Interface: Use Flask to build a front-end where users enter a stock ticker to:
- View EDA charts
- Download the raw CSV
- See predictions overlaid with actual prices
- Download & Preview Data: Fetch any public stock by ticker symbol.
- Descriptive Statistics: Summary statistics (mean, std, percentiles).
- Interactive Visualizations:
- Candlestick charts with Plotly
- Line plots for OHLC & Volume
- SMA & EMA overlays
- LSTM-based Forecasting: Predict next-day or multi-day prices.
- Model Persistence: Save/load trained model (
.h5
file) to avoid retraining. - CSV Export: Download the processed dataset.
- Language: Python 3.x
- Web Framework: Flask
- Data Handling: Pandas, NumPy
- Visualization: Matplotlib, Plotly
- Finance API: yfinance
- Machine Learning:
- Preprocessing: Scikit-learn (
MinMaxScaler
) - Deep Learning: TensorFlow / Keras (Sequential API, LSTM layers)
- Preprocessing: Scikit-learn (
- Template Rendering: Jinja2 (Flask)
-
Clone the Repository
git clone https://github.com/namaniisc/StockSight.git cd StockSight
-
Create & Activate a Virtual Environment
python3 -m venv venv source venv/bin/activate # macOS/Linux venv\Scripts\activate # Windows
-
Install Dependencies
pip install -r requirements.txt
-
Download Pretrained Model (optional)
If you wish to skip training, download
stock_dl_model.h5
into the project root.
├── app.py # Flask application
├── models/ # Saved Keras model (.h5)
├── static/ # Generated plots & downloaded CSVs
├── templates/
│ └── index.html # Main UI template
├── requirements.txt # Python dependencies
├── README.md # Project documentation
└── notebooks/ # Jupyter notebooks used for prototyping
-
Run the Flask App
flask run # or python app.py
-
Interact
- Open your browser to
http://127.0.0.1:5000
- Enter a stock ticker (e.g.,
AAPL
,POWERGRID.NS
) - View EDA charts, download CSV, and see LSTM forecasts.
- Open your browser to
If you want to retrain the LSTM model:
- Open
notebooks/train_model.ipynb
. - Adjust hyperparameters (e.g., lookback window, epochs).
- Run all cells to preprocess data, train the model, and save
stock_dl_model.h5
.
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch:
git checkout -b feature/YourFeature
. - Commit your changes:
git commit -m 'Add some feature'
. - Push to the branch:
git push origin feature/YourFeature
. - Open a Pull Request.