### FE8827 Quantitative Trading Strategies project High Frequency

```FE8827 QUANTITATIVE
PROJECT
REGIME SWITCHING STRATEGY
Huynh Gia Huy (G1000176L)
Le Hoang Thai (G1000293G)
REFERENCE

Models”, Leandro Rafael Infantino, Savion
Itzhaki, MBA thesis, MIT, June 2010.
CONTENTS
Simply Guide
 Model Building: motivation, trading ideas,
potential problems and implementation.
 Simulation Results: without/with transaction
costs, development from the thesis.
 Weaknesses of Trading Signals in the Thesis and
Proposed Improvement: mean reverting signals
and regime switching signals.

SIMPLE GUIDE


To display performance statistics, run rsperf.m file: rsperf(index,
rf, lossthreshold)
Input:
index = 1: regime switching with transaction costs.
index = 2: regime switching without transaction costs.
index = 3: mean reverting with transaction costs.
index = 4: mean reverting without transaction costs.
rf: risk free rate
lossthreshold: omega loss threshold

Ouput: Omega ratio, Sharpe ratio, Omega Sharpe ratio, MaxDD
(max drawdown) and MaxDDD (max drawdown duration).
SIMPLE GUIDE


To start trading strategies, run regswitch.m file.
In this file, turn on/off regime switching by setting regimeSwitching
variable to 1 to turn on and 0 to turn off.
regimeSwitching = 1; % default value

Change line 32 in this file to run simulation for a period of time.
Default is whole year running from week 1 to week 52.
for week=1:52
MODEL BUILDING - MOTIVATION

In high frequency environment, high precision of
the stock return prediction is not required.

Fundamental Law of Active Management
IR: Information Ratio
IC: Information Coefficient (our skill)
Breadth: “the number of independent forecasts of
Breadth very big => IC can be relatively small
=> prediction can be less precise
Use Principle Component Analysis (PCA) as the
basis to compute cumulative returns
 Depending on the current strategy (meanreversion or momentum), trading signals are
generated if observed cumulative returns differ
from model cumulative returns.

Predicted – observed > threshold => buy (sell)
 Predicted – observed < -threshold => sell (buy)

DIFFERENCES BETWEEN THIS PROJECT
AND THE PAPER





Number of stocks used in the simulation: only first 10
stocks (instead of 50) are chosen to represent the
stock universe.
Data source: the primary data used in this project is
obtained from Thomson Reuters Tick History
database, and from two major exchanges: NASDAQ
and NYSE; whereas prices used in the thesis are from
top of the book bid-ask quotes.
Model parameters: various model parameters are not
specified in the thesis, thus simulation results can be
affected by the choice of different parameter values.
Transaction costs are included.
Signal in the thesis is found insufficient and has been
modified to improve stabilty and performance of
returns.
MODEL BUILDING - POTENTIAL PROBLEMS
- DATA VOLUME

Huge volume of data: more than 15Gbs of one
year tick data to process (and that’s only for 10
stocks).
Simulation time can be very long because of this.
 Code optimization is important!

IMPLEMENTATION
Matlab is chosen as it provides many built-in
mathematics functions suitable for rapid model
development.
 Pre-process data before running simulation:

Only one mid-price per second per stock
 Need to duplicate values for missing seconds in raw
data.
 Processed data saved in separate .csv files.


Run simulation based on processed data.

All daily returns are saved in .csv files.
SOME CODE OPTIMIZATION TECHNIQUES
Always pre-allocate memory for matrix and avoid
changing matrix size constantly.
 Avoid loop as much as possible and make use of
Vectorization (performance increased
dramatically!)

Normal for loop
i = 0;
for t = 0:.01:10
i = i + 1;
y(i) = sin(t);
end

Vectorization
t = 0:.01:10;
y = sin(t);
Use Matlab profiler to identify areas for
improvement.
SIMULATION RESULTS - THESIS

Mean-reversion strategy, without transaction
cost.
SIMULATION RESULTS – THIS PROJECT
Mean-reversion strategy, without transaction
cost.
Cumulative returns
600.00%
500.00%
400.00%
300.00%
200.00%
100.00%
0.00%
1
9
17
25
33
41
49
57
65
73
81
89
97
105
113
121
129
137
145
153
161
169
177
185
193
201
209
217
225
233
241
249

SIMULATION RESULTS – THIS PROJECT
Mean-reversion strategy, without transaction
cost.
 Omega: 2.6741 (Loss threshold: 0)
 Sharpe: 0.3507
 Omega Sharpe: 0.0022
 Max Drawdown: 0.1566
 Max Drawdown duration: 73 days.

SIMULATION RESULTS - THESIS

Regime switching strategy, without transaction
cost.
SIMULATION RESULTS – THIS PROJECT
Regime switching strategy, without transaction
cost.
Cumulative returns
15.00%
10.00%
5.00%
0.00%
-5.00%
-10.00%
-15.00%
-20.00%
-25.00%
-30.00%
1
9
17
25
33
41
49
57
65
73
81
89
97
105
113
121
129
137
145
153
161
169
177
185
193
201
209
217
225
233
241
249

SIMULATION RESULTS – THIS PROJECT
Regime switching strategy, without transaction
cost.
 Omega: 0.7381 (Loss threshold: 0)
 Sharpe: -0.0903
 Omega Sharpe: -0.0014
 Max Drawdown: 0.5569
 Max Drawdown duration: 226 days.


The different simulation results between this
project and thesis can be due to:
Different stock universe
 Different data source (therefore different mid-prices)
 Parameters used (thresholds).


In the thesis, transaction cost is not taken into
account and it is a important factor to consider in


All profits can be erased by transaction cost.
Next step for this project: include transaction
cost!

To be realistic, transaction cost from Interactive
Brokers is used; that is, \$0.005 / share / trade
TRANSACTION COSTS:
MODIFICATIONS TO EXISTING STRATEGY

In an attempt to factor in the transaction cost,
the trading model is modified. Two potential
places:

Mark-up the threshold by the transaction cost, i.e.
new threshold = threshold + transaction cost

Lower the log returns. Use this new log returns as
input for Principal Components Analysis
log_return = log[(current_price - cost) / previous_price + cost)]

This project uses the second approach.
SIMULATION RESULT – MODIFIED MODEL
Mean-reversion strategy, with transaction cost.
Cumulative returns
20.00%
15.00%
10.00%
5.00%
0.00%
1
9
17
25
33
41
49
57
65
73
81
89
97
105
113
121
129
137
145
153
161
169
177
185
193
201
209
217
225
233
241
249

-5.00%
-10.00%
-15.00%
-20.00%
SIMULATION RESULTS – THIS PROJECT
Mean-reversion strategy, with transaction cost.
 Omega: 1.0131 (Loss threshold: 0)
 Sharpe: 0.0192
 Omega Sharpe: 0.0002315
 Max Drawdown: 0.2373
 Max Drawdown duration: 68 days.

SIMULATION RESULT – MODIFIED MODEL
Modified regime switching strategy, with
transaction cost.
Cumulative returns
5.00%
0.00%
-5.00%
-10.00%
-15.00%
-20.00%
-25.00%
-30.00%
-35.00%
1
10
19
28
37
46
55
64
73
82
91
100
109
118
127
136
145
154
163
172
181
190
199
208
217
226
235
244

SIMULATION RESULTS – THIS PROJECT
Mean-reversion strategy, with transaction cost.
 Omega: 0.7805 (Loss threshold: 0)
 Sharpe: -0.0708
 Omega Sharpe: -0.0010
 Max Drawdown: 0.4941
 Max Drawdown duration: 248 days.

WEAKNESSES OF THE TRADING SIGNALS IN
THE THESIS – PROPOSED IMPROVEMENTS

Mean reverting signal:
In the thesis, if mean reverting signal > 0, we buy
and sell when signal < 0. It includes noise due to
rounding or computational issues.
 Solution: set a threshold to filter away noise that
 This threshold after trial and error has been
determined to be 0.0001 (parameter 1)

WEAKNESSES OF THE TRADING SIGNALS IN
THE THESIS - PROPOSED IMPROVEMENTS

Regime Switching Signals:

The authors use difference in two consecutive
Euclidean distance to signal the regime switching:
If EH(t) - EH(t-1) > 0: momentum regime
 If EH(t) - EH(t-1) < = 0: mean reverting regime


This signals introduce noise and cause fault signals
WEAKNESSES OF THE TRADING SIGNALS IN
THE THESIS - PROPOSED IMPROVEMENTS

Regime Switching Signals – Noise
Diagram of Euclidean distance difference (EH(t) EH(t-1)) is shown above.
 According to the authors, the strategy keeps
changing the regimes as signals swing around 0 from
positive to negative.

WEAKNESSES OF THE TRADING SIGNALS IN
THE THESIS - PROPOSED IMPROVEMENTS

Regime Switching Signals – Fault Signals
Diagram of Euclidean distance difference (EH(t) - EH(t-1)) is shown
above and Euclidean distance(EH(t)) below.
 One strong pulse in E distance creates one regime switching signal
but it contains one up pulse and one down pulse in E distance
difference. According to the authors, it creates two signals that causes
the system to switch back and forth (mean reverting -> momentum ->
mean reverting) within <150 seconds.

WEAKNESSES OF THE TRADING SIGNALS IN
THE THESIS - PROPOSED IMPROVEMENTS

Regime Switching Signals – Noise – Solution
We set a threshold of 2 standard deviation to filter
out noise (parameter 2). Magnitude falls between ± 2
std dev is considered insignificant.
 Instead of using differences of 2 consecutive E
distance (EH(t) - EH(t-1)), we use EH(t) –
ewma5(EH(t)) where ewma5(EH(t)) is equally
weighted moving averages value of previous 5
seconds of E distance (parameter 3).
 Ignore 2 consecutive regime switching signals fall
into a timespan of less than 250 seconds to remove
fault signals (parameter 4).

CONCLUSIONS
Simulation returns are very sensitive to
parameters used.
 All 4 parameters can be improved by employing
optimization.
 Due to the time constraint, we leave this part for
future development.

```