Code Monkey home page Code Monkey logo

algobot3's Introduction

Algobot 3

Important Note

This is version 3 of my algorithmic trading platform, the second of which is written primarily in NodeJS. It is not in a working condition and was a sort of prototype for future revisions of the algobot platform.

Future revisions of the platform are listed below:

  1. algobot 1
  2. Algobot-elixir
  3. bot3 (this repository)
  4. bot4/Rustbot

Overview

Algobot 3 is an algorithmic trading bot that attempts to turn a profit by evaluating market conditions in FX markets and placing trades based on calculations.

It consists of a platform that processes live ticks, a backtesting system that enables fast testing of strategies, a manager web interface to monitor and control the bot, and a trade generator that uses modular strategies to place, manage, and close positions dynamically.

Platform

The platform is writte in NodeJS. It consists of a tick generator which processes incoming data and sends it to the algorithm core module. There, all of the necessary calculations are run on the data. Once they have been completed, this new data is sent to the trade generator for evaluation.

The bot is designed to run using live ticks. These are processed internally into larger time-frames as to avoid unecessary calcuations and database usage.

Multiple currency pairs can be monitored at the same time either using one instance of the tick processor or many as generated using the manager web interface. Each pair is handled individually from the others with data being kept separate from the bot's perspective.

Backtests

Each backtest is run on one pair at a time. They read saved tick data in CSV format that can be created using utilities in the data_downloaders directory. These ticks are played back to the bot in a variety of fashions with the end effect of simulating a live trading situation.

There are several types of backtests avaliable to the bot, each offering different benefits.

Live Backtest

Ticks are played back at the rate they were recieved.

This is the closest estimation actual bot performance avaliable and is best suited to mirror live trading conditions as closely as possible.

Fast Backtest

Ticks are played back at a constant rate. The rate they are sent at increases until CPU usage is too high, at which point they will be reduced to maintain equlibrium.

This kind of backtest is best suited for testing the bot's tick processing capabilities over an extended period of time as rapidly.

Pre-calculated Backtest

Pre-calculated backtests rely on a fast or live backtest being previously run. After that, the database is dumped to file. This database dump must be restored before the pre-calculted backtest can begin.

Instead of parsing ticks in an event-based fashion, the calculations and price updates are loaded from the database as a chunk. All calculations from one price update period are then packaged up together and sent to the trade generator.

This style of backtest is best suited for evaluating changes to an already created strategy over the same time period. It is the fastest backtest per tick as no calculations have to be run except those that are part of the trading strategy itself.

No-store Backtest

The largest bottleneck to the bot's performance is the database. Reading to and writing from the database takes up the vast majority of the bot's CPU time during normal execution.

In a no-store backtest, ticks are sent to the bot in an event-based fashion. As soon as the bot finishes the calculations and evalutes the strategy for a particular tick, it sends a message back to the backtester requesting the next tick.

In addition, no data is stored in the database (except for some trade states and other strategy-based data); all calculations are kept in-memory internally.

This backtest is best suited for testing a strategy's performance over new data or data that has not been perviously tested. Since a pre-calculated backtest relies on a fast or live backtest's results, this makes the no-store backtest the fastest option for testing a strategy from scratch.

Manager

The manager is a web interface that allows a user to control and manage the bot. The best way to start the bot is with node app.js -m, which launches only the manager web interface without any tick processing capabilities or backtests.

To start a backtest, first tick processor instances should be launched to handle all of the pairs that are planning on being tested and then starting backtests for each of those pairs.

Monitoring of execution is avaliable for live data as well as live, fast, and pre-calculated backtests. Analysis of backtest performance is planned.

Trade Generator

The trade generator is a container that evaluates modularly defined strategies. Every price update, the newest calculations and market conditions are piped to the trade generator which in turn sends them to all strategies and open position condition functions. (For more information about this process, see documentation in the trade_generator directory).

Data Downloaders

The data downloaders are used for obtaining historical data with which to run backtests. This data can come from many sources including broker APIs, websites, or flatfile storage.

FXCM

