Stairway to Quant Trading - Part 1

A Glimpse of Trading Platform Stream

Recently I’m using TradeStation to build trading Apps for customers. Often their demands are simple–A batch of stocks’ execution, VWAP execution or option trading monitoring. Somehow in this process, I learned how a systematic trading platform should be like and how the orders flow into Market and being executed. However, a more detailed and deeper inspection is needed to understand the whole system (exact the thing I want to figure), for example, how an order, starting at my PC, moving through the Exchange and being dealt by the otherside; how to get access to the Data directly from the Exchange. I would try to work out that later (hope in Part 2).

Let me first use the Math idea to clarify how a trading system works. Any Mathematical concept should be consist of three parts: a SPACE, OBJECTs in this space and objects MOVEMENTs. Same for a trading platform, it should be consist of a FRAME, MODULEs in this frame and modules’ movements, considered as TRIGGERs. A frame is the basement of our platform, including providing data, I/O control, printing log and such. A module is the control part, works functionally in our project, more like a component which helps us to achieve some specific goals. Trigger is the most important thing, it has the similair outlook (syntax frame) as a module, but its major task is to tell system what to do when something happens.

FRAME

A trading system must have the following characters:

  • Event-Driven
  • Dynamic/Real-Time
  • Multi-Threading

The first two characters seem contradictory, one focuses on event and another is time. Indeed our system could be more isolated–Fully event-driven (Only execute strategies when we receive another event’s signal), could also be a combination of time and event–For each specific time interval we execute some specifc things.
Supporting Multi-Threading is necessary for a good trading system. For most of the time, our strategy will do different executions to one same data or whatever, thus we need to split our data flow into several parts and deal each of them seperately.

MODULE

Each module is a function, do their own part of job in the system.

  • System Control Module
  • Calculation Module
  • GUI Module

For system control module, it should include the function that we need to call to get price info, order info or execute our orders. TradeStation provides the following modules (frequently used): PriceSeries (history price data), OrdersProvider (check the status of current filled/unfilled orders), OrdersTickets (send out execution request), AccountsProvider (decide the account used for trading), QuotesProvider (return the current quote for selected stocks). Each of them controls one part of our whole system and they are pre-writen, packaged modules.
Calculation Module is the body of our strategy, in there we put our ideas and call system control modules to help them work functionally.
GUI module may be used to interact with traders, not necessarily needed if we can log.

TRIGGER

Triggers are the core part of doing event-driven trading.

  • System Trigger
  • Strategic Trigger

System Trigger is provided in TradeStation, to help traders execute strategies and more importantly, do event-driven trading. For example, each time you send an ord to server, OrdersProvider_Update will be triggered, and in that module/function, you can tell computers to do things, print out the orders information or others.
Strategic Trigger can be understand as a intrinsic part of the strategies. For most strategies, we have to tell our system what to do, when to do and how to do, strategic trigger is used to dectect the condition satisifying our demands, then being triggered by that condition and run some codes.

Things to Notice

  • Module

Using modules to build trading platforms has many advantages, it simplifies your code and allows a better expansibility. Suppose you are building a new system which has many similar features as an old one, you only need to replace few modules to finish. Imagine you are in a maze and for every step you move, bricks or walls would be added to that maze. The more you move, the harder to escape. This is pretty much like building a platform. When you code for thousands of lines, it becomes hard to keep a clear mind and much harder to lookback thinking about some modifications. Using modules will help you quickly find the target. For example in a trading system we need to load the quotations, excute strategies to filter stocks and then, we apply trading algorithms, send out orders. If the order type is “market price”, our system will trace back to get the quotations. Suppose now you want to use “limited price” for orders, you wouldn’t like to update the whole system, instead you just update the first module, which greatly reduces your work.

  • Coding Safely

So far my feelings about building a trading platform that programming is not the hard part, safety is the major issue. You are not only asked to achieve goals, but also to achieve them in a stable and safety way, which requires a lot of control. For insatance, if all of your orders were correct except one missing the trading volume, your system should be able to detect that before it was send out.