- Wealth PMS (50L+)
As a geek and a trader, I’ve always been fascinated by the thought of “automated trading”. The idea is to have algorithms recognise patterns in stock market data, and automatically take on positions when something is favourable. But this is not just random pattern recognition – the whole area of technical analysis is a science that goes back 200 years (or some crazy number, basically it existed before I was born. And before you were born)
So the idea is that you first create a hypothesis. The hypothesis can be something simple (“Stocks go up in April”) to something complex (“A positive slope ADX with DI+ greater than DI-, combined with a reversing slower acceleration parabolic SAR switchover has a positive expectancy”). If you think the second one is a joke, think again – a number of traders use it.
The hypothesis can then be tested using historical data, automatically, by a computer program. The concept is simple – start with some equity at some past date. With the data on that date, would you take the position? If so, allocate the equity appropriately, reducing brokerage and other transaction costs. Also deal with “slippage” – a difference between noted price and what you will actually get (effect of a moving market).
Then go to the next available date, and consider your options again. Would you get out of your current position? (a “stop-loss” or “book-profit”) Would you reverse and short? (for systems that go both ways) Would you take on a fresh position?
All these are trading rules.
Consider also: Position sizing. How much do you allocate per trade? At what point does it make sense to get out on a portfolio level? Say you allocate maximum 2% risk per position – meaning for a 10 lakh portfolio the stop loss per position is Rs. 20,000 regardless of other considerations.
Some of these rules come together as “money management” rules.
The results of a historical back-test will show:
Once we have a back tested system, we have to analyse what works well and what does not. A system with phenomenal profitability – like 500% or something – is unrealistic , so you should be skeptical. Lots of things can make good results, but be a bad system in reality. Firstly, bad data – not all data available is representative of a real world – for example a few weeks ago, NSE reports that Reliance opened at Rs. 3,000 and that was the high of the day. The problem is it could be one trade of 1 share at this price, but if that makes your system look good, you are going to be in trouble when you really implement it. So discard such odd data points.
Second, you can overfit the system to past data. Let’s say the system was “Stocks go up in April”. That didn’t work. SO you said, ok let’s do “Stocks go up in May”. That doesn’t work either. So you add more rules like “April of every year which is an even number, but ignoring April 15, 16 and 17, unless one of them is a weekend, in which case you don’t take April 10, 11 and 12”. This may give you a phenomenal result tested in the past 10 years, but you have an overfit system – it is very unlikely to work in the future.
Once you have a system you like – I will talk about how to choose a system in a different post – you can then “paper trade” it. Meaning, run it and take the next few signals on some “virtual” money, and see if it works over a good period (of say 40-50 trades).
And if both the back test and paper-trade yield good results, you can start putting real money behind the calls. Remember you should continue to backtest as you move forward to see if the market scenario changes results dramatically.
If we were able to identify, back-test and paper trade systems, then can we set up a computer to trade some money automatically? This saves us time and effort to have to keep watching tickers – and instead, focus on building better systems. In theory this is possible but most brokers in India are loath to provide API access to their systems. There could be regulatory hassles to this too.
But my geekiness has prevailed and I think it’s possible to do – create a system, paper trade it and convert it to auto-trade. I have built two such systems, but what I will do is to take a simple system in another post and demonstrate how a system can be built, tested and paper-traded.
This is an exciting field – very old in the U.S. but extremely worthwhile in India to investigate. Even if one avoids technicals, a system based on “news” and “fundamentals” can be build – the code required for it is not dramatically different.
This, both Kaushik and I think, is the future of the stock markets in India. In the U.S. nearly 30% of volumes come from automated systems. It’s time this happens in India – not just will volumes increase, but more discipline will be maintained as computers can be made to follow rules strictly.
Let’s look at this some more in subsequent posts, but tell me – what do you think?