How naveen3830/ai_stock_prediction works
1. This repo is a Python stock-forecasting application centered on two model families: ARIMA for classical time-series forecasting and LSTM for sequence learning. The runtime app is organized under src/, with src/main.py acting as the orchestration layer for the Streamlit experience described in the README.
2. The main data boundary is external market data. src/stock_data.py is the ingestion layer that pulls historical price series from yfinance, likely returning a cleaned time-indexed dataset of S&P 500 stock prices. All downstream modeling depends on this module’s output.
3. Preprocessing and feature shaping are split across the model modules and src/models/indicators.py. This is where the repo’s two different modeling pipelines diverge: ARIMA expects stationary series and differencing-style transforms, while LSTM expects scaled sliding-window sequences, consistent with the README’s use of MinMaxScaler and 60-day windows.
4. src/models/arima.py is the classical forecasting subsystem. It likely handles stationarity transforms, parameter selection/tuning, model fitting, and forecast generation. In the architecture diagram, this is a self-contained branch from raw series to prediction output, optimized for short-horizon univariate forecasts.
5. src/models/lstm.py is the deep-learning forecasting subsystem. It likely builds, trains, and evaluates an LSTM network over normalized sequences, with dropout and dense output layers as described in the README. This branch is heavier-weight and computationally more expensive than ARIMA, but is the main non-linear forecasting path.
6. src/charts.py is the presentation/visualization layer. Its role is to turn model outputs and historical series into comparison plots, forecast charts, and other UI visuals. This sits at the edge of the application, consuming results from both model pipelines rather than participating in training.
7. src/main.py ties the whole flow together as the application controller: user input from the Streamlit UI selects a stock, data is fetched, preprocessing/model execution happens, and charts are rendered. In architecture terms, it is the central coordination point rather than a domain model itself.
8. src/styles.py and src/logging_config.py are cross-cutting support modules. Styles affect only the UI layer, while logging supports observability across data loading, preprocessing, training, and prediction steps. They don’t define business logic, but they do shape operational behavior and presentation.
9. The notebooks/ directory is an exploratory/research workspace, not the primary runtime path. The ARIMA and LSTM notebooks suggest model experimentation, tuning, and validation happened there before hardening the logic into src/models/.
10. The architecture has a clear separation between offline experimentation and interactive inference. The reusable Python package code in src/ is the deployable core, while the notebooks document model development. That distinction is important if you diagram the repo: notebooks are supporting assets, not a production subsystem.
11. The main external dependencies that materially affect architecture are yfinance for market data access and the Python ML stack implied by ARIMA/LSTM modeling. The app is built for Streamlit-based interactive execution, so the user interface, model execution, and visualization are coupled in a single Python process rather than split into separate services.
12. Overall, the system is a single-app architecture with three major flows: market data ingestion, dual-model forecasting, and visualization/UI rendering. The key boundaries are between data acquisition, preprocessing, model-specific forecasting, and presentation, with shared utility modules providing styling and logging.
Main entry points: main.py Main app · arima.py ARIMA · lstm.py LSTM · stock_data.py Market data
Components 14
Runtime app
Interactive Streamlit application and cross-cutting presentation/ops modules.
- Main app · Orchestrates the Streamlit flow from input to forecast and charts.
src/main.py - Styles · UI styling and presentation constants for the app.
src/styles.py - Logging · Application logging configuration used across the runtime.
src/logging_config.py - Charts · Renders forecast and comparison plots for the UI.
src/charts.py - Streamlit UI · Interactive user-facing experience hosted inside the Python app.
Forecasting models
Data ingestion, feature shaping, and the two forecasting branches.
- Market data · Fetches historical price data from external market sources.
src/stock_data.py - Indicators · Shared preprocessing and indicator/sequence feature preparation.
src/models/indicators.py - ARIMA · Stationary-series forecasting pipeline for short-horizon predictions.
src/models/arima.py - LSTM · Neural sequence forecasting pipeline using scaled windows.
src/models/lstm.py
Research workspace
Notebook-based experimentation and validation.
- ARMA notebook · Exploratory notebook for classical time-series experimentation.
notebooks/ARMA.ipynb - Model notebook · Notebook for model development, tuning, and validation.
notebooks/Model.ipynb - ARIMA notebook · Notebook focused on ARIMA exploration and iteration.
notebooks/arima.ipynb
Other components
- yfinance · External API/library used to obtain historical market prices.
- ML stack · Underlying numerical and machine-learning dependencies used by the models.
Connections 18
- Streamlit UI → Main app: drives · User interactions enter the main orchestration layer.
- Main app → Market data: loads · The app fetches the selected stock's historical series.
- Market data → yfinance: fetches from · Market data is retrieved from the external source.
- Main app → Indicators: prepares · Main flow sends raw series into preprocessing and feature shaping.
- Indicators → ARIMA: feeds · Classical pipeline consumes transformed time series features.
- Indicators → LSTM: feeds · Sequence pipeline consumes scaled windowed features.
- Main app → ARIMA: runs · The controller can execute the ARIMA forecasting path.
- Main app → LSTM: runs · The controller can execute the LSTM forecasting path.
- ARIMA → ML stack: uses · ARIMA relies on the scientific Python forecasting stack.
- LSTM → ML stack: uses · LSTM relies on the numerical and deep-learning stack.
- ARIMA → Charts: outputs to · Forecast results are passed to visualization.
- LSTM → Charts: outputs to · Deep-model predictions are passed to visualization.
- Market data → Charts: supplies · Historical series are included in comparison charts.
- Main app → Styles: applies · UI styling is applied within the app shell.
- Main app → Logging: logs via · Runtime events are recorded through shared logging configuration.
- ARMA notebook → ARIMA: prototypes · Notebook experimentation informs the ARIMA implementation.
- ARIMA notebook → ARIMA: prototypes · Notebook experimentation informs the ARIMA implementation.
- Model notebook → LSTM: prototypes · Notebook experimentation informs the LSTM implementation.