This repository contains code and notebooks for a project focused on cryptocurrency price prediction. The project aims to explore and compare different machine learning approaches, including graph neural networks (GNNs) and Long Short-Term Memory (LSTM) models, to forecast cryptocurrency prices accurately.
Jupyter Notebook 100.00%
tgcn_lstm_for_crypto_forecasting's Introduction
Cryptocurrency Forecasting with LSTM and Dynamic GNN
This repository contains code and notebooks for a project focused on cryptocurrency price prediction. The project aims to explore and compare different machine learning approaches, including graph neural networks (GNNs) and Long Short-Term Memory (LSTM) models, to forecast cryptocurrency prices accurately.
Acknowledgments
Introduction
Cryptocurrency popularity necessitates accurate forecasting. There is a growing interest in cryptocurrencies as investment options.
There is high volatility in cryptocurrency prices.
Deep learning addresses volatility and nonlinear patterns.
LSTM and GNN models improve prediction accuracy.
Dynamic graphs with directed edges are used.
A constructive evaluation method is employed.
This empowers informed decision-making in the cryptocurrency market
Inovation
The proposed approach to the problem is entirely novel, as only one existing work utilizes graph neural networks for cryptocurrency price prediction
In that work, the graph structure remains fixed, and the correlations between cryptocurrencies remain unchanged over time.
However, this approach does not reflect real-life scenarios. Therefore, we employed dynamic graphs to capture the evolving correlations and investor behavior.
Proposed Method
Incorporating core financial indicators, time-related features, and categorical variables.
Proposing two different architectures: LSTM and GNN+LSTM.
LSTM:
Training one LSTM network for each cryptocurrency to capture the unique patterns and characteristics of a specific cryptocurrency.
The proposed LSTM architecture combines LSTM layers to capture long-term dependencies in historical price data.
It is followed by fully connected layers to capture complex relationships and includes dropout and batch normalization for overfitting prevention.
GNN+LSTM:
Utilizing the TGCN2 architecture based on graph neural networks.
Spatializing the problem by using graphs and converting each cryptocurrency into a node.
Constructing dynamic graph datasets with a temporal signal to capture changing relationships.
Constructing directed edges using the Granger causality test to capture predictive relationships between cryptocurrencies.
The GNN+LSTM architecture combines a GNN with a Bidirectional LSTM applied to the spatial dimension.
Dataset
The dataset encompasses the price history from 2021 to March 2023, consisting of 8,000 timesteps recorded at 4-hour intervals.
The dataset was divided into three sets for training (5,370 data points), validation (2,005 data points), and testing (622 data points).
Information on eight prominent cryptocurrencies is included: ADA, BNB, BTC, DASH, ETH, LINK, LTC, and XRP.
Key features such as high-low values, open-close values, and volume are available for each cryptocurrency.
Project Structure
The project is divided into several notebooks, each serving a specific purpose:
Data_preprocessing.ipynb: This notebook focuses on loading the raw data and preprocessing it to ensure it is in a suitable format, specifically a Pandas dataframe. The preprocessed data will serve as input for the subsequent notebooks.
Graph_Construction.ipynb: In this notebook, the data that has been transformed into a tabular format by the previous notebook is further processed to be in a suitable format for graph neural networks. The notebook handles the conversion of the data into an appropriate input format for graph-based models.
TGCN_model.ipynb: This notebook revolves around training and evaluating multiple architectures of graph neural networks. The focus is on implementing Temporal Graph Convolutional Networks (TGCN) and exploring their performance for the given task.
LSTM_model.ipynb: This notebook is dedicated to training and evaluating LSTM (Long Short-Term Memory) neural networks. The emphasis is on implementing and assessing the performance of LSTM models for the project.
Comparison_Popular_ML_Algo.ipynb: In this notebook, a variety of commonly used state-of-the-art machine learning algorithms are trained and evaluated. The goal is to conduct a fair comparison between these popular algorithms and the proposed method in the project.
Backtesting.ipynb: This notebook focuses on implementing a backtesting technique, which involves applying the trained models to real-life scenarios. The notebook explores how well the models perform in practical situations and evaluates their effectiveness.
Prerequisites
Usage
To get started with the project, follow these steps:
Clone this repository to your local machine.
Install the required dependencies using pip install -r requirements.txt.
Run the notebooks in the specified order to preprocess the data, train different models, compare algorithms, and perform backtesting.
Feel free to explore the code, experiment with different approaches, and modify the notebooks to suit your needs.