Building a Machine Learning Library for Forex Trading: Creating a toolbox of input/output generators

Through the past two years I have been making significant progress in the design and application of machine learning based systems for Forex trading. You can see in my blog articles how I have succeeded in the creation of Forex systems to trade across different time frames and pairs using a variety of different machine learning techniques and input/ouput descriptors (you can read here, here, here or here, for more information about my machine learning developments). However one of the things my approach has been missing is the creation of libraries that makes it easier for other traders to create strategies that use parts of my developments. Although I have always posted code within the Asirikuy community forum, such code is often difficult for users to implement for their particular purposes and it would therefore be ideal to put this code in a format that is much easier for users to use. Today I am going to talk about how I am building a machine learning library for Forex trading that is centered around the creation of a wide variety of input/output generator functions, which are the most tricky part for most traders attempting to tackle machine learning in FX.


When you want to create a machine learning strategy for trading, the first thing you need to create is an input/output structure. This structure contains a series of examples that you use for the training of the machine learning technique and then for actual trading. This input/output structure is in large responsible for the success or failure of your trading approach, as it determines what you want to predict and what information you will be using to predict it. The inputs and outputs can be a variety of different things, for example your inputs can be the simple returns of the past ten bars, the last five RSI values, the past 100, 20 period moving average results, etc; while your outputs can be whether the next bar is bearish or bullish, whether a given SL/TP is reached within 10 bars, whether a given indicator value increases/decreases within 5 bars, etc. It is clear that you can have a wide variety of input/output structures and having to create a generator for each one when you want to design a machine learning technique (especially a technique that retrains on every bar) can be quite challenging.

As you can see through my previous posts on machine learning, I have developed a wide variety of input/output generators that explore several different concepts. These generators are created using the shark C++ library, such that the only thing you need to do in order to take advantage of a given generator is to simply call its function. The only thing you need to consider is whether the input/output generator has a structure that is adequate for your problem (whether the input/output formatting is adequate for your method) as different methods might require different structures. For example a linear mapping algorithm might require an output formatted as a variable of type ClassificationDataset while a regression method would require an output formatted as a variable of type RegressionDataset. Once you determine the type of algorithm you need you can then use it for the training of your machine learning method.

By putting all the input/ouput generators within a library it will become very easy for other programmers to create a wide variety of machine learning approaches as they can easily choose and/or modify any given input/output structure to match their needs. Furthermore many of the generator functions have input parameters that allow you to control how the data is generated. For example a function that uses past bar returns as inputs can have a parameter controlling how many bars are used, or whether the return calculated is simple or logarithmic. Functions can also be long/short specific, such that a parameter needs to be passed in order to specify whether you’re making a prediction for the success of a bullish or bearish trade. My idea is to create a library that makes the construction of machine learning implementations quite intuitive and easy for those trades within Asirikuy who want to explore the world of machine learning.

Imagine you want to create a system that uses the input/output structure of one of my blog articles. This input/output structure might have taken me quite some time to develop and may involve using several different indicators and mathematical transformations. Instead of having to code this yourself or see how to implement my code within your current F4 framework implementation, you can simply call a function released within the next update and have my whole development at your fingertips.


The above also opens up the possibility to combine several different machine learning methods in the creation of machine learning strategies without a lot of thought. For example you may want to explore how a system mixing a linear classification and linear regression approach might behave. To do this you would need to write a function that creates an array with the desired input/output functions for both the classification and regression methods. If a library of input/output functions is available, it is as easy as writing two lines of code that invoke the functions for the creation of the desired data-frames before the training/testing of your machine learning implementation. Removing the often frustrating task – especially for novice programmers – of creating these input/output structures will certainly enhance our ability as a community to create new machine learning strategies.

The input/output library will be released within the next update of the F4 framework within Asirikuy. If you would like to learn more about system development and how you too can develop your own machine learning systems for Forex trading please consider joining, a website filled with educational videos, trading systems, development and a sound, honest and transparent approach towards automated trading in general . I hope you enjoyed this article ! :o)

Print Friendly, PDF & Email
You can leave a response, or trackback from your own site.

2 Responses to “Building a Machine Learning Library for Forex Trading: Creating a toolbox of input/output generators”

  1. ebw says:

    Hi Daniel,
    Great idea! I was wondering if you have/plan to release to the input/output library the input structure of the Asirikuy brain – the inputs that are image representations of each bar?

    • admin says:

      Hi Eric,

      Thanks for writing :o) The thing is that the input/output library is thought as an interface to the Shark library while the AsirikuyBrain is coded using FANN (so the input/output structure need to be recoded). To get an idea about how the input/output structure is generated you’ll have to look at the system’s code. However there is no reason why we couldn’t create an input/output function for Shark as well that mimics the Asirikuy Brain’s image system (let me add that to my to-do list).

      The input for the AsirikuyBrain’s image system (remember that this system is actually made of three different NN) is an image of the entire price chart, as you see it when you open a trading platform, with some image processing additions to make it much lighter and easier to process. Feel free to post on the forum if you have any further questions about this :o)

      Best Regards,


Leave a Reply

internal_server_error <![CDATA[WordPress &rsaquo; Error]]> 500