Archive for the 'Automated Trading' Category

Trading System Framework

The core of our architecture rests on a universal trading system framework. This framework abstracts all of the basic market interfaces, allowing us to write generic strategies that run on any market, including simulation.

2010-11-22 Trading System Framework

As you can see in the above central box, our trading system abstracts several core functionalities.

  • Settings Management – the entire trading system is configured via a straightforward xml configuration file. The actual storage and management of this is abstracted by the particular profile. For live running, these settings are version controlled and managed in a central replicated sql database. For simulation, these are stored as a simple file provided to a console based simulator. For optimization purposes, these files serve as the basis for chromosomes in the genetic optimizer (with an optimization file providing the constraints for the search space). At the end of the day, develop a simple generic settings management system that can be abstracted for different targets.
  • Contract Manager / Base Contract – The core component of any system is the instrument that you are trading / measuring. The contract manager provides position management and risk management abstractions, as well as contract locating functionalities. Ultimately any object that requires a contract, goes through the contract manager, and is given an abstraction of a base contract. The base contract can be a futures contract, equity, bond etc. This provides for a universal interface to subscribe to market data, and issue / monitor orders.
  • Strategy Engine / Base Strategies – The strategy engine is the very heart of any trading system. This basic class subscribes to message pumps and processes the messages to handle orders. It is the most versatile object in the trading system, allowing for nearly any type of strategy.
  • Charting – Few systems put enough emphasis on thorough charting, but I find it critical for visualizing the results of a simulation, as well as determining what is happening during live trading. All contracts and strategies implement a simple IChartable interface that allows them to output highly configurable charts, right down to the Graphics handles. This allows the charts to be presented in a live windows forms view, or painted to a Bitmap class for saving to disk.
  • Logging – At the end of the day, traceability is critical. Every trade made needs to be serialized to disk / database in order to reconcile with your clearing house. Furthermore, every strategy needs to output useful tracing information to aid in debugging. Beyond the obvious tracing, strategies also need to implement a reporting interface to provide live state information to the user interface in order to determine how it is behaving, and if necessary to modify its parameter set, or to debug the strategy. This again is abstracted, just like settings and charting to go to different destinations based on the target of the trading engine. For simulation it outputs to the simulation results, whereas in live trading we work against easily queried database engines.

Next up I want to cut into application design and multithreading. There is a lot to cover, and I am swamped, so expect the articles to continue to appear as I have time. And if you have any questions feel free to email email hidden; JavaScript is required.

Six Pillars of Automated Trading

There are six major components to an automated trading system.2010-11-04 Automated Trading Overview

  • Live Trading Engine – Any given system will start with the live trading engine. This is the piece of software which runs in real time and actually places orders and reacts to market data.
  • Simulation Engine – When developing strategies, you often need to back test them. In an ideal world back testing would demonstrate profitability, but in reality it is just used to verify that your strategy does what you think it does. The key to a good simulation engine is that you run the exact same code in simulation as you do in production. I can’t understate that last sentence, so I’ll state it again – the key to a good simulation engine is that you run the exact same code in simulation as you do in production.
  • Historical Service – this runs hand in hand with the simulation engine. You need a tick database for simulation. This is the backbone of all research applications, from back testing strategies to developing market models, you need a thorough, indexed, tick database. You can also build bar data from ticks, but you better have ticks available for simulation.
  • Optimization Engine – All of your automated strategies require parameterization. Generally speaking these are best optimized by hand through selection of sensible variables. Sometimes however, you need to parameterize a simple strategy for a large number of symbols, in which case you want an automated system for optimization. Our system uses a cloud computing service to distribute instances of our simulation engine which run chromosomes from a centralized genetic optimization engine.
  • Analytics – You need to ruthlessly track your trading performance. At the core of any solid trading engine is a solid analytics engine which tracks your various strategies.
  • Reconciler – This was the biggest surprise coming from retail brokers to institutional brokers, but everyone makes mistakes. Sometimes the exchange will fail to tell your clearing house about trades you made, other times your clearing house will accidentally include another clients trades in your account. At the end of every day you need to reconcile every fill you think you made with the statements you receive from your clearing house and immediately reconcile any errors with your clearing house and the exchange.

Next up, I will cover the major components of the Trading Engine.

KISS

