Archive for the 'auto trading system' Category

Page 2 of 2

Optimization

Rules based Optimization

Before I discuss my second Automated Trading System (ATS), I need to explain the principal in which it operates. A rule based ATS depends on carefully chosen thresholds and parameters to determine when a particular stock should be entered and exited (long or short). Experience and theory can provide an excellent starting point, but to perform really well for a particular stock, it is useful to maximize these parameters on historical data.

Think about your set of rules as though they are a function.

function rules (double shortMATime, double longMATime)
{
“Enter Long when the shortMATime minute moving average crosses above the longMATime minute moving average.”
“Exit when the longMATime minute moving average crosses above the shortMATime minute moving average.”
}

In this example, there are two rules which are executed over live or historical data, with two parameters, shortMATime and longMATime. We would like to select values for these parameters such that they would have made the most money over the last week (or any time frame), assuming this represents closely what values will make the most money tomorrow. This function is very difficult to maximize, as it is not continuous. Small adjustments to either parameter can cause huge swings in the profitability of the system.

In this particular case, you may consider running the entire variable space through the function, setting each parameter from 0 to 1000 minutes, incrementing by one second, and taking the maximum output when you are done. This turns out to be roughly (1000 * 60)2 = 3,600,000,000 runs. Assuming a very fast 5 seconds per run for a week’s worth of data, this would take 570.77 years to process. Clearly a better maximization function is needed, but it cannot depend on the derivative of the function, nor can it require continuity of the first order. This is exactly where genetic algorithms shine.

My next series of articles will cover Genetic Optimization in detail. Stay tuned for more updates.

My ATS History (Part 1)

I took a course in college on Portfolio Analysis, and while the course itself was interesting, what really inspired me was my professor’s research. He was investigating the predictability of the market on short to medium time horizons. His research suggested that it is certainly possible to forecast a stock’s performance, and back test to ascertain a statistical likelihood of this forecast. This was day and night to me(one might say a Jurassic change of mind!), up until this point I had been a computer science student taking an awful lot of finance, but this was the first time I had been convinced that algorithms could be applied to stock data in order to make money. (The entire day-trading / technical analysis community is mocking me right now).

In any case, this spurred a lot of research on my part. Up until now I had been investing in the best discount broker available, scottrade, and as a software engineer, the first thing I did was to write an html parsing interface to scottrade to allow my soon to be automated framework to make buy and sell orders. It wasn’t long before I did my research on the difference between a direct access broker and a brokerage firm. The former allowing me to place direct orders with an exchange, and the latter attempting to take a piece of my cake by being a market maker. My research immediately led me to Interactive Brokers, which offers an API (what you say? No HTML parsing to interface?), as well as much lower fees (we’re talking half a penny per share baby!). Later I learned that they do not offer the best margin rates, nor do they offer the highest leverage… but lets just say for my level of sophistication, they are perfect.

After establishing my new brokerage account, I needed to test the waters. I developed an incredibly simple trading infrastructure in C# using the interface provided in http://finance.groups.yahoo.com/group/twsapi/. This first cut interface simply parsed news events at the fastest possible speed, allowing my application to track it, and rapidly trade on it. As you can see from the chart below, there was some news event at 12:00. If the news event was detected at 12:00:10, one could make a tidy profit simply by going long early, and selling at around 12:04 with a stop at 43.55, this would represent a profit of 45 cents/share at a risk of 15 cents/share, or a nice 3R.

I implemented this strategy and ran for two months before trading live. It worked flawlessly, I back tested it on old news releases for about two years, and there was not a single case where the momentum did not follow the news. Then I turned it on last July, and got one good month of running, and come August it started out alright, right before the bull came. Then it hit (possibly like triceratops butting heads), the uptrend in all of the stocks I was following was proceeded by erratic trading behavior. Momentum on the in the news stocks was no longer carrying. After a news release I may see a large down tick followed be an instant up tick, so fast that I could not liquidate and close positions in time to make money. Clearly my strategy had to change. I shutdown my strategy in September, and went to work on version 2.0 of my ATS. (Part II to follow…)