Giter Club home page Giter Club logo

algotrading's Introduction

AlgoTrading

This project aims to combine Neural Networks and Genetic programming to create a trading algortihm able to perform consistently in different market conditions.
To achive this result we divide the problem in two steps:

  1. First we train a set of strategies to trade on a specific market.
  2. Then we train a trading system which select different strategies and dynamically allocate capital to each strategy based on broad market conditions.

Strategies

A strategy is composed of two layers:

  1. Feature extraction: This layer uses a customized version of Cartesian Genetic Programming to extract features from the market data. It does so by combining techinal indicators and selectors, technical indicators are just the usual indicators used in technical analysis, while selectors are used to select and perform operations on a subset of the indicators to create new features.
  2. Trading logic: This layer uses a Neural Network to decide when to buy and sell. The input of the Neural Network is the features extracted by the previous layer and the output is the decision to buy, sell or hold. The neural newtrok is tradined with reinforcement learning using an evolution strategy.

Both layers are combined and trained concurrently by simulating the trading on historical data, the objective is a custom metric that combines the return and the drawdown of the strategy, to incentivize the strategy to produce consistent returns.

Trading System

A trading system is composed of two layers:

  1. Feature extraction: Similar to the strategy, this layer uses a customized version of Cartesian Genetic Programming to extract features from the market data. The difference is that the features are extracted from different markets.
  2. Capital allocation: This layer uses a Neural Network to decide how to allocate capital to each strategy. The input of the Neural Network is the features extracted by the previous layer and the output is the allocation of capital to each strategy. The neural newtrok is tradined with reinforcement learning using an evolution strategy.

The training is similar to the strategy, the objective is to maximize the return of the trading system while keeping, drawdown and volatility low.

Training

The training happens in two stages:

  1. Strategy training: A set of stretgies is trained on a specific market, the training is done by simulating the trading on historical data. The top performing strategies are selected.
  2. Trading system training: A trading system is trained using the top performing strategies from the previous step.

The detailed explanation of how to train a neural network using evolution startegies can be found here

The project is optimized to run on a large number of cores, with a main process resposible for the overall training and a set of worker processes responsible for the simulations thus calculating the fitness of the strategies and the trading system. I tested the project succescfully on a 256 core machine.

Deployment

After the training is complete the trading system is ready to be deployed for live trading and backtesting. The project contains a simple server that can recive market data and send back the trading signals. I was able to integrate project with the "CTrader" a trading platform that allows to create custom trading bots in C#.

Results

The project was able to consistently produce trading systems capable of producing high and consistent profits in backtesting, however the results in live trading were not as good. Despite having carefully design the fitness metric to prevent overfitting the limited amount of data was likely the cause of the poor results.

Usage

To train a pool of strategies:

  1. Create a configuration file with the parameters of the training (see configs/strat_creation.yml for an example)
  2. Run julia train_strat.jl configs/strat_creation.yml

To train a trading system:

  1. Create a configuration file with the parameters of the training (see configs/trad_sys_creation.yml for an example)
  2. Run julia train_trad_sys.jl configs/trad_sys_creation.yml

To evaluate a trading system:

  1. Create a configuration file with the parameters of the evaluation (see configs/trad_sys_evaluation.yml for an example)
  2. Run julia utils.jl evaluate configs/trad_sys_evaluation.yml

To serve a trading system:

  1. Create a configuration file with the parameters of the deployment (see configs/trad_sys_serving.yml for an example)
  2. Run julia utils.jl serve configs/trad_sys_serving.yml

To clean the pool of strategies and take only the top performing ones:

  1. Create a configuration file with the parameters of the cleaning (see configs/strat_clean.yml for an example)
  2. Run julia utils.jl clean-strat configs/strat_clean.yml

To clean the pool of trading systems and take only the top performing ones:

  1. Create a configuration file with the parameters of the cleaning (see configs/trad_sys_clean.yml for an example)
  2. Run julia utils.jl clean-trad-sys configs/trad_sys_clean.yml

algotrading's People

Contributors

cesch97 avatar

Watchers

 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.