So you want to develop an automated trading system. No problem, you’ve noticed every time S&P goes up, the Russell 2000 should not be far behind (strategy used for example, please don’t go trying this). Here again, most people I know get started with seeing the phenomena in TWS, and deciding they want to automate the process. Now you fire up visual studio, create a swiss army knife C# console application and include my C# Interactive Brokers library. Seems easy enough, bind to data update events for S&P and Russell 2000, keep a local state variable of the inside prices of each, and when the calculated spread between them moves up or down, buy or sell the other leg.

Believe it or not – it is this simple, and is how I suggest most developers get started. You really need to see your automated widget trade sooner than later. The longer you live in development hell, the longer it is before you understand what your system need to do. The key to your first automated trader is to make it as simple as possible. Do not try to start off with an interface abstracted, general purpose strategy engine; instead build as simple an engine that trades every day, and recognize the common challenges / design patterns required as you develop.

My next series of articles will cover the architecture of a monolithic strategy engine, but I do not want to preach this as the solution to everyone’s needs. Keep it Simple Stupid.

Automated Trading 101

So you’ve just signed up for your Interactive Brokers account, downloaded my C# interface to Ib, and are ready to begin automated trading… what else is there? A LOT.

Because of this website, nearly every automated trader I have met has started this way:

  1. Manual trading with interactive brokers
  2. Seeing a strange phenomena in the market
  3. Building a simple widget to hook up to Ib
  4. Exploiting the mispricing until their trading volume grows and they realize Ib does not negotiate fees and on a bum day auto liquidates your account without any notice.
  5. Decides they need to go the institutional route, and figure out what their other options are.

This is exactly how I got started, and it is only after developing a full institutional system that I appreciated how good Interactive Brokers is, and why they can charge such a premium.

If you are still in steps 1 – 3, then you will want to stick with IB (in fact after step 5, for many people, sticking with IB will still be the right call). For those who have gotten to step 5, my next series of posts will cover your basic decision space.

Your first step is to get your requirements figured out. What contracts do you trade? Equities, Options, Futures, Bonds? Interactive Brokers is incredible in their support for cross asset class trading in a single account. Starting with them, it seems trivial to expect all clearing houses to let you short shares on the ASX and use your acquired buying power to buy futures on Eurex. This is simply not the case. Interactive Brokers provides both clearing services, and execution services. In institutional land these services are broken up, and the most important piece is partnering with the right clearing house.

Your clearing house determines which exchanges you can trade. They establish relationships with each exchange, and guarantee your trades. If you place a loosing bet in a leveraged account, you stand to loose more money than you have in the account, and if the clearing house mistakenly allows you to do this, they will have to cover your losses. I mentioned you have to choose your products, this is because if you want to trade futures on the LME and NYMEX, you will have to find a clearing house with relationships to both exchanges. Likewise if you would like to trade equities, you will need a clearing house that specializes in equities. Generally, clearing houses do not support all asset classes, and execution platforms certainly don’t. Example clearing houses are Advantage Futures, MF Global, NewEdge, Goldman Sachs etc.

So if clearing houses are the first piece of the puzzle, then execution platforms are the second. The clearing house will clear your trades and manage your account on behalf of an exchange, but to actually place trades, you will need an execution platform. For interactive brokers, this is their Trader Workstation front end, and their timberhill backend. In the futures market, there are a few major players, Trading Technologies, RTS (Real Time Systems Group), CQG, and Pats. These are the interfaces you will use to actually trade, and are generally all supported by the major clearing houses and exchanges, so you can use the same execution platform regardless of who you clear with.

image

The above diagram generally illustrates the basic relationship between the parties. What you will notice is that the only time money exchanges hands is at night. Intraday there is no relationship between your cash and your maximum position. That is strictly a risk management function of your clearing house. This is where your clearing house relationship becomes incredibly important. It is not uncommon for clearing houses to let you have much lower intraday margins than required by the exchange (how do you think velocity futures gives out $500 margin on intraday e-minis), but at night time the clearing house has to settle with the exchange. Here again, the clearing house will frequently lend you money to increase your margin , but in general over night is dangerous enough, no reason to over leverage it.

There is a lot more to this, but I want to cut to the technology. If you are going through this process, and want a lot more detail on the various fee structures and technology tradeoffs, please email hidden; JavaScript is required. I have worked with or thoroughly researched nearly every major futures clearing house and execution platform, as well as most of the equities options.

My next posts are going to continue to be overview posts, but I am particularly excited to cut to the technical / code, so stay tuned.