# Time Series Analysis of Cryptocurrency Prices Using Long Short-Term Memory
## 5 Implementation  
A first approach for predicting cryptocurrency was to gain the close data by scraping financial websites. A Python module to initially achieve this was _BeautifulSoup_, but the module was not an ideal solution as the script had to be rewritten every time the financial websites' structure or layout changed. Additionally, to predict lesser-known cryptocurrencies such as EOS, we also explored Kaggle; however, the datasets provided there were not a viable option as they were deprecated and out of date. Thus, the most promising method we found was to download historical price data through the _vfinance_ Python module, which returns the close values from the day of its first appearance on the market to the latest available price. Our neural network framework of choice is the long short-term memory (LSTM) model because it has a memory capacity. As we are using a time series dataset, which means the data are historical and regularly occur over a period of time, the memory capacity is ideal. The model can remember historical patterns and use them to generate predictions [17]. The Jupyter notebook iterates through a Python function, which normalizes the data using min-max normalization; fits a long short-term memory model using Keras, a Python deep-learning API; undergoes model predictions; saves the figures of predictions; and outputs a log file with detailed benchmarks. The notebook can be altered to include other cryptocurrency tickers as long as they are available on Yahoo Finance. The notebook is also able to analyze traditional stock tickers. The Python pseudocode for the Jupyter notebook program is shown in Figure 3.  
The code contains multiple loops that iterate through the hyperparameters, including each cryptocurrency, each quantity of epochs, and the number of repeats so that the results can be presented in a statistically sound manner. The program also allows us to perform multiple runs and to select the best set of parameters for maximum accuracy. For more details about the program, the code on GitHub is available and open-source [18]. The notebook's first phase involves downloading the cryptocurrency's historical data using _vfinance_[13]. The data undergo normalization so that the model accuracy is easier to compare between different cryptocurrencies with widely different values. Next, the close data are isolated because this experiment only focuses on the close price. The close data were divided into a training set and test set, which were subsequently split into their own x and y sets for the purposes of the Keras LSTM model. The learning model contains 250 units within its LSTM cell and is run through a dropout layer of 0.2 to prevent overfitting. Additionally, the model is run through a dense layer of 1 unit dimensionality to connect the neurons of the previous dropout layer. A diagram of the sequence of layers is shown in Figure 4. A visual description of the long short-term memory principle is showcased in [19]. Figure 2: The process of producing a time series cryptocurrency prediction line graph using LSTM. Our architecture allows easy modification of the entire model with more layers, but also the adaptation of the hyperparameters. Figures 5-7 use the EOS-USD dataset of close prices from 9 November 2017 to 30 June 2022. Within the trained model, only the 200 days at the end of the dataset are predicted so that the model learns from all of the prior days. After the model was trained through 100 epochs, the Python notebook generated Figure 5, a line graph of the prediction model. Since it is hard to see the difference between the blue line (with the true close prices) and the red prediction line of the last 200 days, Figure 6 zooms into that point for human readability. Figure 7 also shows the impact that epochs have on the accuracy of the prediction model. Figure 7 contains two graphed lines: a blue line representing the price of the EOS coin and a red line representing the model's prediction of the price.