Automated Trading
What IS Trading /what do traders
do
Traders observe market behaviourfor a long time
They detect certain patterns in market data and their mind makes certain prediction models consciously or subconsciously ( intuition )
They try to execute trades as instructed by the abstract model which was learned by their mind
Feed historical data to our system
Make it automatically learn patterns using ML/Statistics/Pattern Recognition and build prediction models
Make it execute trades as instructed by the automated model which was learned by our system
How about building a system that learns patterns in the market automatically?
But, What is the role of computer science in all this?
Advantages of automated trading ✖ Very reactive Quickly Responds to minor changes in the market
✖ Objective in natureNot subject to emotional bias
✖ Capable of handling very high dimensional data
1000’s of features
Prediction Problem
✖ General IdeaPredict future price under given market conditions/ scenario
✖ Challenge1 - High Dimensional data
1000s of variables/features to characterise given market scenario. Question:Why is that a problem ??
Overfitting??What if most the the features are correlated ??
How to avoid that ??Dimensionality Reduction/PCA/subset selection
Prediction Problem - Continued
✖ Challenge2 - Loss function/Objective function
How to evaluate if the learned model/pattern is good enough
Profit??Accuracy rate??Correlation ??
What if an objective function is not analytical.
Other Challenges - Overfitting problems (bias / variance tradeoff), Outlier detection
What if an objective function is not even continuous
Limit Order Book
Best Bid Price Best Ask Price
{ }Passive BuyOrders
Passive SellOrders
Bid Order Count
Bid Size
Bid Price
Ask Price
Ask Size
Ask Order Count
4 18 3061 3062 50 6
5 40 3060 3063 100 8
10 200 3059 3065 140 13
12 190 3058 3066 110 7
…. …. …. …. …. ….
Bid Order Count
Bid Size
Bid Price
Ask Price
Ask Size
Ask Order Count
4 18 3061 3062 50 6
5 40 3060 3063 100 8
10 200 3059 3065 140 13
12 190 3058 3066 110 7
…. …. …. …. …. ….
Place Passive Sell Orders
Cancel Passive Sell Orders
AggressivelySell
AggressivelyBuy
3 7 2 6 18
14
Ask Queue
Place Passive Buy Orders
Cancel Passive Buy Orders
Bid Queue
7 2 6 3
Notion of PRice - Reducing Order
book Dimensionality✖ No concrete fair price defined
✖ Only order book snapshots and trade history
✖ Total dimensionality of order book is high
✖ How to map this higher dimension data to a single number ( A Notion of fair price ) ??
Let’s take an easy problem
Total size at Bid
Number of orders at Bid
Price at highest Bid
Price at lowest Ask
Number of orders at Ask
Total size at Ask
240 25 99 100 40 80
What is your price ?
● Should it be between the bid and the ask ?
o How about the mean of the two ?
o How should sizes affect it?
● Should the inference be different if the market has been
moving a lot and this is just the current snapshot ?
APPLICATION Of Computer
Science in
ALGORITHMIC TRADING
➽ Every microsecond matters !
➽ Need to be Fast, Optimized and Robust.
➽ Several Areas of Computer Science involved.
Infrastructure Challenges
Infrastructure Pipeline
Receiving &
Decoding Market Data
Processing &
Building Book
Strategy Decision
Sending Orders
Receiving Replies
Infrastructure Pipeline
Receiving &
Decoding Market Data
Processing &
Building Book
Strategy Decision
Sending Orders
Receiving Replies
What’s going on in the market right now?
Infrastructure Pipeline
Receiving &
Decoding Market Data
Processing &
Building Book
Strategy Decision
Sending Orders
Receiving Replies
Interpreting market data and effectively keeping a track of bid/ask sides
Infrastructure Pipeline
Receiving &
Decoding Market Data
Processing &
Building Book
Strategy Decision
Sending Orders
Receiving Replies
In which direction is the market going to move?
Infrastructure Pipeline
Receiving &
Decoding Market Data
Processing &
Building Book
Strategy Decision
Sending Orders
Receiving Replies
Sending new orders or cancelling previously placed orders
Infrastructure Pipeline
Receiving &
Decoding Market Data
Processing &
Building Book
Strategy Decision
Sending Orders
Receiving Replies
What happened to my order?Did it get placed successfully, or was there
any error?
➽ Receiving exchange data faster : UDP(Multicast) or TCP ?
➽ Colocation servers, direct lines to exchange.
➽ Data through Microwave.
COMPUTER NETWORKS
➽ Book building requires efficient data structures.
➽ Using the best algorithms, minimizing latency.
➽ Optimizing code for better hardware utilization
Data Structures / Algorithms
➽ Inter Process Communication : Shared Memory or TCP or Multicast ?
➽ Multithreaded Applications: Locks, Mutexes, Semaphores ?
➽ Context Switches ? Affine process to a single core Messaging Accelerators ( eg. VMA ) :
bypass kernel for network input
Operating Systems
➽ Decoding provided data using Hardware (instead of software)?
➽ FPGAs programmed to decode data.
➽ Latency benefits due to parallel processing (at Hardware level)
Digital Hardware Design
➽ Managing large amounts of historical exchanges’ data, and running studies on it.
➽ Amazon EC2 (compute), S3 (backups)
BIG DATA MANAGEME
NT
➽ Large Codebase with common code.
➽ Design Patterns, Object Oriented, Templated Programming.
Design Practices
Thanks!Any questions?
Two Roads Technological Solutions
http://www.tworoads.co.in/[email protected]
08800355641