UChicago Algo Trading Lecture 3 Micro Modeling
UChicago Algo Trading Lecture 3 Micro Modeling
& Execution
2
The Bid & Ask
Some Important Terms
3
The Bid & Ask
Some Important Terms
> BBO: The Best Bid and Best Offer in a market. Also called the market quotation.
> Bid/ask spread: the difference between the best ask and the best bid.
– Traders sometimes call it the inside spread because the space between the highest bid price and the lowest ask
price is inside the market.
4
Market Orders
Algorithmic Trading
Market Orders
A market order is an instruction to trade at the best price currently available in the market. Market order
traders pay the bid/ask spread.
6
Market Orders
A market order is an instruction to trade at the best price currently available in the market. Market order
traders pay the bid/ask spread.
7
Market Orders
A market order is an instruction to trade at the best price currently available in the market. Market order
traders pay the bid/ask spread.
8
Market Orders
A market order is an instruction to trade at the best price currently available in the market. Market order
traders pay the bid/ask spread.
> When we sell it later, we also paid half the spread for liquidity because we received only 75 for a 9
bond worth ____
Market Orders
A market order is an instruction to trade at the best price currently available in the market. Market order
traders pay the bid/ask spread.
> When we sell it later, we also paid half the spread for liquidity because we received only 75 for a 10
bond worth 75.5.
Limit Orders
Algorithmic Trading
Limit Orders
In contrast to Market Orders, limit orders have conditions that (usually) prevent their immediate execution.
12
Limit Orders
In contrast to Market Orders, limit orders have conditions that (usually) prevent their immediate execution.
13
Limit Orders
In contrast to Market Orders, limit orders have conditions that (usually) prevent their immediate execution.
> Thus for limit orders to buy, the execution price must be at or ?(above/below)? the limit price.
14
Limit Orders
In contrast to Market Orders, limit orders have conditions that (usually) prevent their immediate execution.
> Thus for limit orders to buy, the execution price must be at or below the limit price.
15
Order-driven Markets
Algorithmic Trading
Rule-Based Order-Matching Systems
Rule-based order-matching systems use trading rules to process price and quantity information from the orders that
traders submit, in order to arrange trades.
17
Rule-Based Order-Matching Systems
Rule-based order-matching systems use trading rules to process price and quantity information from the orders that
traders submit, in order to arrange trades.
18
Rule-Based Order-Matching Systems
Rule-based order-matching systems use trading rules to process price and quantity information from the orders that
traders submit, in order to arrange trades.
Footnotes:
Pure price-time precedence systems: Systems that Display precedence: Gives displayed orders
rank orders based only on price priority and precedence over undisclosed orders at the
strict time precedence. same price.
19
Rule-Based Order-Matching Systems
Rule-based order-matching systems use trading rules to arrange trades from the orders that traders submit to them. All orders specify the maximum
quantities that traders will accept. Rule-based order-matching systems process this price and quantity information to arrange their trades. Almost all rule-
based systems now use electronic trading systems to process their orders.
20
Rule-Based Order-Matching Systems
Rule-based order-matching systems use trading rules to arrange trades from the orders that traders submit to them. All orders specify the maximum
quantities that traders will accept. Rule-based order-matching systems process this price and quantity information to arrange their trades. Almost all rule-
based systems now use electronic trading systems to process their orders.
> Step 1:
– The market matches the highest-ranking buy and sell orders to each other. If the buyer
will pay at least as much as the seller demands, the match will result in a ____
21
Rule-Based Order-Matching Systems
Rule-based order-matching systems use trading rules to arrange trades from the orders that traders submit to them. All orders specify the maximum
quantities that traders will accept. Rule-based order-matching systems process this price and quantity information to arrange their trades. Almost all rule-
based systems now use electronic trading systems to process their orders.
> Step 1:
– The market matches the highest-ranking buy and sell orders to each other. If the buyer
will pay at least as much as the seller demands, the match will result in a trade. If
one order is smaller than the other, the smaller order will fill completely.
> Step 2:
– The market then will match the remainder of the larger order with the next highest-
ranking order on the opposite side of the market.
– The market then will match the next highest- ranking buy and sell orders.
> Step 3:
– This process continues until the market arranges all possible trades.
– Since the market processes orders ranked by decreasing price priority, the last match
that results in a trade often involves two orders that bid and offer the same price.
> Ending:
– The next match does not result in a trade because the buyer's bid price is below the
seller's offer price.
22
Example
Example Background Setting The Matching Procedure
> Suppose that the traders submit their orders to a fixed-time
market auction that calls at 10:30. The following orders are
submitted, before the auction happens:
Order Book
BUYERS SELLERS
ORDER
TRADER SIZE SIZE TRADER
PRICE
Bif 4 Market
buy
20.2 5 Stu
Bea 3 20.0
Ben 2 20.0
20.0 6 Sue
Order Book
BUYERS SELLERS
ORDER
TRADER SIZE SIZE TRADER
PRICE
Bif 4 Market
buy
20.2 5 Stu
Bea 3 20.0
Ben 2 20.0
20.0 6 Sue
BUYERS SELLERS
ORDER
TRADER SIZE SIZE TRADER
PRICE
Bif 4 Market
buy
20.2 5 Stu
Bea 3 20.0
Ben 2 20.0
20.0 6 Sue
ORDER
TRADER SIZE SIZE TRADER
PRICE
Bif 4 Market
buy
20.2 5 Stu
Bea 3 20.0
Ben 2 20.0
20.0 6 Sue
20.2 5 Stu
Bea 3 20.0
Ben 2 20.0
20.0 6 Sue
Bea 3 20.0 – The market then matches Sue's remainder of 1 with Bea's order to buy 3 for 20.0. This
match fills the remainder of Sue's order and leaves Bea with a remainder of 2 to buy for
Ben 2 20.0 20.0. Sue can trade with Bea because Sue is offering 20.0 and Bea is bidding
20.0 6 Sue
– The next match does not result in a trade. Bea's remainder of 2 to buy for 20.0 cannot
Bud 7 19.8 1 Sol trade with Sam's order to sell 2 at 20.1 because Bea will not pay as much as Sam
demands. No further trades are possible. Table 6-3 summarizes the trades.
28
Order Book After the Matching
Example Continued
> The order book with the remaining unfilled orders appears below.
> Note that the buy and sell orders no longer overlap.
> Continuous markets always have a spread between the best bid and the best offer. If they
did not, a _______ would result.
BUYERS SELLERS
TRADER SIZE ORDER PRICE SIZE TRADER
20.2 5 Stu
20.1 2 Sam
Bea 2 20.0
Ben 2 20.0
Bud 7 19.8
29
Order Book After the Matching
Example Continued
> The order book with the remaining unfilled orders appears below.
> Note that the buy and sell orders no longer overlap.
> Continuous markets always have a spread between the best bid and the best offer. If they
did not, a trade would result.
BUYERS SELLERS
TRADER SIZE ORDER PRICE SIZE TRADER
20.2 5 Stu
20.1 2 Sam
Bea 2 20.0
Ben 2 20.0
Bud 7 19.8
30
Order Book After the Matching
Example Continued
> The order book with the remaining unfilled orders appears below.
> Note that the buy and sell orders no longer overlap.
> Continuous markets always have a spread between the best bid and the best offer. If they
did not, a trade would result.
> If this market now started continuous trading, the market quoted BBO would be:
BUYERS SELLERS
TRADER SIZE ORDER PRICE SIZE TRADER
20.2 5 Stu
20.1 2 Sam
Bea 2 20.0
Ben 2 20.0
Bud 7 19.8
31
Order Book After the Matching
Example Continued
> The order book with the remaining unfilled orders appears below.
> Note that the buy and sell orders no longer overlap.
> Continuous markets always have a spread between the best bid and the best offer. If they
did not, a trade would result.
> If this market now started continuous trading, the market quoted BBO would be 4 bid
for 20.0, 2 offered at 20.1.
BUYERS SELLERS
TRADER SIZE ORDER PRICE SIZE TRADER
20.2 5 Stu
20.1 2 Sam
Bea 2 20.0
Ben 2 20.0
Bud 7 19.8
32
The Winner’s Curse of
Transaction Costs + How to
Optimize
> As mentioned in a previous talk, informed traders push market prices towards their
estimates of fundamental value. We examine this more in the following slides.
> First of all, intuitively why might trading leak information about security values?
> Intuitive analogy: In poker the bets you make reveal your hand strength. You opponents
(other traders) figure out that you think your hand-range (the security) is valuable if you make
large bets.
1. TE Chpt. 10.3-10.4 34
Costs of Information Leakage
Informed trades push market prices towards fundamental value.
> Thus the price impact of informed trading is a transaction cost which harms the
informed trader. On the bright side, impact benefits society at large through more accurate
valuation/allocation of resources.
> First of all, are these costs important? Perhaps they are a boring detail?
1. TE Chpt. 10.3-10.4 35
Costs of Information Leakage
Informed trades push market prices towards fundamental value.
> Thus the price impact of informed trading is a transaction cost which harms the
informed trader. On the bright side, impact benefits society at large through more accurate
valuation/allocation of resources.
> First of all, are these costs important? Perhaps they are a boring detail- WRONG:
1. TE Chpt. 10.3-10.4 36
A Simple Market: Betting on a Binary Event
Setting up the problem toOptimizing
optimize. b/w Profits and Transaction Costs
1. TE Chpt. 10.6 37
A Simple Market: Betting on a Binary Event
Setting up the problem toOptimizing
optimize. b/w Profits and Transaction Costs
1. TE Chpt. 10.6 38
A Simple Market: Betting on a Binary Event
Setting up the problem toOptimizing
optimize. b/w Profits and Transaction Costs
> Since you know the event is more likely to happen than other people expect, you are
going to buy Q quantity of these futures to profit from their ignorance.
> Warmup questions: Explain why you want to buy the future not short-sell. Explain why your expected
payoff (ignoring transaction costs) is 𝜋𝑄
1. TE Chpt. 10.6 39
Adding the Leakage (Transaction Cost)
Betting on a binary event E. All other traders believe p(E)=𝛼. You’re the most informed trader
and know that p(E)=𝜋>𝛼.
> Unfortunately nothing in life is free. Other traders suspect that you may be better
𝑸
informed. As such, the more you buy, the higher the price they charge: 𝑷 = 𝜶 + 𝑳
– P = Price
– Q = quantity of futures bought
– L = parameter that characterizes liquidity in the market – when L is large you can
buy a lot without significant price impact.
1. TE Chpt. 10.6 40
Adding the Leakage (Transaction Cost)
Betting on a binary event E. All other traders believe p(E)=𝛼. You’re the most informed trader
and know that p(E)=𝜋>𝛼.
> Unfortunately nothing in life is free. Other traders suspect that you may be better
𝑸
informed. As such, the more you buy, the higher the price they charge: 𝑷 = 𝜶 + 𝑳
– P = Price
– Q = quantity of futures bought
– L = parameter that characterizes liquidity in the market – when L is large you can
buy a lot without significant price impact.
> Question: If you don’t trade then 𝑄 = 0 and we have 𝑃 = 𝛼. Why does that make sense, i.e. why is
the default starting price point 𝛼?
1. TE Chpt. 10.6 41
Transaction Cost Functions
Betting on a binary event E. All other traders believe p(E)=𝛼. You’re the most informed trader
and know that p(E)=𝜋>𝛼.
𝑄
> Note: 𝑃 = 𝛼 + is an example transaction cost function (also called market impact
𝐿
function).
> Quants use this type of function 1000s of times per day.
> If you haven’t seen it before, welcome the bane and joy of all quant trading. It is about
to haunt you for the rest of your (trading) life.
42
Transaction Cost Functions
Betting on a binary event E. All other traders believe p(E)=𝛼. You’re the most informed trader
and know that p(E)=𝜋>𝛼.
𝑄
> Note: 𝑃 = 𝛼 + is an example transaction cost function (also called market impact
𝐿
function).
> Quants use this type of function 1000s of times per day.
> If you haven’t seen it before, welcome the bane and joy of all quant trading. It is about
to haunt you for the rest of your (trading) life.
Details:
43
Interview Q
𝑄
> Recall that 𝑃 = 𝛼 + 𝐿
– P = Price
– Q = quantity of futures bought
– L = parameter that characterizes liquidity in the market – when L is large you can buy a lot without significant price impact.
> We previously mentioned that your expected payoff (ignoring transaction costs) is πQ
> Question: Now that we include transaction costs, explain why your expected net profit is:
𝑄
𝜋𝑄 − 𝑃𝑄 = 𝜋𝑄 − 𝛼 + 𝑄
𝐿
1. TE Chpt. 10.6 45
Optimization: Finding the Highest Net Profit
You’re the most informed trader and know that p(E)=𝜋>𝛼 . Profit = 𝜋𝑄−(𝛼+𝑄/𝐿)𝑄, where
P = price, Q=quantity bought, L=liquidity.
𝑄
> As established, Expected Profit = 𝜋𝑄 − 𝑃𝑄 = 𝜋𝑄 − 𝛼 + 𝑄.
𝐿
> Interview q: How much Q should you buy to make the most money?
𝑄
> The interview q is thus: max 𝜋𝑄 − 𝛼 + 𝐿 𝑄 . Easy calculus!
𝑄
1. TE Chpt. 10.6 46
Optimization: Finding the Highest Net Profit
You’re the most informed trader and know that p(E)=𝜋>𝛼 . Profit = 𝜋𝑄−(𝛼+𝑄/𝐿)𝑄, where
P = price, Q=quantity bought, L=liquidity.
𝑄
> As established, Expected Profit = 𝜋𝑄 − 𝑃𝑄 = 𝜋𝑄 − 𝛼 + 𝑄.
𝐿
> Interview q: How much Q should you buy to make the most money?
𝑄
> The interview q is thus: max 𝜋𝑄 − 𝛼 + 𝐿 𝑄 . Easy calculus!
𝑄
2
> FOC: 𝑄 : 𝜋 − 𝛼 − 𝐿 𝑄 = 0
> Rearrange terms for Q gives the answer to the interview question:
𝐿
𝑄∗ = 𝜋−𝛼
2
1. TE Chpt. 10.6 47
Findings from our
Transaction Cost Derivation
Important conclusions
Examining the Solution: General Findings
𝐿
Profit = 𝜋𝑄−(𝛼+𝑄/𝐿)𝑄, where P = price, Q=quantity bought, L=liquidity. 𝑄 ∗ = 2 𝜋 − 𝛼
𝐿
> What is the Maximum Expected Profit? Easy: let us now plug in 𝑄∗ = 2 𝜋 − 𝛼 .
1. TE Chpt. 10.6 49
Examining the Solution: General Findings
𝐿
Profit = 𝜋𝑄−(𝛼+𝑄/𝐿)𝑄, where P = price, Q=quantity bought, L=liquidity. 𝑄 ∗ = 2 𝜋 − 𝛼
𝐿
> What is the Maximum Expected Profit? Easy: let us now plug in 𝑄∗ = 2 𝜋 − 𝛼 .
> Key takeaways are that you expect to make more money if (1) the market is liquid and/or
(2) if your information is better than everyone else’s.
– Thus, depending on the circumstances, high liquidity may be more profitable than good differentiated information.
– Finally: When values aren’t known, informed trading make prices more informative.
1. TE Chpt. 10.6 50
Comparison to “Fancier” Tcost Model
The Almgren-Chriss Transaction Cost function is the most famous model
> The study was investigated by Robert Almgren et al. (2005) and was specifically for U.S. equities.
> The coefficients, possibly the exponents and functional forms might be significantly different across
different markets as well as over time.
– Therefore, such models require careful calibration for each market before use.
𝑄 Θ
𝐼𝑝𝑒𝑟𝑚 = 𝛾𝜎 ( )1/4 +(𝑛𝑜𝑖𝑠𝑒)
𝑉 𝑉
3/5
𝑄
𝐼𝑟𝑒𝑎𝑙𝑖𝑧𝑒𝑑 = 𝜇𝐼𝑝𝑒𝑟𝑚 + 𝑠𝑖𝑔𝑛(𝑋)𝜂𝜎 + (𝑛𝑜𝑖𝑠𝑒)
𝑉𝑇
– σ is the asset specific volatility
– Q/T is the trading rate
– V is the average daily volume
– Θ is the shares outstanding
– γ, η are coefficient
– μ is the adjustment factor
𝑄
> Compare with: 𝑃 − 𝛼 = 4𝐿
51
Theory of Modeling
> How should we get started modeling, i.e. relating the real world to some more abstract math to
infer something new?
> A stochastic process {𝑋𝑡 } is as a ordered collection of Random Variables, often with past
observations influencing future ones.
> A stochastic process {𝑋𝑡 } is as a ordered collection of Random Variables, often with past
observations influencing future ones.
> When the ordering represents time, a stochastic process is also often called a (stochastic) time
series.
– (Or to split hairs, the realized series is sometimes called the time series) Chan Algorithmic Trading (2013)
55
Stationarity
Algorithmic Trading
What is a “nice” time series to work with?
You have probably seen the IID assumption in classical statistics. The (slightly weaker) equivalent is Stationarity
57
Chan Algorithmic Trading (2013)
Stationarity: Similar to IID
What is a “nice” time series to work with? You have probably seen the IID assumption in classical statistics. The (slightly weaker)
equivalent is Stationarity
58
Chan Algorithmic Trading (2013)
Stationarity: Similar to IID
What is a “nice” time series to work with? You have probably seen the IID assumption in classical statistics. The (slightly weaker)
equivalent is a Stationarity
Note 1: The definition of stationarity holds for not only a single time series, but
more generally, a stochastic process ie a family of potentially multi-dimensional
random variables indexed by time.
IID is stronger than the stationarity, for example the stationary variables don’t’
59
have to be independent, but just have same mean/variance/etc.
Chan Algorithmic Trading (2013)
Sample Interview
Question
Algorithmic Trading
Deriving the Moments of an AR(1)
An easy interview question once you know what an AR(1) is. This is asked of undergrads by multiple hedge funds.
Interview Question
Interview Question: (*assumes stationarity though interviewers often don’t say this*)
Interview Question: (*assumes stationarity though interviewers often don’t say this*)
Algorithmic Trading
How to Model Everything: State Variables
You have data, you like math. What should you actually do to relate the 2?
> Intuitively, this means they describe enough about the system to determine all its
future behavior perfectly (or, as perfectly as possible, up to assumed independent
random shocks).
> Usually, state variables are specified with smallest dimension possible, both for clarity
and computational simplification.
– In mechanical systems, the position coordinates and velocity of mechanical parts are typical state variables.
Why? Because knowing these, it is possible to determine the future state of the objects in the system.
– Similarly, in ecosystem models, population sizes of plants/animals plus quantities of resources (nutrients,
organic material) are typical state variables.
Advanced Econometrics
65
How to Model Everything: State-Space Models
You have data, you like math. What should you actually do to relate the 2?
– Why do we have 2 time series instead of 1? We generalize to saying you cannot directly observe the true
state (is my dog truly happy inside) but instead just have observed data (did he jump up and down).
Advanced Econometrics
66
How to Model Everything: State-Space Models
You have data, you like math. What should you actually do to relate the 2?
– Why do we have 2 time series instead of 1? We generalize to saying you cannot directly observe the true
state (is my dog truly happy inside) but instead just have observed data (did he jump up and down).
(2) The measurement model, also called the observation equation, which describes how
the measurements/observations 𝒀𝒕 depend on the state variables.
Advanced Econometrics
67
Example State-Space Model: Equations
You have data, you like math. What should you actually do to relate the 2?
> Why restrict to linear and gaussian? For the same reason that linear and gaussian is often
beloved in many problems: closed-form solutions! Aside: the most famous solution is the
Kalman Filter.
Advanced Econometrics
68
Example State-Space Model: NASA
This type of model was first used by NASA, to solve the problem of locating and navigating Apollo spaceships with extremely limited
observations.
You can see why it would be important to figure out where a ship actually is!
Example:
Advanced Econometrics
69