Limited Period Offer:Be a PRO for 1 month @Rs49/-Multiple payment options available. Know More

# Algo trading: Here are five steps to set up your own algorithm

## The data collected has to be processed step by step with some rules or conditions. The conditions can be as simple as two moving averages crossovers or it can be extremely complex.

April 08, 2019 / 11:23 AM IST

Sovit Manjani

The dictionary definition of 'algorithm' is: A precise step-by-step plan for a computational procedure that possibly begins with an input value and yields an output value in a finite number of steps. Let’s break it into parts now.

Data collection phase:

Firstly, the system needs to have input. This can be anything from technical data like prices of stocks, commodities, indices, volume, option price, open interest, etc. or fundamental data like PE ratios, ROCE, Book Value, OPM, etc.

The data can also be news, special situations, inflation numbers, GDP numbers, interest rates, etc. The data is the key for any algorithm, and utmost care is to be taken to collect the data and clean it.

Close

If the data is incorrect then the results cannot be relied upon. In the computing world, it’s called garbage in and garbage out. The data has to be stored in a structured manner so that it can be retrieved as and when required.

This data can be sliced to in-sample data and out-of-sample data. The in-sample data means the data on which the rules are run and optimised. Out-of-sample data is the data that is unseen. The strategy once finalised is to be tested on this data for authenticity and confirmation.

Development phase:

The data collected has to be processed step by step with some rules or conditions. The conditions can be as simple as two moving averages crossovers or it can be extremely complex.

To create a viable system there has to be a hypothesis or in simple words, an idea. This idea has to be explained to the computer by a language. There are many computer languages which can be used but the most popular ones are Python, C++, Java, Julia, R and Amibroker Formula language.

Language selection depends on coder’s comfort, frequency of trades, acceptable latency, database size, etc. The back-test results are the output of the algorithm.

Care has to be taken for not adding unnecessary rules. Simple strategy with lesser and simple rules is much more robust than a complex strategy with too many conditions.

Optimisation phase:

After coding the idea, the system may or may not produce desirable risk-adjusted returns on the in-sample data. The strategy may be optimised by adding or removing certain rules.

If after multiple attempts, the strategy does not give decent results then the idea needs to be scrapped. The results may be optimised by changing some parameters. Care has to be taken as there is a danger of over-optimisation or curve fitting.

Testing or validation phase:

If the strategy looks decent then it is tested on the out-of-sample data. By decent result, one may assume a reward to risk ratio of at least 1.8 to 1.

The returns should beat the buy on hold returns and the max drawdown should not be more than 35 percent. These metrics are subjective depending on the nature of the strategy and the psychological ability of the executor.

Execution phase:

Only if the strategy survives in the out-of-sample data then it can be tested for execution. The strategy is then connected to the API of a broker for auto execution.

At this stage, some of the mistakes of system traders can be highlighted like wrong assumption of brokerages and slippage, liquidity, coding errors related to signal time and execution time.

The execution part has to be tested toughly with small order size like 1 share per signal for at least a month. Now your system is ready to be deployed on real money.

The author is Co-Founder, Head of Trading Strategies at Dravyaniti Consulting LLP.

Disclaimer: The views and investment tips expressed by investment expert on moneycontrol.com are his own and not that of the website or its management. Moneycontrol.com advises users to check with certified experts before taking any investment decisions.
Moneycontrol Contributor
first published: Apr 8, 2019 11:23 am