Giter VIP home page Giter VIP logo

optimizer's Introduction

RL-Optimizer

Description

RL-Optimizer is a powerful and flexible tool designed for optimizing reinforcement learning agents in various environments, with support for dynamic plugins. It utilizes multiple optimization techniques, including NEAT, NEAT_P2P, and those supported by OpenRL, to optimize models controlling trading agents. The tool is capable of handling multi-asset trading environments, making it highly versatile for both training and evaluation tasks in the domain of financial trading and beyond.

Key Features:

  • Dynamic Plugins: Easily switch between different optimizer techniques (e.g., NEAT, NEAT_P2P, OpenRL algorithms), environments (e.g., gym-fx for multi-asset management), and agents.
  • Configurable Parameters: Customize the optimization process with parameters such as trading actions, portfolio balancing strategies, and evaluation metrics.
  • Model Management: Save and load models for reuse, avoiding the need to retrain models from scratch.
  • Remote Configuration: Load and save configurations remotely, facilitating seamless integration with other systems and automation pipelines.
  • Incremental Search: Optimize the model parameters dynamically during training to achieve the best performance based on specified error thresholds.

This tool is designed for data scientists, machine learning engineers, and financial analysts who need to optimize trading strategies and models efficiently, and it can be easily integrated into larger machine learning workflows.

Installation Instructions

To install and set up the RL-Optimizer application, follow these steps:

  1. Clone the Repository:

    git clone https://github.com/harveybc/rl-optimizer.git
    cd rl-optimizer
  2. Create and Activate a Virtual Environment (Anaconda is required):

    • Using conda:
      conda create --name rl-optimizer-env python=3.9
      conda activate rl-optimizer-env
  3. Install Dependencies:

    pip install --upgrade pip
    pip install -r requirements.txt
  4. Build the Package:

    python -m build
  5. Install the Package:

    pip install .
  6. (Optional) Run the RL-Optimizer:

    • On Windows, run the following command to verify installation:

      rl-optimizer.bat tests/data/encoder_eval.csv -ytf tests/data/csv_sel_unb_norm_512.csv -of output_predictions.csv -sm trained_model.pkl -op neat -ep prediction -ap neat 
      
    • On Linux, run:

      sh rl-optimizer.sh tests/data/encoder_eval.csv -ytf tests/data/csv_sel_unb_norm_512.csv -of output_predictions.csv -sm trained_model.pkl -op neat -ep prediction -ap neat 
      
  7. (Optional) Run Tests:

    • On Windows, run the following command to run the tests:

      set_env.bat
      pytest
    • On Linux, run:

      sh ./set_env.sh
      pytest
  8. (Optional) Generate Documentation:

    • Run the following command to generate code documentation in HTML format in the docs directory:
      pdoc --html -o docs app
  9. (Optional) Install Nvidia CUDA GPU support:

Usage

The application supports several command line arguments to control its behavior:

usage: rl-optimizer.bat tests\data\config.json

Command Line Arguments

Required Arguments

  • config_file (str): Path to the configuration JSON file.

Optional Arguments

  • -of, --output_file (str): Path to the output CSV file.
  • -sm, --save_model (str): Filename to save the trained model.
  • -lm, --load_model (str): Filename to load a trained model from.
  • -ef, --evaluate_file (str): Filename for outputting evaluation results.
  • -op, --optimizer_plugin (str, default='neat'): Name of the optimizer plugin to use.
  • -ep, --environment_plugin (str, default='gym_fx'): Name of the environment plugin to use.
  • -ap, --agent_plugin (str, default='agent_multi'): Name of the agent plugin to use.
  • -te, --threshold_error (float): Error threshold to stop the optimization process.
  • -rl, --remote_log (str): URL of a remote API endpoint for saving debug variables in JSON format.
  • -rlc, --remote_load_config (str): URL of a remote JSON configuration file to download and execute.
  • -rsc, --remote_save_config (str): URL of a remote API endpoint for saving configuration in JSON format.
  • -u, --username (str): Username for the API endpoint.
  • -p, --password (str): Password for the API endpoint.
  • -lc, --load_config (str): Path to load a configuration file.
  • -sc, --save_config (str): Path to save the current configuration.
  • -sl, --save_log (str): Path to save the current debug info.
  • -qm, --quiet_mode (flag): Suppress output messages.
  • -fd, --force_date (flag): Include date in the output CSV files.
  • -inc, --incremental_search (flag): Enable incremental search for interface size.

Examples of Use

Optimization Example

To optimize an agent using the NEAT optimizer with the gym-fx environment and agent-multi plugin, use the following command:

rl-optimizer.bat tests\data\EURUSD_hour_2010_2020.csv --y_train_file ..\Documents\encoder_eval_close_eurusd_1h_norm_10y.csv --environment_plugin automation --optimizer_plugin neat_automation --agent_plugin neat_automation

Project Directory Structure

rl-optimizer/
│
├── app/                           # Main application package
│   ├── cli.py                    # Handles command-line argument parsing
│   ├── config.py                 # Stores default configuration values
│   ├── config_handler.py         # Manages configuration loading, saving, and merging
│   ├── config_merger.py          # Merges configuration from various sources
│   ├── data_handler.py           # Handles data loading and saving
│   ├── data_processor.py         # Processes input data and runs the optimization pipeline
│   ├── main.py                   # Main entry point for the application
│   ├── plugin_loader.py          # Dynamically loads optimizer, environment, and agent plugins
│   └── plugins/                  # Plugin directory
│       ├── optimizer_plugin_neat.py        # Optimizer plugin using NEAT
│       ├── optimizer_plugin_neat_p2p.py    # Optimizer plugin using NEAT_P2P
│       ├── optimizer_plugin_openrl.py      # Optimizer plugin using OpenRL
│       ├── environment_plugin_prediction.py # Environment plugin for prediction
│       └─ agent_plugin_predictor.py       # Agent plugin for prediction
│
├── tests/              # Test modules for the application
│   ├── acceptance          # User acceptance tests
│   ├── system              # System tests
│   ├── integration         # Integration tests
│   └── unit                # Unit tests
│
├── README.md                     # Overview and documentation for the project
├── requirements.txt              # Lists Python package dependencies
├── setup.py                      # Script for packaging and installing the project
├── set_env.bat                   # Batch script for environment setup
├── set_env.sh                    # Shell script for environment setup
└── .gitignore                         # Specifies intentionally untracked files to ignore

Contributing Contributions to the project are welcome! Please refer to the CONTRIBUTING.md file for guidelines on how to make contributions.

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

optimizer's People

Contributors

harveybc avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.