lstm-forecast


Namelstm-forecast JSON
Version 0.1.2 PyPI version JSON
download
home_pagehttps://github.com/gianlucamazza/lstm_forecast
SummaryA package for LSTM-based financial time series forecasting
upload_time2024-08-10 22:23:18
maintainerNone
docs_urlNone
authorGianluca Mazza
requires_python>=3.7
licenseMIT
keywords lstm forecasting finance time series deep learning
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # LSTM Forecast

 
## Overview

This project implements an LSTM-based model for predicting cryptocurrency prices. It includes features for data loading, preprocessing, model training, hyperparameter optimization, backtesting, and API deployment.

## Table of Contents

- [LSTM Forecast](#lstm-forecast)
  - [Overview](#overview)
  - [Table of Contents](#table-of-contents)
  - [Project Structure](#project-structure)
  - [Installation](#installation)
    - [Install with pip](#install-with-pip)
    - [Install from sources](#install-from-sources)
  - [Usage](#usage)
    - [Prepare Data](#prepare-data)
    - [Optimize Hyperparameters and Feature Selection](#optimize-hyperparameters-and-feature-selection)
    - [Train the Model](#train-the-model)
    - [Make Predictions](#make-predictions)
    - [Start the API Server](#start-the-api-server)
    - [General Usage](#general-usage)
  - [Configuration](#configuration)
  - [API](#api)
  - [Backtesting](#backtesting)
  - [Testing](#testing)
  - [License](#license)

## 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:

```
lstm_forecast server --config path/to/config.json
```

### 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/
```

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/gianlucamazza/lstm_forecast",
    "name": "lstm-forecast",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "lstm forecasting finance time series deep learning",
    "author": "Gianluca Mazza",
    "author_email": "gmazza1989@proton.me",
    "download_url": "https://files.pythonhosted.org/packages/b9/d7/43e3389ec77ac20bf9eeb6999502eedb1d92a34f715a0788e59bd09e85db/lstm_forecast-0.1.2.tar.gz",
    "platform": null,
    "description": "# LSTM Forecast\n\n \n## Overview\n\nThis project implements an LSTM-based model for predicting cryptocurrency prices. It includes features for data loading, preprocessing, model training, hyperparameter optimization, backtesting, and API deployment.\n\n## Table of Contents\n\n- [LSTM Forecast](#lstm-forecast)\n  - [Overview](#overview)\n  - [Table of Contents](#table-of-contents)\n  - [Project Structure](#project-structure)\n  - [Installation](#installation)\n    - [Install with pip](#install-with-pip)\n    - [Install from sources](#install-from-sources)\n  - [Usage](#usage)\n    - [Prepare Data](#prepare-data)\n    - [Optimize Hyperparameters and Feature Selection](#optimize-hyperparameters-and-feature-selection)\n    - [Train the Model](#train-the-model)\n    - [Make Predictions](#make-predictions)\n    - [Start the API Server](#start-the-api-server)\n    - [General Usage](#general-usage)\n  - [Configuration](#configuration)\n  - [API](#api)\n  - [Backtesting](#backtesting)\n  - [Testing](#testing)\n  - [License](#license)\n\n## Project Structure\n\n```\n.\n\u251c\u2500\u2500 LICENSE\n\u251c\u2500\u2500 README.md\n\u251c\u2500\u2500 config.json\n\u251c\u2500\u2500 data/\n\u251c\u2500\u2500 docs/\n\u251c\u2500\u2500 logs/\n\u251c\u2500\u2500 models/\n\u2502   \u251c\u2500\u2500 checkpoints/\n\u2502   \u2514\u2500\u2500 optuna/\n\u251c\u2500\u2500 png/\n\u251c\u2500\u2500 pyproject.toml\n\u251c\u2500\u2500 reports/\n\u251c\u2500\u2500 requirements.txt\n\u251c\u2500\u2500 setup.py\n\u251c\u2500\u2500 src/\n\u2502   \u2514\u2500\u2500 lstm_forecast/\n\u2502       \u251c\u2500\u2500 __init__.py\n\u2502       \u251c\u2500\u2500 api/\n\u2502       \u251c\u2500\u2500 backtesting/\n\u2502       \u251c\u2500\u2500 cli.py\n\u2502       \u251c\u2500\u2500 config.py\n\u2502       \u251c\u2500\u2500 data_loader.py\n\u2502       \u251c\u2500\u2500 early_stopping.py\n\u2502       \u251c\u2500\u2500 feature_engineering.py\n\u2502       \u251c\u2500\u2500 feature_selection.py\n\u2502       \u251c\u2500\u2500 generate_html.py\n\u2502       \u251c\u2500\u2500 hyperparameter_optimization.py\n\u2502       \u251c\u2500\u2500 logger.py\n\u2502       \u251c\u2500\u2500 model.py\n\u2502       \u251c\u2500\u2500 model_utils.py\n\u2502       \u251c\u2500\u2500 predict.py\n\u2502       \u251c\u2500\u2500 predict_utils.py\n\u2502       \u2514\u2500\u2500 train.py\n\u251c\u2500\u2500 static/\n\u2514\u2500\u2500 tests/\n```\n\n## Installation\n\n### Install with pip\n\nIf you want to use the latest stable version, you can install the package directly from PyPI:\n\n```\npip install lstm-forecast\n```\n\n### Install from sources\n\nIf you want to use the latest development version or contribute to the project, you can install from the source:\n\n1. Clone the repository:\n   ```\n   git clone https://github.com/gianlucamazza/lstm_forecast.git\n   cd lstm_forecast\n   ```\n\n2. Create a virtual environment:\n   ```\n   python -m venv venv\n   source venv/bin/activate  # On Windows use `venv\\Scripts\\activate`\n   ```\n\n3. Install the required packages:\n   ```\n   pip install -r requirements.txt\n   ```\n\n4. Install the project in editable mode:\n   ```\n   pip install -e .\n   ```\n\nThis way, you'll have the latest version of the code and be able to make changes if needed.\n\n## Usage\n\nThe `lstm_forecast` command-line interface provides several subcommands for different functionalities:\n\n### Prepare Data\n\nTo prepare the data for training and prediction:\n\n```\nlstm_forecast prepare --config path/to/config.json\n```\n\n### Optimize Hyperparameters and Feature Selection\n\nTo run hyperparameter optimization and feature selection:\n\n```\nlstm_forecast optimize --config path/to/config.json [OPTIONS]\n```\n\nOptions:\n- `--n_trials INTEGER`: Number of trials for hyperparameter tuning (default: 100)\n- `--n_feature_trials INTEGER`: Number of trials for feature selection (default: 15)\n- `--min_features INTEGER`: Minimum number of features to select (default: 5)\n- `--force`: Force re-run of Optuna study\n\n### Train the Model\n\nTo train the model:\n\n```\nlstm_forecast train --config path/to/config.json\n```\n\n### Make Predictions\n\nTo make predictions using a trained model:\n\n```\nlstm_forecast predict --config path/to/config.json\n```\n\n### Start the API Server\n\nTo start the API server:\n\n```\nlstm_forecast server --config path/to/config.json\n```\n\n### General Usage\n\nAll 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.\n\nFor more information on any command, you can use the `--help` option:\n\n```\nlstm_forecast [COMMAND] --help\n```\n\nReplace `[COMMAND]` with any of the available commands (prepare, optimize, train, predict, server) to see specific help for that command.\n\n## Configuration\n\nThe `config.json` file contains all the necessary settings for data processing, model architecture, training, and prediction. Modify this file to adjust parameters such as:\n\n- Data settings (ticker, date range, features)\n- Model settings (hidden size, number of layers, dropout)\n- Training settings (epochs, learning rate, batch size)\n- Backtesting parameters\n\n## API\n\nThe project includes a FastAPI-based API for model inference. To start the API server:\n\n```\nuvicorn lstm_forecast.api.app:app --reload\n```\n\nAPI endpoints:\n- `/predict`: Make predictions using the trained model\n- `/backtest`: Run backtesting on historical data\n\n## Backtesting\n\nThe backtesting module allows you to evaluate the model's performance on historical data. It includes:\n\n- Trading engine simulation\n- Performance metrics calculation\n- Visualization of results\n\nTo run a backtest:\n\n```\nlstm_forecast backtest --config path/to/config.json --model path/to/model.pth\n```\n\n## Testing\n\nTo run the tests:\n\n```\npytest tests/\n```\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A package for LSTM-based financial time series forecasting",
    "version": "0.1.2",
    "project_urls": {
        "Bug Tracker": "https://github.com/gianlucamazza/lstm_forecast/issues",
        "Documentation": "https://github.com/gianlucamazza/lstm_forecast#readme",
        "Homepage": "https://github.com/gianlucamazza/lstm_forecast",
        "Source Code": "https://github.com/gianlucamazza/lstm_forecast"
    },
    "split_keywords": [
        "lstm",
        "forecasting",
        "finance",
        "time",
        "series",
        "deep",
        "learning"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "25023b23ff44f47d25faeffc2361f7980c76032a5a517dc039470774f5fc120e",
                "md5": "1e220a7c4e970d05c9b55e322d7aae47",
                "sha256": "126189113bcaa01fe04b0a449c280fb0476e55817d22c7ce08c29da7ed6f832f"
            },
            "downloads": -1,
            "filename": "lstm_forecast-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1e220a7c4e970d05c9b55e322d7aae47",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 52196,
            "upload_time": "2024-08-10T22:23:16",
            "upload_time_iso_8601": "2024-08-10T22:23:16.703782Z",
            "url": "https://files.pythonhosted.org/packages/25/02/3b23ff44f47d25faeffc2361f7980c76032a5a517dc039470774f5fc120e/lstm_forecast-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b9d743e3389ec77ac20bf9eeb6999502eedb1d92a34f715a0788e59bd09e85db",
                "md5": "2b1cfdba12ef69d93711c5b35e98ee8e",
                "sha256": "11de7316fe8c0a74de7b7031b443ff47d4cd25e02d474aa6591a4e48a16d14d4"
            },
            "downloads": -1,
            "filename": "lstm_forecast-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "2b1cfdba12ef69d93711c5b35e98ee8e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 45491,
            "upload_time": "2024-08-10T22:23:18",
            "upload_time_iso_8601": "2024-08-10T22:23:18.353435Z",
            "url": "https://files.pythonhosted.org/packages/b9/d7/43e3389ec77ac20bf9eeb6999502eedb1d92a34f715a0788e59bd09e85db/lstm_forecast-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-10 22:23:18",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "gianlucamazza",
    "github_project": "lstm_forecast",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "lstm-forecast"
}
        
Elapsed time: 0.99757s