File size: 2,941 Bytes
49be941
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
---
tags:
- time-series
- forecasting
- cryptocurrency
- lstm
- finance
library_name: pytorch
license: mit
datasets:
- coingecko_daily
metrics:
- rmse
- mape
---

# CryptoPriceForecaster: Deep LSTM for Short-Term Price Trend Prediction

## 📑 Overview

**CryptoPriceForecaster** is a deep **Long Short-Term Memory (LSTM)** neural network optimized for predicting the closing price trend (i.e., the price change magnitude) of a major cryptocurrency (e.g., BTC/USD) over a short-term horizon (e.g., next 24 hours). It is trained on historical data including price, volume, and derived technical indicators.

## 🤖 Model Architecture

This is a custom deep learning model implemented in PyTorch/TensorFlow.

* **Type:** Recurrent Neural Network (RNN) - LSTM variant.
* **Input Features:** 10 features (e.g., Open, High, Low, Close, Volume, 7-day EMA, RSI, MACD Histogram, etc.).
* **Sequence Length:** 30 time steps (i.e., the model looks at the last 30 daily data points).
* **Layers:** 3 stacked LSTM layers.
    * `Hidden Size`: 128 units per layer.
    * `Dropout`: 0.2 applied between layers.
* **Output:** A single dense layer predicting the scaled *normalized* closing price. The predicted value needs to be inverse-transformed to get the actual price.

## 🎯 Intended Use

This model is designed for:
1.  **Short-Term Trading Strategy:** Generating daily signals for predicting price movement direction.
2.  **Research:** Studying the non-linear dependencies between technical indicators and price volatility.
3.  **Educational Purposes:** Demonstrating the use of RNNs for financial time-series forecasting.

## ⚠️ Limitations

* **Prediction vs. Reality:** This model predicts price based on historical and technical data; it does *not* account for Black Swan events, regulatory changes, or breaking news. **It is not financial advice.**
* **Generalization:** Trained primarily on BTC/USD daily data, its performance on altcoins or intraday data may be significantly lower.
* **Stationarity:** Requires pre-processed, potentially stationary, input data (e.g., log returns) for optimal performance.

## 💻 Example Code

Assuming the input data is a 3D numpy array `X_test` (batch_size, sequence_length, features):

```python
import torch
import numpy as np
from CryptoPriceForecaster_Model import LSTMForecaster # Custom model class

# Load the model weights and config
config = json.load(open("config.json"))
model = LSTMForecaster(**config) 
model.load_state_dict(torch.load("pytorch_model.bin"))
model.eval()

# Example input: 1 sample, 30 sequence length, 10 features
X_test_sample = np.random.rand(1, 30, 10).astype(np.float32) 
input_tensor = torch.from_numpy(X_test_sample)

with torch.no_grad():
    scaled_prediction = model(input_tensor)

# The output must be inverse-transformed using the original scaler (MinMaxScaler)
# For demonstration:
print(f"Scaled Predicted Price Change: {scaled_prediction.item():.4f}")