Stairway to Quant Trading - Part 2

Dynamic Trading System Programming

To run your trading strategies in a real time environment is different from backtesting your ideas on a full set of data, though they have lots of similarities and both called “dynamic”.

A simplified analogy used by the most basic Physics idea: If you have a relative movement with a target, either you are moving or the target is moving. This the word “Dynamic” means in a trading system–Either your data is static and the strategy loops for each data, or your strategy keeps passive and is triggered by the continuous coming data at every moment. For most of the trading platforms, they are the latter. By some means they have to be the latter since this is how data flows in live trading. However in backtests we prefer to the former one. A typical example is that we put those historical data in Excel and loop our strategies for each or a series of data, to gain the PnL from results then make judgements about strategies. Why would we use two different ideas in backtesting and live trading? It is not hard to understand because that is the way how humans regard histories–Stay in current trying to predict the future with knownledges about the past. The question is, what is the differences between static backtesting and real time trading? I hope my answer could offer a methodological perspective in explaining why good performed strategy in backtest fails in live trading.

Fixed Data and Flowing Data

For static backtesting we shall have a start point and an end point, it is convenient to obtain historical informations since a specific data will correspond to a fix position in our set. For example if our backtest starts at 2017-01-01, 2017-01-02’s data must be in the second row of the line (regardless of closed market). However in a live market, obtaining history data would be a bit harder. Assume we stand at 2017-01-03, 2017-01-02’s data would one daily bar before. If date moves to 2017-01-04, it becomes two bars. In this condition we have to first calculate a dynamic time span and then traceback that span, which influences the way we look history. This problem affects not only on date time issues, but also on safety control–Imagine in a high frequence trading market, if data comes faster than the time of calculating the time span (this is possible since in some markets closed price is not sampled by a fixed time, it is created whenever a trade happens. If two orders are executed in a very close time, your calculation may be slower than that), the method here would be a serious fault.

Statistics Problem

In backtesting we are facing an all known data set, it would be decent to do regressions, analyze the distributions or find remarkable statistics. The result of its trendency prediction would be clear as well as convincible. In a real time system things work different. Take regression for example, the up-coming data has the ability to totally change your previous regression and even worse, you cannot define them as outliers. Statistic samples would be trapped in limited known informations.

Loop Problem

In trading strategy’s realization, we often generate loops to cycle our positions or data, for many cases items in loop need to be removed or added. This affects the range of our loop when data is updated. Example: Loop from 0 to 10, when loop = 3 an asset previous in loop = 6, is removed from our position thus the range becomes 0 to 9. This loop probably crashes when counts to 6. This idea is the same for increasing ranged loop. To solve this problem we need to use a combination of backward loop (downto loop, counter -1 for each cycle) and forward loop (counter +1) and distinguish whether the range is increasing or decreasing. This problem affects no more in a static backtest, for it wouldn’t have an update in your loops.

Practical Problem

Under this section we can find tons of real life problems of a backtested strategy. How to deal with an order if it is rejected by the Exchange, re-order, cancel or makeup? How to deal with shares split or reverse split? If three strategies ordered one same stock, how to distinguish them in your positions?… Countless problems will appear even for one simplest idea when it turns to be a mature excutable strategy. Thus, I strongly suggest you to backtest your ideas in a simulated real time environment. Many platforms have this feature: Quantopian, Interactive Brokers, TradeStation, all of them are better than Excel when deal with backtesting.

Things to Notice

Though those differences may not lead to an direct impact on the result, they do cause a different stream of thoughts. Static backtesting is in view of the whole data set, programming could be both backward and forward (often forward due to intuition). Real time backtesting is in a backward point of view since the newest data would be continuously replaced. I hope this page provides a insipirable thinking.