Hack Day 2018 – Algebros Algorithmic Trading

Hack Day 2018 was themed ‘Power to the People’, which offered a broad spectrum for interpretation. Enter team Algebros, the dynamic trio of Tom Pitts, Bodrul Alam and Jack Cusack. Our mission: to give power to the people – by giving power to the robots. Our project for this year’s hack day was to build an algorithmic trading system, using the Caplin Platform.

The plan

We planned to start off with some simple algorithms that the user could select and then tweak. Later on, we would also allow the user to build, back test and run their own custom algorithms.

We would implement this by creating an adapter (a Caplin Java DataSource ) that reads historical prices one tick (price event) at a time. At each tick, the user’s algorithm would determine whether to buy, sell, hold or do nothing.

For the first iteration, we would use open-high-low-closing (OHLC) data sets and so the tick frequency would be a very slow one tick per day, but the idea could be scaled to handle ticks at any frequency.

Back-testing would be an important part of the project. Generally speaking, back-testing is the method of running an algorithm over tradable financial products to see if it is profitable. Our plan was to run back tests over 10 years’ of UK and US stock prices, and 5 years’ of BTCUSD (BitCoin – US Dollar) exchange rates.

We decided that this iteration was for the casual investor and so would only allowed the algorithms to ‘go long’ (buy and then sell).

We saw potential for further studies using Alpha, Beta, drawdown etc, but on Hack Day itself we ran out of time to add these metrics to the published fields.

Hack day

We obtained historical prices in CSV format for various stocks. Each data set contained the following fields: Date, Open Price, High Price, Low Price, Close Price, and Volume.

Each row in an OHLC data set represents the opening, high, low, and closing prices for a single day’s trading. Our Java DataSource iterated over the rows in each dataset in accelerated time, using each row as a tick (price event).

The first algorithm was a Simple Moving Average (SMA) crossover detection. The adapter looked at the average price ((High + Low) / 2) of the previous 20 days and the previous 50 days. This means we are investing when there is momentum behind the price over a long period of time, giving a strong signal that price is increasing. When the 20 day moving average is greater than the 50 day moving average, this is a bullish signal to go long and so the adapter would buy at the price of the open of the next day. The inputs that the adapter took in this case were two periods 20 and 50 days, allowing for some control of the algorithm.

The second algorithm is more complicated as we converted the prices read by the adapter into a format known as Heikin Ashi, developed by Munehisa Homma in the 1700s. This technique uses two period averages that if plotted on a graph, gives the movement of price a smoother appearance, making it easier to spot trends.  The idea was to look through a customer’s eyes, convert how they currently trade using a graph where they spot trends into an algorithm that can trade on their behalf. The algorithm would look at the last 3 days’ prices and if there was a strong positive trend, then buy the stock on the open of the next day. As with the first algorithm, we allowed the user to customise the algorithm by tweaking the periods that the algorithm used.

Finally, we provided a means to submit an algorithm to our adapter, which would then be processed and applied during ticks. We did this by leveraging JavaScript and providing the user with information about what data could be accessed.

So they could write their algorithm as follows:

if(OHLC[-1].close > OHLC[-2].close)
    return BUY

We tried to reduce the burden on the user as much as possible, so all they need to understand is that OHLC[-1] returns yesterday’s price, and OHLC[-2] the day before that, and the number could be changed to go back whatever number of days/ticks they would need.

With basic knowledge of how an if statement works and the requirement that it should return either BUY or SELL, users would be able build out their algorithm.

After a user submits a JavaScript algorithm to the adapter, it is compiled using Java’s ScriptEngine and run on each price tick.

The project was successful, and we came second place. Looking to the future, we would like to package the adapter as a Caplin Platform blade, increase the parameters available to algorithms, and test performance at higher tick frequencies.

Leave a Reply

Your e-mail address will not be published. Required fields are marked *