Date post: | 21-Jan-2018 |
Category: |
Economy & Finance |
Upload: | quantopian |
View: | 2,604 times |
Download: | 0 times |
Quantitative Trading as a Mathematical Science
QuantCon Singapore 2016
Haksun Li [email protected]
www.numericalmethod.com
Abstract
2
Quantitative trading is distinguishable from other trading methodologies like technical analysis and analystsβ opinions because it uniquely provides justifications to trading strategies using mathematical reasoning. Put differently, quantitative trading is a science that trading strategies are proven statistically profitable or even optimal under certain assumptions. There are properties about strategies that we can deduce before betting the first $1, such as P&L distribution and risks. There are exact explanations to the success and failure of strategies, such as choice of parameters. There are ways to iteratively improve strategies based on experiences of live trading, such as making more realistic assumptions. These are all made possible only in quantitative trading because we have assumptions, models and rigorous mathematical analysis.
Quantitative trading has proved itself to be a significant driver of mathematical innovations, especially in the areas of stochastic analysis and PDE-theory. For instances, we can compute the optimal timings to follow the market by solving a pair of coupled HamiltonβJacobiβBellman equations; we can construct sparse mean reverting baskets by solving semi-definite optimization problems with cardinality constraints and can optimally trade these baskets by solving stochastic control problems; we can identify statistical arbitrage opportunities by analyzing the volatility process of a stochastic asset at different frequencies; we can compute the optimal placements of market and limit orders by solving combined singular and impulse control problems which leads to novel and difficult to solve quasi-variational inequalities.
Speaker Profile Dr. Haksun Li CEO, NM LTD. (Ex-)Adjunct Professors, Industry Fellow, Advisor,
Consultant with the National University of Singapore, Nanyang Technological University, Fudan University, the Hong Kong University of Science and Technology.
Quantitative Trader/Analyst, BNPP, UBS Ph.D., Computer Science, University of Michigan Ann
Arbor M.S., Financial Mathematics, University of Chicago B.S., Mathematics, University of Chicago
3
What is Quantitative Trading?
4
Quantitative Trading?
5
Quantitative trading is the buying and selling of assets following the instructions computed from a set of proven mathematical models.
The differentiation from other trading methodologies or the emphasis is on how a strategy is proven and not on what strategy is created.
It applies (rigorous) mathematical reasoning in all steps during trading strategy construction from the start to the end.
Moving Average Crossover as a TA
6
A popular TA signal: Moving Average Crossover. A crossover occurs when a faster moving average (i.e. a
shorter period moving average) crosses above/below a slower moving average (i.e. a longer period moving average); then you buy/sell.
In most TA book, it is never proven only illustrated with an example of applying the strategy to a stock for a period of time to show profits.
Technical Analysis is Not Quantitative Trading
7
TA books merely describes the mechanics of strategies but never prove them.
Appealing to common sense is not a mathematical proof.
Conditional probabilities of outcomes are seldom computed. (Lo, Mamaysky, & Wang, 2000)
Application of TA is more of an art (is it?) than a science. How do you choose the parameters?
For any TA rule, you almost surely can find an asset and a period that the rule βworksβ, given the large number of assets and many periods to choose from.
Fake Quantitative Models 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 a model is invalidated? Cannot explain winning and losing trades Cannot be analyzed (systematically)
8
The Quantitative Trading Research Process
9
NM Quantitative Trading Research Process
10
1. Translate a vague trading intuition (hypothesis) into a concrete mathematical model.
2. Translate the mathematical symbols and equations into a computer program.
3. Strategy evaluation. 4. Live execution for making money.
Step 1 - Modeling
11
Where does a trading idea come from? Ex-colleagues Hearsays Newspapers, books TV, e.g., Moving Average Crossover (MA)
A quantitative trading strategy is a math function, f, that at any given time, t, takes as inputs any information that the strategy cares and that is available, Ft, and gives as output the position to take, f(t,Ft).
Step 2 - Coding
12
The computer code enables analysis of the strategy. Most study of a strategy cannot be done analytically. We must resort to simulation.
The same piece of code used for research and investigation should go straight into the production for live trading. Eliminate the possibility of research-to-IT translation
errors.
Step 3 β Evaluation/Justification
13
Compute the properties of a trading strategy. the P&L distribution the holding time distribution the stop-loss the maximal drawdown
http://redmine.numericalmethod.com/projects/public/repository/svn-algoquant/show/core/src/main/java/com/numericalmethod/algoquant/execution/performance
Step 4 - Trading
14
Put in capitals incrementally. Install safety measures. Monitor the performance. Regime change detection.
Mathematical Analysis of Moving Average Crossover
15
Moving Average Crossover as a Quantitative Trading Strategy
16
There are many mathematical justifications to Moving Average Crossover. weighted Sum of lags of a time series Kuo, 2002
Whether a strategy is quantitative or not depends not on the strategy itself but entirely on the process to construct it; or, whether there is a scientific justification to prove it.
Step 1 - Modeling Two moving averages: slower (π) and faster (π). Monitor the crossovers.
π΅π‘ = 1πβ ππ‘βππβ1π=0 β 1
πβ ππ‘βππβ1π=0 , π > π
Long when π΅π‘ β₯ 0. Short when π΅π‘ < 0.
How to Choose π and π? It is an art, not a science (so far). They should be related to the length of market cycles. Different assets have different π and π. Popular choices: (250, 5) (250 , 20) (20 , 5) (20 , 1) (250 , 1)
Two Simplifications
19
Reduce the two dimensional problem to a one dimensional problem. Choose π = 1. We know that m should be small.
Replace arithmetic averages with geometric averages. This is so that we can work with log returns rather than
prices.
GMA(n , 1)
π΅π‘ β₯ 0 iff ππ‘ β₯ β ππ‘βππβ1π=0
1π
π π‘ β₯ ββ πβ π+1πβ1
π π‘βππβ2π=1 (by taking log)
π΅π‘ < 0 iff ππ‘ < β ππ‘βππβ1π=0
1π
π π‘ < ββ πβ π+1πβ1
π π‘βππβ2π=1 (by taking log)
What is π? π = 2 π = β
Acar Framework Acar (1993): to investigate the probability distribution
of realized returns from a trading rule, we need the explicit specification of the trading rule the underlying stochastic process for asset returns the particular return concept involved
Knight-Satchell-Tran Intuition Stock returns staying going up (down) depends on the realizations of positive (negative) shocks the persistence of these shocks
Shocks are modeled by gamma processes. Asymmetry Fat tails
Persistence is modeled by a Markov switching process.
Knight-Satchell-Tran ππ‘
Zt = 0 DOWN TREND
ππΏ π₯
=π2
πΌ2π₯πΌ2β1
Ξ πΌ2πβπ2π₯
Zt = 1 UP TREND ππ π₯
=π1
πΌ1π₯πΌ1β1
Ξ πΌ1πβπ1π₯
q p
1-q
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π₯πΌ1β1
Ξ πΌ1πβπ1π₯
ππΏ π₯ = π2πΌ2π₯πΌ2β1
Ξ πΌ2πβπ2π₯
Step 3 β Evaluation/Justification Assume the long term mean is 0, ππ = 0. When π = 2, π΅π‘ β₯ 0 β‘ π π‘ β₯ 0 β‘ ππ‘ = 1 π΅π‘ < 0 β‘ π π‘ < 0 β‘ ππ‘ = 0
GMA(2, 1) β NaΓ―ve MA Trading Rule Buy when the asset return in the present period is
positive. Sell when the asset return in the present period is
negative.
NaΓ―ve MA Conditions The expected value of the positive shocks to asset
return >> the expected value of negative shocks. The positive shocks persistency >> that of negative
shocks.
π Period Returns π π π = β π π‘ Γ πΌ π΅π‘β1β₯0
ππ‘=1
Sell at this time point
π
π΅π < 0
0 1
hold
Holding Time Distribution π π = π = π π΅π < 0,π΅πβ1 β₯ 0, β¦ ,π΅1 β₯ 0,π΅0 β₯ 0 = π ππ = 0,ππβ1 = 1, β¦ ,π1 = 1,π0 = 1 = π ππ = 0,ππβ1 = 1, β¦ ,π1 = 1|π0 = 1 π π0 = 1
= οΏ½Ξ ππβ1 1 β π , T β₯1
1 β Ξ , T=0
Stationary state probability: Ξ = 1βπ
2βπβπ
Conditional Returns Distribution (1)
Ξ¦π π π|π=π π = E π π β π π‘ΓπΌ π΅π‘β1β₯0ππ‘=1 π |π = π
= E π π β π π‘ΓπΌ π΅π‘β1β₯0ππ‘=1 π |π΅π < 0,π΅πβ1 β₯ 0, β¦ ,π΅0 β₯ 0
= E π π β π π‘ππ‘=1 π |ππ = 0,ππβ1 = 1, β¦ ,π1 = 1
= E π π π1+β―+ππβ1βπΏπ π
= οΏ½Ξ¦ππβ1 π Ξ¦πΏ βπ , T β₯1Ξ¦πΏ βπ , T =0
Unconditional Returns Distribution (2) Ξ¦π π π π =
β E π π β π π‘ΓπΌ π΅π‘β1β₯0ππ‘=1 π |π = π π π = πβ
π=0 =β Ξ ππβ1 1 β π Ξ¦π
πβ1 π Ξ¦πΏ βπ βπ=1 + 1 β Ξ Ξ¦πΏ βπ
= 1 β Ξ Ξ¦πΏ βπ + Ξ 1 β π Ξ¦πΏ βπ 1βπΞ¦π π
Expected Returns E π π π = βπΞ¦π π π
β² 0
= 11βπ
Ξ πππ β 1 β π ππΏ
When is the expected return positive? ππ β₯
1βπΞ π
ππΏ, shock impact
ππ β« ππΏ, shock impact Ξ π β₯ 1 β π, if ππ β ππΏ, persistence
GMA(β,1) Rule
ππ‘ β₯ β ππ‘βππβ1π=0
1π
lnππ‘ β₯1πβ lnππ‘βππβ1π=0
lnππ‘ β₯ π1
GMA(β,1) Expected Returns Ξ¦π π π π =
1 β Ξ π Ξ¦πΏ π + Ξ¦πΏ βπ +1 β π 1 β Ξ Ξ¦π π + Ξ¦π βπ
E π π π = β 1 β π 1 β Ξ ππ + ππΏ
MA Using the Whole History An investor will always expect to lose money using
GMA(β,1)! An investor loses the least amount of money when the
return process is a random walk.
Optimal MA Parameters So, what are the optimal π and π?
Step 2: AR(1)
Step 2 : ARMA(1, 1)
no systematic winner
optimal order
Step 2 : ARIMA(0, d, 0)
Live Results of Quantitative Trading Strategies
41
Unique Guiding Principle What Others Do: Start with a trading strategy. Find the data that the
strategy works.
Result: Paper P&L looks good. Live P&L depends on luck.
Trading strategies are results of a non-scientific, a pure data snooping process.
What We Do: Start with simple assumptions
about the market. Compute the optimal trading
strategy given the assumptions.
Result: Can mathematically prove
that no other strategy will work better in the same market conditions.
Trading strategies are results of a scientific process.
42
Optimal Trend Following (TREND) We make assumptions that the market is a two (or
three) state model. The market state is either up, down, (or sideway).
In each state, we assume a random walk with positive, negative, or zero drift.
We use math to compute what the best thing to do is in each of the states.
We estimate the conditional probability, π, of that the market is going up given all the available information.
When π is big enough, i.e., most certainly that the market is going up, we buy.
0.00%
20.00%
40.00%
60.00%
80.00%
100.00%
120.00%
140.00%
160.00%
trading period 2015/1/2 - 2016/5/2
assets traded Hang Seng china enterprises
index futures annualized return 107.00% max drawdown 6.61% Sharpe ratio 4.79
Result:
Optimal Trend Following (Math) Two state Markov model for a stockβs prices: BULL and
BEAR.
πππ = ππ ππΌπππ + πππ΅π , π‘ β€ π β€ π < β The trading period is between time π‘,π . πΌπ = 1,2 are the two Markov states that indicates
the BULL and BEAR markets.
π1 > 0
π2 < 0
π = βπ1 π1π2 βπ2
, the generator matrix for the Markov
chain. When π = 0, expected return is
E0,π‘ π π‘ =
Eπ‘ ππ π1βπ‘ β ππππππ
1βπΎπ 1+πΎπ
πΌ ππ<πππ ππ+1βππβ
π=1
We are long between ππ and ππ and the return is determined by the price change discounted by the commissions.
We are flat between ππ and ππ+1 and the money grows at the risk free rate.
Value function:
J0 π,πΌ, π‘,Ξ0 =
Eπ‘π π1 β π‘ +
β log ππππππ
+ πΌ ππ<π log 1βπΎπ 1+πΎπ
+ π ππ+1 β ππβπ=1
J1 π,πΌ, π‘,Ξ1 =
Eπ‘log
ππ1π
+ π π2 β π1 + log 1 β πΎπ +
β log ππππππ
+ πΌ ππ<π log 1βπΎπ 1+πΎπ
+ π ππ+1 β ππβπ=2
Find an optimal trading sequence (the stopping times) so that the value functions are maximized.
ππ π, π‘ = supΞπ
π½π π, π, π‘,Ξπ
ππ: the maximum amount of expected returns
οΏ½π0 π, π‘ = sup
π1πΈπ‘ π π1 β π‘ β log 1 + πΎπ + π1 ππ1 , π1
π1 π, π‘ = supπ1
πΈπ‘ logππ1ππ‘
+ log 1 β πΎπ + π0 ππ1 , π1
Hamilton-Jacobi-Bellman Equations
οΏ½min ββπ0 β π,π0 β π1 + log 1 + πΎπ = 0
min ββπ1 β π π ,π1 β π0 β log 1 β πΎπ = 0
with terminal conditions: οΏ½ π0 π,π = 0π1 π,π = log 1 β πΎπ
β = ππ‘ + 12
π1βπ2 π 1βππ
2πππ + β π1 + π2 π + π2 ππ
Based on: M Dai, Q Zhang, QJ Zhu, "Trend following trading under a regime switching model," SIAM Journal on Financial Mathematics, 2010.
Optimal Mean Reversion (MR)
45
Basket construction problem: Select the right financial instruments. Obtain the optimal weights for the
selected financial instruments. Basket trading problem:
Given the portfolio can be modelled as a mean reverting OU process, dynamic spread trading is a stochastic optimal control problem.
Given a fixed amount of capital, dynamically allocate capital over a risky mean reverting portfolio and a risk-free asset over a finite time horizon to maximize a general constant relative risk aversion (CRRA) utility function of the terminal wealth .
Allocate capital amongst several mean reverting portfolios.
Based on: Mudchanatongsuk, S., Primbs, J.A., Wong, " Optimal Pairs Trading: A Stochastic Control Approach," Dept. of Manage. Sci. & Eng., Stanford Univ., CA.
Optimal Mean Reversion (Math)
46
Assume a risk free asset ππ‘, which satisfies πππ‘ = πππ‘ππ‘
Assume two assets,π΄π‘ and π΅π‘. Assume π΅π‘follows a geometric Brownian
motion. ππ΅π‘ = ππ΅π‘ππ‘ + ππ΅π‘ππ§π‘
π₯π‘is the spread between the two assets. π₯π‘ = logπ΄π‘ β logπ΅π‘
πππ‘ππ‘
= βπ‘ππ΄π‘π΄π‘
+ βπ‘οΏ½ππ΅π‘π΅π‘
+ πππ‘ππ‘
= βπ‘ π π β π₯π‘ + 12π2 + πππ + π ππ‘ +
βπ‘ππππ‘ max
βπ‘πΈ πππΎ , s.t.,
π 0 = π£0, x 0 = π₯0 ππ₯π‘ = π π β π₯π‘ ππ‘ + ππππ‘ πππ‘ = βπ‘ππ₯π‘ = βπ‘π π β π₯π‘ ππ‘ + βπ‘ππππ‘
β π‘ β = ππ‘1βπΎ
β ππ2
π₯π‘ β π + 2πΌ π‘ π₯π‘ + π½ π‘
covariance selection
Intraday Volatility Trading (VOL) In mid or high frequency trading, or
within a medium or short time interval, prices tend to oscillate.
If there are enough oscillations before prices move in a direction, arbitrage exists.
47
profit region
loss region
-20.00%
0.00%
20.00%
40.00%
60.00%
80.00%
100.00%
120.00%
140.00%
trading period 2014/2/27 - 2015/2/27
assets traded Hang Seng china enterprises
index futures annualized return 122.32% max drawdown 10.24% Sharpe ratio 18.45
Live Result:
Intraday Volatility Trading (Math) For a continuous price process ππ‘, we
define H-variation ππ π»,π = sup
πβ π π‘π β π π‘πβ1πΏπ=1
It can be shown that for any H, there exists a sequence ππβ , ππ π=0,1,β¦,π such that ππ π=0,1,β¦,π are Markovian and ππβ are defined by ππ‘ on intervals ππβ1, ππ . And they satisfy the equality: ππ π»,π = β π ππβ β π ππβ1βπ
π=1
ππ π»,π is the number of KAGI-inversion in the T-interval.
H-volatility:
ππ π»,π = ππ π»,πππ π»,π
For an no-arbitrage Wiener process, we have lim
πββππ π»,ππ = πΎπ» = 2π»
Define a trading strategy such that the position of X is: πΎοΏ½π‘πΎ π»,π =
β sign π ππβ1 β π ππβ1β π ππβ1,ππ π‘ππ π»,ππ=1
The trend following P&L is:
ποΏ½π‘πΎ π»,π = β« πΎοΏ½π’πΎ π»,π ππ π’π‘0
= ππ π»,π β 2π» ππ π»,π + π The expected income per trade is:
ππ‘πΎ π»,π = β« πΎπ’πΎ π»,π ππ π’π‘0
π¦π‘πΎ π»,π = ππ‘πΎ π»,πππ‘πΎ π»,π
limπββ
Eπ¦π‘πΎ π»,π = πΎ β 2 π»
48
Based on: SV Pastukhov, "On some probabilistic-statistical methods in technical analysis," Theory of Probability & Its Applications, SIAM, 2005.
Optimal Market Making (MM) We optimally place limit and market
orders depending on the current inventory and spread.
49
the best market making strategy:
trading period 2015/7/16 - 2016/3/1
assets traded rebar + iron ore commodity
futures annualized return 65% max drawdown 0.90% Sharpe ratio 16.71
Live Result:
0.00%
5.00%
10.00%
15.00%
20.00%
25.00%
30.00%
35.00%
40.00%
Optimal Market Making (Math) State variable:
π,π,π, π cash, inventory, mid price, spread
Objective:
maxπΌ
E π ππ β πΎ β« π ππ‘ ππ‘π0
ππ = 0, e.g., donβt hold position overnight π: utility function ππ: terminal wealth πΎ: penalty for holding inventory
Liquidation function (how much we get by selling everything):
πΏ π₯,π¦,π, π = π₯ β π βπ¦,π, π = π₯ + π¦π β π¦ π 2β π
Equivalent problem (get rid of ππ = 0):
maxπΌ
E π πΏ ππ ,ππ ,ππ , ππ β πΎ β« π ππ‘ ππ‘π0
Value function:
π£ π‘, π§, π = supπΌ Eπ‘,π§,π
π πΏ ππ , ππ β πΎ β« π ππ’ ππ’ππ‘
π§ = π₯,π¦,π
This is a mixed regular/impulse control problem in a regime switching jump-diffusion model.
Quasi-Variational Inequality
min βππππ‘β sup βπ,ππ£ + πΎπ,π£ ββ³π£ = 0
Terminal condition:
π£ π, π₯, π¦,π, π = π πΏ π₯,π¦, π, π
For each state π, we have
min
βπππππ‘β π«π£π β β πππ π‘ π£π π‘, π₯,π¦,π β π£π π‘, π₯,π¦, ππ
π=1
β sup πππ ππ π£π π‘, π₯ β πππ ππ,π ππ ,π¦ + ππ ,π β π£π π‘, π₯, π¦,πβ sup πππ ππ π£π π‘, π₯ + πππ ππ,π ππ ,π¦ β ππ ,π β π£π π‘, π₯,π¦, π
+πΎπ,π£π π‘, π₯,π¦,π β sup π£π π‘, π₯ β ππ π, π ,π¦ + π, π
= 0
π£π π, π₯, π¦,π = π πΏπ π₯,π¦,π
Assumptions:
π π₯ = π₯; we care about only how much money made.
ππ‘ π‘ is a martingale; we know nothing about where the market will move.
Solution:
π£π π‘, π₯,π¦, π = π₯ + π¦π + ππ π‘, π¦
ππ π‘,π¦ is the solution to the system of integro-differential equations (IDE):
min
βπππππ‘
β β πππ π‘ ππ π‘,π¦ β ππ π‘,π¦ππ=1
β sup πππ ππ ππ π‘,π¦ + ππ β ππ π‘,π¦ + ππΏ2β πΏ1ππ=ππ‘π+ ππ
β sup πππ ππ ππ π‘, π¦ β ππ β ππ π‘, π¦ + ππΏ2β πΏ1ππ=ππ‘πβ ππ
+πΎπ π¦ ,ππ π‘,π¦ β sup ππ π‘,π¦ + π β ππΏ
2π β π
= 0
ππ π, π¦ = β π¦ ππΏ2β π
50
Based on: F Guilbaud, H Pham, "Optimal high-frequency trading with limit and market orders," Quantitative Finance, 2013.
Conclusions
51
FinMath Infrastructure Support All these mathematics and simulations are possible only with a
finmath technology that serves as the modeling infrastructure.
52
β’ Linear algebra
β’ Calculus
οΏ½ π π₯π
π
= πΉ π β πΉ π
β’ Unconstrained optimization
β’ Statistics
β’ Differential Equations
local minimum global minimum
Financial Mathematics
Advanced Mathematics
Foundation Mathematics
β’ Parallelization
β’ Cointegration
β’ Optimization (LP, QP, SQP, SDP, SOCP, IP, GA)
β’ Digital Signal Processing
β’ Time Series Analysis
Applications
β’ Optimal Trading Strategies
β’ Portfolio Optimization
β’ Extreme Value Theory
β’ Trading Signals
β’ Asset Allocation
β’ Risk Management
The Essential Skills
53
Financial intuitions, market understanding, creativity. Mathematics. Computer programming.
An Emerging Field
54
It is a financial industry where mathematics and computer science meet.
It is an arms race to build more reliable and faster execution platforms (computer
science); more comprehensive and accurate prediction models
(mathematics).