Skip to main content

A package for LSTM-based financial time series forecasting

Project description

LSTM Forecast

Overview

LSTM Forecast is an advanced tool designed for predicting cryptocurrency prices using Long Short-Term Memory (LSTM) networks. This project combines cutting-edge deep learning techniques with comprehensive financial analysis, making it a robust solution for traders and data scientists alike.

With a focus on modularity and flexibility, LSTM Forecast provides a full suite of features including data loading, preprocessing, model training, hyperparameter optimization, backtesting, and API deployment. These tools enable users to build, evaluate, and deploy predictive models tailored to their specific needs, whether for academic research, financial analysis, or active trading.

Key Features

  • Data Loading and Preprocessing: Easily load and preprocess time series data from various sources, with built-in support for technical indicators.
  • Model Training: Train LSTM models with customizable architectures and hyperparameters to fit your specific use case.
  • Hyperparameter Optimization: Leverage advanced techniques like Optuna for automated hyperparameter tuning and feature selection.
  • Backtesting: Evaluate model performance using historical data with a fully integrated backtesting engine.
  • API Deployment: Deploy your trained models as RESTful APIs using FastAPI, enabling real-time predictions and integrations.
  • Command-Line Interface: A powerful CLI that simplifies all aspects of model training, evaluation, and deployment.

LSTM Forecast is designed to be both user-friendly and powerful, providing everything you need to create and deploy sophisticated forecasting models for cryptocurrencies and financial assets.

Table of Contents

Project Structure

.
├── LICENSE
├── README.md
├── config.json
├── data/
├── docs/
├── logs/
├── models/
│   ├── checkpoints/
│   └── optuna/
├── png/
├── pyproject.toml
├── reports/
├── requirements.txt
├── setup.py
├── src/
│   └── lstm_forecast/
│       ├── __init__.py
│       ├── api/
│       ├── backtesting/
│       ├── cli.py
│       ├── config.py
│       ├── data_loader.py
│       ├── early_stopping.py
│       ├── feature_engineering.py
│       ├── feature_selection.py
│       ├── generate_html.py
│       ├── hyperparameter_optimization.py
│       ├── logger.py
│       ├── model.py
│       ├── model_utils.py
│       ├── predict.py
│       ├── predict_utils.py
│       └── train.py
├── static/
└── tests/

Installation

Install with pip

If you want to use the latest stable version, you can install the package directly from PyPI:

pip install lstm-forecast

Install from sources

If you want to use the latest development version or contribute to the project, you can install from the source:

  1. Clone the repository:

    git clone https://github.com/gianlucamazza/lstm_forecast.git
    cd lstm_forecast
    
  2. Create a virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows use `venv\Scripts\activate`
    
  3. Install the required packages:

    pip install -r requirements.txt
    
  4. Install the project in editable mode:

    pip install -e .
    

This way, you'll have the latest version of the code and be able to make changes if needed.

Usage

The lstm_forecast command-line interface provides several subcommands for different functionalities:

Prepare Data

To prepare the data for training and prediction:

lstm_forecast prepare --config path/to/config.json

Optimize Hyperparameters and Feature Selection

To run hyperparameter optimization and feature selection:

lstm_forecast optimize --config path/to/config.json [OPTIONS]

Options:

  • --n_trials INTEGER: Number of trials for hyperparameter tuning (default: 100)
  • --n_feature_trials INTEGER: Number of trials for feature selection (default: 15)
  • --min_features INTEGER: Minimum number of features to select (default: 5)
  • --force: Force re-run of Optuna study

Train the Model

To train the model:

lstm_forecast train --config path/to/config.json

Make Predictions

To make predictions using a trained model:

lstm_forecast predict --config path/to/config.json

Start the API Server

To start the API server:

uvicorn lstm_forecast.api.app:app --reload

General Usage

All commands require a configuration file specified with the --config option. This JSON file contains all the necessary settings for data processing, model architecture, training, and prediction.

For more information on any command, you can use the --help option:

lstm_forecast [COMMAND] --help

Replace [COMMAND] with any of the available commands (prepare, optimize, train, predict, server) to see specific help for that command.

Configuration

The config.json file contains all the necessary settings for data processing, model architecture, training, and prediction. Modify this file to adjust parameters such as:

  • Data settings (ticker, date range, features)
  • Model settings (hidden size, number of layers, dropout)
  • Training settings (epochs, learning rate, batch size)
  • Backtesting parameters

API

The project includes a FastAPI-based API for model inference. To start the API server:

uvicorn lstm_forecast.api.app:app --reload

API endpoints:

  • /predict: Make predictions using the trained model
  • /backtest: Run backtesting on historical data

Backtesting

The backtesting module allows you to evaluate the model's performance on historical data. It includes:

  • Trading engine simulation
  • Performance metrics calculation
  • Visualization of results

To run a backtest:

lstm_forecast backtest --config path/to/config.json --model path/to/model.pth

Testing

To run the tests:

pytest tests/

Documentation

Comprehensive technical documentation is available at the following link:

View LSTM Forecast Documentation

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lstm_forecast-0.1.5.tar.gz (47.1 kB view details)

Uploaded Source

Built Distribution

lstm_forecast-0.1.5-py3-none-any.whl (53.0 kB view details)

Uploaded Python 3

File details

Details for the file lstm_forecast-0.1.5.tar.gz.

File metadata

  • Download URL: lstm_forecast-0.1.5.tar.gz
  • Upload date:
  • Size: 47.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for lstm_forecast-0.1.5.tar.gz
Algorithm Hash digest
SHA256 a7e9a1ca579d17070ace4837e738a8e3759e6497a494ccce0c9fd1033669b419
MD5 3b0fdb68c6978c762d49ab8c30d6d15b
BLAKE2b-256 000459e2b1bbe63c4d0424d49826edd7b1bf435e7f726e19333f91af7e8c75f2

See more details on using hashes here.

File details

Details for the file lstm_forecast-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for lstm_forecast-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 6b2d5eec7fc12ed1b0aa04846012c19720e422766728b152fa4ceef5a157ed2b
MD5 69fd7f8e9d03c7b4f79ec1d8517772cc
BLAKE2b-256 4382951e8d74a2a61de8e1e72555f5416a373147b209decf8bfdbc35957cd73b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page