The FXCM data downloader uses the FXCM API in combination with the tick_recorder server to request data and store it to a csv. To use, first start up the tick_recorder/TickRecorder Java application. Once it has started, edit the download.js file and set the start time, stop time, pair, and other configuration options. To begin the download process, run node download.js.

Once the download finishes, run the script ./process.sh output/nameofcsv.csv. This will remove any duplicates that may have ended up in the csv as well as sort it. Due to the fact that the download process was made somewhat asynchronous to speed up download times, ticks can be written out of order making sorting necessary.

In addition to sorting and removing duplicates, the chunker.py script is also called which splits the csv into smaller csvs and produces index.csv in the tick_data directory. At this point, the data is in a format appropriate for backtesting.

Dukascopy

This script was originally the primary source of tick data for the bot. It worked by downloading compressed tick segments from Dukascopy's website which were then decompressed, organized, parsed, and saved to csv.

The quality of ticks as well as the ease of their aquisition is worse than the FXCM method, making this tick source obsolete.

algobot3's People

Contributors

ameobea avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

algobot3's Issues

[TODO] Performance improvements

โœ“ Reduce the amount of smas calculated to only calculate if the core algorithm has need of them.

Do anything possible to reduce the amount of queries made to the database.

Optimize the database by indexing the collections in ways that improve performance.

tickProcessor Output Failing

After a certain period of time passes from the launch of a tickProcessor, its stderr/stdout -> redis functionality seems to die. This may be from the function getting killed off after it fulfills or some other thing, but in any case output was NOT written to redis except right after the instance was launched,

add Dockerfile

I don't trust your code and would like a docker instance so I can be sure you aren't tampering with my machine

please fix soon :)

Tick data chunk size

The current size for a tick data chunk file is around 13mb. Once loaded into memory and parsed into an array of floats, that really adds up and on a 500mb dev server that amount of memory usage may not be viable in the future, especially when running many backtests simultaneously.

At some point, all or some tick_data needs to be re-chunked into smaller files.

Java FXCM API connect module crashes on internet interruption

Need to make it so that it can handle internet issues and deal with them instead of crashing completely.

ATM, the issue seems to stem from Jedis not being able to contact the redis server. Not sure about FXCM API connector, but I'm pretty sure that's able to deal with issues.

Conflict with Instance Spawning and Management

There is an issue when spawning backtests and tick processors that one ends up killing the other after being spawned. I expect this is due to some sort of bug where the database is being wiped at inappropriate times or the API is set up in a way that it doesn't work as it should.

Severe issues with mongodb performance

As backtests run for more than a few minutes, mongodb becomes incredibly slow and symptoms of overload become apparent such as system load reaching upwards of 200.

I believe this is due to poor indexing in the database as the database size increases, but I'm not 100% sure. If that is the case, it will absolutely be necessary to incorporate some kind of local cache for very highly regularly accessed data, namely ticks. That will probably be a good idea either way, as I predict the majority of calculations being made by the bot to be on rather short timeframes.

Database Number Rounding

All data stored in the database should be rounded off to an appropriate number of decimals before being stored.

Momentum Calculation Monstrosity

The momentum calculation code is evil. I believe at some point it left this world and commenced to exist partly in another dimension, because the hell of 5 layers of promises, three callbacks per function call, and disparity between the functions called in nostore core and normal core have made it impossible to understand let alone debug.

The majority (if not all of) the momentum calculation module needs to be re-written to work in a fashion that is compatible with both of the cores (nostore, precalc, normal). A good way to do this may to include the calls to the various callbacks to an callbacks object instead of listing them all and hoping some are undefined, or perhaps eliminating them altogether.

Backtest using pre-calculated figures

If backtesting multiple strategies over the same time periods is going to be a thing, it's going to be necessary to figure out a way to use pre-calculated data. Instead of re-calculating the same moving averages over and over, it would be a lot better to calculate them once and then come up with a backtester that loads them out of the database instead of going about re-calculating and storing them all over again.

Plan:

  1. Create a database dump utility that can dump and load a database on-demand
  2. Tweak algo_core and other necessary files to disable calculations and instead just read desired data from the database.
  3. Possibly include functionality to reduce/remove database reads + writes completely and test completely in-memory?

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.