This project focuses on time series prediction using Convolutional Neural Network (CNN) - Long Short-Term Memory (LSTM) model. The goal is to forecast future values of finaicial instrument based on historical data.
The project includes the following components:
- Time Series Data
- Seasonal Decomposition of Target
- Addition of technical indicators as a features
-
Data Extraction: The input time series data is extracted using the yfinance library (Python wrapper for Yahoo Finance), which allows fetching historical stock data from Yahoo Finance. The ticker symbols or stock names are provided as input to yfinance to retrieve the historical price data. Other parameters, such as the start and end dates, can also be specified to define the time range of interest.
-
Data Preprocessing: The extracted data is preprocessed to prepare it for input to the prediction model. This involve tasks such as handling missing values, removing outliers, or performing feature engineering.
- In addition of time series data the target (Closing Price)
- Additionally, the data may need to be split into training and testing sets.
-
Model Architecture: The model architecture consists of a combination of convolutional layers (Conv1D), max pooling layers (MaxPooling1D), and recurrent layers (LSTM). Additional layers such as fully connected (Dense) layers are also added to the model. The final output layer predicts the target variable.
-
Model Training: The model is trained using the training dataset. The loss function used is mean squared error (MSE), and the optimizer used is Adam. The training is performed for a specified number of epochs with a defined batch size.
-
Model Evaluation: The trained model is evaluated on the test dataset using the same loss function. The predictions made by the model are compared with the actual values to assess the performance of the model. The evaluation metrics used include root mean squared error (RMSE) and R-squared (coefficient of determination).
-
Hyperparameter Tuning: Hyperparameter tuning has been performed to find the optimal values for hyperparameters such as the number of filters, kernel size, LSTM units, etc. This helps in improving the model's performance.
-
After parameter tuning final model is trained with all the available data and deployed in flask app via VSCode.
- Clone the repo
- To install dependencies: pip install -r requirements.txt
- download dataset using code from final_model.ipynb. There you can download dataframe of desired timeframe by changing code.
- Model building and parameter tuning : main_mvp.ipynb
- model training and stock data download: final_model.ipynb
- flask app deployment:
-- go to /flask/app.py
-- inside key.py replace your news api key (key = "your newsapi key"). You can get your api key from here: https://newsapi.org
- once you replace your api key you are good to go.
Predicting how the stock market will perform is a challenging task. There are various factors involved in stock price prediction, including physical and psychological factors, rational and irrational behavior, market trends, and more. These factors contribute to the dynamic and volatile nature of stock prices, making it difficult to predict them with high accuracy. Therefore, it's important to exercise caution and not solely rely on the predictions generated by this model for making investment decisions.
Here are some possible enhancements that can be considered:
- Incorporating unstructured textual information, such as investor sentiment from social media, earning reports of underlying companies, immediate policy-related news, and research reports from market analysts, to enhance the prediction accuracy.
-
- Incorporating additional features or external factors that might influence the time series data to improve the predictions.
- Exploring alternative data sources or features that could provide valuable insights into the stock market dynamics and improve the forecasting capabilities of the model.
- Considering advanced techniques, such as ensemble models or combining multiple forecasting methods, to further enhance the accuracy of the predictions.
- Implementing different model architectures, such as variations of CNN-LSTM or other deep learning models, to compare their performance.
- Exploring different loss functions or evaluation metrics that are more suitable for the specific time series forecasting task.
Investing in the stock market involves risks, and it's important to conduct thorough research and analysis before making any investment decisions. The predictions generated by this model should be used as a tool for informational purposes only and should not be solely relied upon for investment purposes. **It's recommended to consult with financial advisors or professionals who specialize in the stock market before making any investment decisions. **
