An advanced deep learning-based cryptocurrency price forecasting tool that uses LSTM neural networks to predict future price movements with confidence intervals.
- Historical price data fetching from cryptocurrency APIs
- Advanced LSTM model with technical indicators
- Monte Carlo simulation for uncertainty estimation
- Automatic CPU/GPU detection and optimization
- Beautiful visualization of forecasts with confidence intervals
- Automatic plot saving functionality
- Robust error handling and logging
- Python 3.7+
- TensorFlow 2.x
- NumPy
- Pandas
- Matplotlib
- Requests
- Scikit-learn
- Clone this repository:
git clone <repository-url>
cd <repository-name>
- Install the required packages:
pip install tensorflow numpy pandas matplotlib requests scikit-learn
The main functionality is provided through the ai_price_forecast
function in ai_forecast.py
:
from ai_forecast import ai_price_forecast
# Example usage
forecast_dates, prices, upper_bound, lower_bound = ai_price_forecast(
api_url="https://api.coingecko.com/api/v3",
crypto_id="bitcoin",
historical_days=180,
forecast_days=30
)
api_url
: Base URL for the cryptocurrency APIcrypto_id
: Identifier for the cryptocurrency (e.g., "bitcoin")historical_days
: Number of historical days to use for training (default: 180)forecast_days
: Number of days to forecast into the future (default: 30)seq_length
: Sequence length for LSTM input (default: 90)epochs
: Number of training epochs (default: 500)batch_size
: Batch size for training (default: 32)patience
: Early stopping patience (default: 30)model_path
: Path to save/load the model (optional)save_path
: Path to save the best model during training (optional)
Currently you are only prompted for forecast length
The model uses several technical indicators for improved forecasting:
- Moving averages (5, 10, and 20-day)
- Volatility measures
- Price momentum
- Rate of change indicators
- Automatic GPU detection and utilization when available
- Graceful fallback to CPU when GPU is unavailable or encounters errors
- Multi-core CPU optimization
- Historical price plots
- Forecast line with confidence intervals
- Automatic plot saving with timestamps
The function returns four lists:
- Forecast dates
- Forecasted prices
- Upper confidence bounds
- Lower confidence bounds
Plots are automatically saved in the forecast_plots
directory.
The system includes comprehensive error handling for:
- API connection issues
- Data processing errors
- Hardware configuration problems
- Model training issues
All errors are logged with detailed messages for debugging.
[Your chosen license]
Contributions are welcome! Please feel free to submit a Pull Request.