Algorithmic Trading Strategy1
Algorithmic Trading Strategy1
Outline
Lecturer Profile
Dr. Haksun Li CEO, Numerical Method Inc. (Ex-) Adjunct Professors, Advisor with the National University of Singapore, Nanyang Technological University, Fudan University, etc. Quantitative Trader/Analyst, BNPP, UBS PhD, Computer Sci, University of Michigan Ann Arbor M.S., Financial Mathematics, University of Chicago B.S., Mathematics, University of Chicago
A consulting firm in mathematical modeling, esp. quantitative trading or wealth management Products:
SuanShu AlgoQuant brokerage houses and funds all over the world multinational corporations very high net worth individuals gambling groups academic institutions
Customers:
Overview
Quantitative trading is the systematic execution of trading orders decided by quantitative market models. It is an arms race to build
more reliable and faster execution platforms (computer sciences) more comprehensive and accurate prediction models (mathematics)
Market Making
Quote to the market. Ensure that the portfolios respect certain risk limits, e.g., delta, position. Money comes mainly from client flow, e.g., bid-ask spread. Risk: market moves against your position holding.
Statistical Arbitrage
Bet on the market direction, e.g., whether the price will go up or down. Look for repeatable patterns. Money comes from winning trades.
Prerequisite
Trading Infrastructure
Communication network for broadcasting and receiving information about, e.g., order book, events and order status. API: the interfaces between various components, e.g., strategy and database, strategy and broker, strategy and exchange, etc.
existing syste
Booking System
Adapter Protocol
Clearanc
Clearance Adapter
FIX
Market Data
Risk Management
Credit Limit
Hypothesis
Start with a market insight Translate the insight in English into mathematics in Greek
Modeling
Model validation
Backtesting
Understand why the model is working or not
Analysis
11
Handle missing data Incorporate events, news and announcements Code up the quant. strategy Code up the simulation
Debug Debug again Debug more Debug even more Debug patiently Debug impatiently Debug frustratingly Debug furiously Give up Start to trade
Wait a very long time for the simulation to complete Recalibrate parameters and simulate again Wait a very long time for the simulation to complete Recalibrate parameters and simulate again Wait a very long time for the simulation to complete 12
Excel Matlab/R/other scripting languages MetaTrader/Trade Station RTS/other automated trading systems
13
Matlab/R
They are very slow. These scripting languages are interpreted line-by-line. They are not built for parallel computing. They do not handle a lot of data well. How do you handle two year worth of EUR/USD tick by tick data in Matlab/R? There is no modern software engineering tools built for Matlab/R. How do you know your code is correct? The code cannot be debugged easily. Ok. Matlab comes with a toy debugger somewhat better than gdb. It does not compare to NetBeans, Eclipse or IntelliJ IDEA.
There are more people who know Java/C#/C++/C than Matlab, R, etc., combined.
It has a huge collection of math functions for math modeling and analysis.
Math libraries are also available in SuanShu (Java), Nmath (C#), Boost (C++), and Netlib (C).
15
R Disadvantages
TOO MANY!
16
Some R Disadvantages
Must interpret the code line-by-line How to read and process gigabytes of tick-by-tick data Cannot calibrate/simulate a strategy in many scenarios in parallel No usage, rename, auto import, auto-completion No conditional breakpoint, disable, thread switch and resume No interface, inheritance; how to define ?
Limited memory
Limited parallelization
Inconvenient editing
17
Rs Biggest Disadvantage
18
Productivity
19
programming
debugging
calibrating
data extracting
Industrial-Academic Collaboration
Portfolio optimization from Prof. Lai Pairs trading model from Prof. Elliott Optimal trend following from Prof. Dai Moving average crossover from Prof. Satchell Many more
21
Backtesting
Backtesting simulates a strategy (model) using historical or fake (controlled) data. It gives an idea of how a strategy would work in the past.
It gives an objective way to measure strategy performance. It generates data and statistics that allow further analysis, investigation and refinement.
allow easy strategy programming allow plug-and-play multiple strategies simulate using historical data simulate using fake, artificial data allow controlled experiments
23
generate standard and user customized statistics have information other than prices
24
Iterative Refinement
Backtesting generates a large amount of statistics and data for model analysis. We may improve the model by
regress the winning/losing trades with factors identify, delete/add (in)significant factors check serial correlation among returns check model correlations the list goes on and on
25
pnl mean, stdev, corr Sharpe ratio confidence intervals max drawdown breakeven ratio biggest winner/loser breakeven bid/ask slippage
26
Omega
The higher the ratio; the better. This is the ratio of the probability of having a gain to the probability of having a loss. Do not assume normality. Use the whole returns distribution.
27
Bootstrapping
We observe only one history. What if the world had evolve different? Simulate similar histories to get confidence interval. White's reality check (White, H. 2000).
28
Calibration
Most strategies require calibration to update parameters for the current trading regime. Occams razor: the fewer parameters the better. For strategies that take parameters from the Real line: Nelder-Mead, BFGS For strategies that take integers: Mixed-integer nonlinear programming (branch-and-bound, outerapproximation)
29
Sensitivity
How much does the performance change for a small change in parameters? Avoid the optimized parameters merely being statistical artifacts. A plot of measure vs. d(parameter) is a good visual aid to determine robustness. We look for plateaus.
31
Summary
Algo trading is a rare field in quantitative finance where computer sciences is at least as important as mathematics, if not more. Algo trading is a very competitive field in which technology is a decisive factor.
32
can list out assumptions can quantify models from assumptions can deduce properties from models can test properties can do iterative improvements
33
Superstition
Many quantitative models are just superstitions supported by fallacies and wishful-thinking.
34
Conclude that
the slope is positive the t-stat is significant
Reality
Mistakes
why 2?
using a moving calibration window (e.g., Bands) using various sorts of moving averages (e.g., MA, WMA, EWMA)
Data snooping Misuse of mathematics Assumptions cannot be quantified No model validation against the current regime Ad-hoc take profit and stop-loss
why 2?
How do you know when the model is invalidated? Cannot explain winning and losing trades Cannot be analyzed (systematically)
40
A Scientific Approach
hopefully without peeking at the data write down the idea in math formulae
In-sample calibration; out-sample backtesting Understand why the model is working or not
41
Markov model co-integration stationarity hypothesis testing bootstrapping signal processing, e.g., Kalman filter returns distribution after news/shocks time series modeling The list goes on and on
42
When the price trends up, we buy. When the price trends down, we sell.
What is a Trend?
An Upward Trend
More positive returns than negative ones. Positive returns are persistent.
Knight-Satchell-Tran
1-q
Zt = 0 DOWN TREND
Zt = 1 UP TREND
1-p
Knight-Satchell-Tran Process
= + 1
: long term mean of returns, e.g., 0 , : positive and negative shocks, non-negative, i.i.d
1 1 11 1 1
2 2 21 2 2
Two moving averages: slow () and fast (). Monitor the crossovers. =
1 1 =0
1 =0
, >
For most traders, it is an art (guess), not a science. Lets make our life easier by fixing = 1.
Why?
What is ?
= 2 =
Expected P&L
GMA(2,1)
E =
1 1
1 +
GMA()
E = 1 1
It makes predictions about which regime we are now in. We quantify how useful the model is by
the parameter sensitivity the duration we stay in each regime the state differentiation power
53
Is it because of calibration? Is it because of state prediction? Are 3 states sufficient? prediction variance?
We can justify take profit and stoploss based on trader utility function.
54
Limitations
Variance
55
=1
56
Given the past returns 1 , , max{ +1 +1 } is regarded as a risk-aversion index (user input)
max{[ +1 +1 }
( +1 )}
= 1 + 2( )
57
Summary
Market understanding gives you an intuition to a trading strategy. Mathematics is the tool that makes your intuition concrete and precise. Programming is the skill that turns ideas and equations into reality.
59
AlgoQuant Demo
60