Skip to content

Python-based trading framework designed for high-performance backtesting, hyperparameter optimization, and live trading.

Notifications You must be signed in to change notification settings

cyclux/tradeforce

Repository files navigation

Tradeforce

Python Trading Framework

Tradeforce is a comprehensive Python-based trading framework designed for high-performance backtesting, hyperparameter optimization, and live trading. By leveraging Just-In-Time (JIT) machine code compilation, Tradeforce is able to run trading simulations on whole markets (100+ assets) covering years of historical data. This benefit of speed allows to find optimal hyperparameters of trading algorithms within large search spaces in a reasonable amount of time. Setups via Docker compose stack offer flexible deployment options and enable scalability to cluster environments.

Features

  • Numba accelerated simulations, processing 100k+ records / second / thread
  • Customizable trading strategies
  • Dedicated market server supporting 100+ simultaneous WebSocket connections
  • Backend support for PostgreSQL and MongoDB
  • Local caching of market data in Arrow format for rapid loading times
  • Hyperparameter optimization through the Optuna framework
  • Live trading capabilities
  • Easy and flexible deployment via Docker
  • Scalable to cluster environments, such as Kubernetes
  • Jupyter Notebook integration for analysis and visualization of results

Feature support

Supported features depend on the choice of database backend:

Market Server Simulations Live Trading Optuna
Postgres
MongoDB
Local Cache

For a more detailed explanation of the differences see the Storage section of the documentation.

Note - The recommended setup with Docker compose includes
Postgres as backend and is therefore fully featured.

Architecture

Note - See the Documentation for a more detailed description of the architecture.

Installation

Docker (recommended)

Requirements

  1. Download the docker and examples folders from this repository
    or git clone the whole repository and cd into the docker folder:

    git clone https://github.com/cyclux/tradeforce.git
    cd docker
  2. Spin up the Docker compose stack:

    docker compose up
    
    # or detached to run in the background
    # and get the console back
    docker compose up -d

    This will spin up following services specified in docker/docker-compose.yml:

    Check out the docker folder for further examples of deployment options.

    Note - On the first run of docker compose up the images of the services
    specified in docker/docker-compose.yml will be fetched from Docker Hub.

pip

Requirements

  • Python 3.10+
  • Optional: Postgres or MongoDB instance.
    See feature support for limitations without database backend.
  1. Create virtual environment (optional)

    # Create environment
    python3 -m venv tradeforce
    
    # Activate environment
    source tradeforce/bin/activate

    Note - The environment name "tradeforce" is arbitrary and can be changed.

  2. Install via pip

    pip install tradeforce
    

Usage

Run modes

Tradeforce can be run in different modes depending on the use case:

Note - See Documentation: Run modes for more details on how to use and configure the different run modes.

Configuration

See the Configuration Documentation which details all the available config options.

Generally Tradeforce can either be configured via

  • Python dictionary:

    from tradeforce import Tradeforce
    
    CONFIG = {
        ...
    }
    
    sim_result = Tradeforce(config=CONFIG).run_sim()

    Note - See simulator_simple_dict.py for a working example.

  • YAML file:

    from tradeforce import Tradeforce
    
    sim_result = Tradeforce(config_file="config.yaml").run_sim()

    Note - See simulator_simple_yaml.py and config.yaml for a working example.

Shell in container

In some use cases it might be helpful to open a shell in the Tradeforce container. For instance if docker compose is run in detached mode: docker compose up -d.

To connect to the Tradeforce container and open a bash shell run:

docker exec -it tradeforce bash

Note - Here tradeforce refers to the container_name specified in docker/docker-compose.yml
and might defer depending on the deployment option or setup.

DISCLAIMER

Warning Use at your own risk! Tradeforce is currently in beta, and bugs may occur.
Furthermore, there is no guarantee that strategies that have performed well
in the past will continue to do so in the future.

Build

Get requirements.txt from container

cd /path/to/tradeforce/Dockerfile
docker build -t tradeforce:build --target build .
docker create --name tradeforce_build tradeforce:build
docker cp tradeforce_build:/opt/tradeforce/requirements.txt ./requirements.txt

Build production stage

cd /path/to/tradeforce/Dockerfile
docker build -t cyclux/tradeforce:latest -t cyclux/tradeforce:0.0.1 --target production .
docker push -a cyclux/tradeforce

Note - Here cyclux refers to the Docker Hub repo / user name and needs to be changed accordingly.

About

Python-based trading framework designed for high-performance backtesting, hyperparameter optimization, and live trading.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages