Introduction
This guide explores the design and training of an LSTM (Long Short-Term Memory) model to predict Bitcoin prices using historical hourly data. Our goal is to minimize the Root Mean Square Error (RMSE) between predicted and actual prices in test samples.
Key Components
1. Data Preparation
We analyze closing price sequences of three cryptocurrencies:
- Ethereum (ETH/USD)
- Tezos (XTZ/USD)
- Litecoin (LTC/USD)
Dataset Example:
from ccrypto import getMultipleCrypoSeries
import pandas as pd
ccpairs = ['BTCUSD', 'ETHUSD', 'XTZUSD', 'LTCUSD']
df = getMultipleCrypoSeries(ccpairs, freq='h', exch='Coinbase',
start_date='2019-08-09', end_date='2020-03-13')👉 Explore cryptocurrency datasets
2. Feature Engineering
- Labels: Bitcoin prices at 1-hour intervals
- Features: Lagged prices of correlated cryptocurrencies (ETH, XTZ, LTC)
Correlation Analysis:
plt.figure(figsize=(12,4))
plt.grid()
for win in range(3, 72): # Rolling window analysis
avg_corr1.append(df.ETHUSD.rolling(win).corr(df.BTCUSD).mean())Model Architecture
3. LSTM Network Design
- LSTM Units: 8540
- Dropout Rate: 10%
- Output Layer: Single-unit dense layer
import tensorflow as tf
model = tf.keras.models.Sequential()
model.add(tf.keras.layers.LSTM(units, input_shape=(1,8)))
model.add(tf.keras.layers.Dropout(0.1))
model.add(tf.keras.layers.Dense(1))4. Training Parameters
- Epochs: 3000
- Batch Size: 20% of training data
- Loss Function: Mean Squared Error (MSE)
Results and Analysis
5. Prediction Performance
- Test MSE: 0.01957
- Price Deviation Range: -$50 to +$250 during stable periods
Notable Limitation:
The model struggled to predict sudden COVID-19-induced price drops in March 2020.
👉 Learn advanced prediction techniques
FAQ Section
Q: Why use LSTM for cryptocurrency prediction?
A: LSTMs effectively capture temporal dependencies in time-series data, making them ideal for volatile assets like Bitcoin.
Q: How many data points are needed for training?
A: We used 4,972 hourly observations (95% of dataset) for training, with 260 samples reserved for testing.
Q: What other cryptocurrencies correlate with Bitcoin?
A: Ethereum and Litecoin show >80% correlation with Bitcoin across varying time windows.
Conclusion
This LSTM model demonstrates promising results in Bitcoin price prediction, though extreme market events remain challenging to forecast. Stay tuned for Series 2, where we'll enhance the model with advanced techniques.