high frequency trading - stanford university...high frequency trading mse 448 - group 1 thibaud...

25
High Frequency Trading MSE 448 - Group 1 Thibaud Bruyelle Brian Lui Computational Engineering Computer Science [email protected] [email protected] Tom Morvan Julius Stener Computational Engineering Computer Science [email protected] [email protected] Stanford University June 3, 2020 MSE 448 - Group 1 T. Bruyelle, T. Morvan, Brian Lui, Julius Stener, Stanford 1/25

Upload: others

Post on 24-Jan-2021

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: High Frequency Trading - Stanford University...High Frequency Trading MSE 448 - Group 1 Thibaud Bruyelle Brian Lui Computational Engineering Computer Science thibaudb@stanford.edu

High Frequency TradingMSE 448 - Group 1

Thibaud Bruyelle Brian LuiComputational Engineering Computer Science

[email protected] [email protected]

Tom Morvan Julius StenerComputational Engineering Computer Science

[email protected] [email protected]

Stanford University

June 3, 2020

MSE 448 - Group 1 T. Bruyelle, T. Morvan, Brian Lui, Julius Stener, Stanford 1/25

Page 2: High Frequency Trading - Stanford University...High Frequency Trading MSE 448 - Group 1 Thibaud Bruyelle Brian Lui Computational Engineering Computer Science thibaudb@stanford.edu

Table of contents

1. Introduction

1.1 HFT

1.2 Strategy development framework

1.3 Data & General Statistics

2. Mean Reversal in HFT

2.1 Statistical Principle

2.2 Strategy

3. Pairs Trading in HFT

3.1 Statistical Principle

3.2 Strategy

4. Conclusion

MSE 448 - Group 1 T. Bruyelle, T. Morvan, Brian Lui, Julius Stener, Stanford 2/25

Page 3: High Frequency Trading - Stanford University...High Frequency Trading MSE 448 - Group 1 Thibaud Bruyelle Brian Lui Computational Engineering Computer Science thibaudb@stanford.edu

1. Introduction - High Frequency Trading

Goal

Build a fully automated trading strategy that executes largeamount of trades based on sub-second data.

Requires:

I Vast amount of granular order book data.

I Algorithms that produce trading signals in split-seconds.

Maystreet Simulator provides an ideal framework for HFTstrategy development.

MSE 448 - Group 1 T. Bruyelle, T. Morvan, Brian Lui, Julius Stener, Stanford 3/25

Page 4: High Frequency Trading - Stanford University...High Frequency Trading MSE 448 - Group 1 Thibaud Bruyelle Brian Lui Computational Engineering Computer Science thibaudb@stanford.edu

1. Introduction - Maystreet Simulator

Maystreet Simulator

Full Market Replay order by order.

What’s handled by the simulator:

I Real-time order book data retrieval

I Trading order management and execution with slippage

What’s not handled by the simulator:

I Market activity fees (Trading fees, Equity Borrow fees...)

I Reaction of other agents to our trading activity

I Multiday simulation

MSE 448 - Group 1 T. Bruyelle, T. Morvan, Brian Lui, Julius Stener, Stanford 4/25

Page 5: High Frequency Trading - Stanford University...High Frequency Trading MSE 448 - Group 1 Thibaud Bruyelle Brian Lui Computational Engineering Computer Science thibaudb@stanford.edu

1. Introduction - Maystreet Simulator

Algorithm Framework

Set parameters and start trading day

I At every time interval:I Retrieve Market DataI Update statisticsI Send and/or Cancel a trade

I At every order message from exchange:I Check if our orders have been filledI Update portfolio

MSE 448 - Group 1 T. Bruyelle, T. Morvan, Brian Lui, Julius Stener, Stanford 5/25

Page 6: High Frequency Trading - Stanford University...High Frequency Trading MSE 448 - Group 1 Thibaud Bruyelle Brian Lui Computational Engineering Computer Science thibaudb@stanford.edu

1. Introduction - Data

Market Open Data

MSE 448 - Group 1 T. Bruyelle, T. Morvan, Brian Lui, Julius Stener, Stanford 6/25

Page 7: High Frequency Trading - Stanford University...High Frequency Trading MSE 448 - Group 1 Thibaud Bruyelle Brian Lui Computational Engineering Computer Science thibaudb@stanford.edu

1. Introduction - Statistical studies

Which statistical tools to assess these data ?

I Statistical tests (Is the time serie stationary?, Are the returnsnormally distributed?, Are these two series cointegrated?)

I Statiscal/Time Series Analysis (Any correlation in a givenportfolio? , Can we create clusters within this portfolio?)

I Stochastic Modelling (Can we estimate parameters thatprovide us relevant information?)

MSE 448 - Group 1 T. Bruyelle, T. Morvan, Brian Lui, Julius Stener, Stanford 7/25

Page 8: High Frequency Trading - Stanford University...High Frequency Trading MSE 448 - Group 1 Thibaud Bruyelle Brian Lui Computational Engineering Computer Science thibaudb@stanford.edu

1. Introduction - Price and Returns Series

I Bid and Ask series over a trading day

I Time interval can be very small (up to 1µs)

AAPL Bid/Ask - 2015/01/21 AAPL Mid returns - 2015/01/21

MSE 448 - Group 1 T. Bruyelle, T. Morvan, Brian Lui, Julius Stener, Stanford 8/25

Page 9: High Frequency Trading - Stanford University...High Frequency Trading MSE 448 - Group 1 Thibaud Bruyelle Brian Lui Computational Engineering Computer Science thibaudb@stanford.edu

1. Introduction - Returns and market influence

I In order to make an analysis of the returns series Rt , we useSPDR S&P 500 returns Mt to compute the linear regression :

Rt = βMt + α + εt

AAPL returns against Market

I We then used the residuals εt to do our analysis.

MSE 448 - Group 1 T. Bruyelle, T. Morvan, Brian Lui, Julius Stener, Stanford 9/25

Page 10: High Frequency Trading - Stanford University...High Frequency Trading MSE 448 - Group 1 Thibaud Bruyelle Brian Lui Computational Engineering Computer Science thibaudb@stanford.edu

2. Mean Reversal - Statistical Principle

Mean Reversal relies on the assumption that longer term movingaverages are more consistent than shorter term movingaverages

I Most-Relevant Hyperparameters Available:

I Short and Long Interval Periods

I Time Intervals between Strategy Executions

I Traded Universe

I Data to be tracked for the ”Mean”

MSE 448 - Group 1 T. Bruyelle, T. Morvan, Brian Lui, Julius Stener, Stanford 10/25

Page 11: High Frequency Trading - Stanford University...High Frequency Trading MSE 448 - Group 1 Thibaud Bruyelle Brian Lui Computational Engineering Computer Science thibaudb@stanford.edu

2. Mean Reversal - Statistical Tools

Using a statistical modelling approach can be useful to considersome metrics that will bring us relevant information.

I Hurst exponent H

I The Hurst exponent, H, measures the long-term memory of atime series, characterising it as either mean-reverting, trendingor a random walk. We have :

E(R(n)

S(n)) = CnH

MSE 448 - Group 1 T. Bruyelle, T. Morvan, Brian Lui, Julius Stener, Stanford 11/25

Page 12: High Frequency Trading - Stanford University...High Frequency Trading MSE 448 - Group 1 Thibaud Bruyelle Brian Lui Computational Engineering Computer Science thibaudb@stanford.edu

2. Mean Reversal - Statistical Tools

I The Ornstein–Uhlenbeck process Xt is defined by thefollowing stochastic differential equation:

dXt = θ(µ− Xt)dt + σdWt

I Useful model in a mean reversion context because theparameter θ is the speed of reversion.

I Thus, we can model the half-time which is the time it takesfor the series to move half the distance towards its long termaverage :

T1/2 =ln(2)

θ

MSE 448 - Group 1 T. Bruyelle, T. Morvan, Brian Lui, Julius Stener, Stanford 12/25

Page 13: High Frequency Trading - Stanford University...High Frequency Trading MSE 448 - Group 1 Thibaud Bruyelle Brian Lui Computational Engineering Computer Science thibaudb@stanford.edu

2. Mean Reversal - Strategy

I Traded Universe

I Utilized the Russell 2000 tickers

I Chose Small Caps due to their relative stability against markettrends due to lower trading volumes

I Cleaned the Russell tickers for use on the Maystreet Simulator(resulted in < 1500 tickers)

I Type of ”Mean”

I Bid

I Ask

I Mid

I Implemented due to the simplicity of tracking one set of means

I Naively ignores the bid-ask spread cost when producing atrading signal

MSE 448 - Group 1 T. Bruyelle, T. Morvan, Brian Lui, Julius Stener, Stanford 13/25

Page 14: High Frequency Trading - Stanford University...High Frequency Trading MSE 448 - Group 1 Thibaud Bruyelle Brian Lui Computational Engineering Computer Science thibaudb@stanford.edu

2. Mean Reversal - Results

2018-07-16

˜$10,000 traded with End of Day PNL at $(178.16)

MSE 448 - Group 1 T. Bruyelle, T. Morvan, Brian Lui, Julius Stener, Stanford 14/25

Page 15: High Frequency Trading - Stanford University...High Frequency Trading MSE 448 - Group 1 Thibaud Bruyelle Brian Lui Computational Engineering Computer Science thibaudb@stanford.edu

2. Mean Reversal - Optimizations

2 Primary Methods we have identified as worth exploring

I Large-scale Grid Search

I Due to the high-dimensionality of hyperparameters, thesmall-subset version of this will take 6̃ days

I 1420 tickers across 2̃00 hyper-parameter configurations withmultiple random trials to determine the most profitable/leastrisk-inclined strategy tickers

I Reinforcement Learning

I This is a task for RL due the innate ability to learn state andaction pairs across high-dimensionality parameters

I Barrier to implementation: running out of time due to the lostweek

MSE 448 - Group 1 T. Bruyelle, T. Morvan, Brian Lui, Julius Stener, Stanford 15/25

Page 16: High Frequency Trading - Stanford University...High Frequency Trading MSE 448 - Group 1 Thibaud Bruyelle Brian Lui Computational Engineering Computer Science thibaudb@stanford.edu

3. Pairs Trading - Principal Component Analysis

I Portfolio : AAPL, ADOBE, BOA, CRM, GS, JPM, MA,MSFT, VISA.

I Residual Returns εt must be stationary to satisfy theassumptions of th PCA model.

I Augmented Dickey Fuller test assumes that :

εt = ρ · εt−1 + ut

Test for the presence of a unit root, ie, H0 : ρ = 1

I Conclusion : For the returns series, we can always reject H0

at all confidence levels so the models assuming that ourobservations must be iid can be used.

MSE 448 - Group 1 T. Bruyelle, T. Morvan, Brian Lui, Julius Stener, Stanford 16/25

Page 17: High Frequency Trading - Stanford University...High Frequency Trading MSE 448 - Group 1 Thibaud Bruyelle Brian Lui Computational Engineering Computer Science thibaudb@stanford.edu

Pairs Trading - Principal Component Analysis

I PCA to observe correlation patterns within the portfolio.

I Conclusion : We easily observe several trends and can notice astrong industry influence (technology, finance)

MSE 448 - Group 1 T. Bruyelle, T. Morvan, Brian Lui, Julius Stener, Stanford 17/25

Page 18: High Frequency Trading - Stanford University...High Frequency Trading MSE 448 - Group 1 Thibaud Bruyelle Brian Lui Computational Engineering Computer Science thibaudb@stanford.edu

3. Pairs Trading - Correlation and Cointegration

I For several reasons, we would like to study the associationbetween two (or more) stocks (e.g. Pairs Trading)

I Correlation : when two securities move together in the samedirection or opposite direction.

I Cointegration : when the distance between the pair doesn’tchange drastically over time.

Why studying cointegration ?

I Granger – Engel test to check if two series xt , yt arecointegrated. We must have xt , yt ∼ I(1) andyt = α + βxt + ut with ut ∼ I(0).

MSE 448 - Group 1 T. Bruyelle, T. Morvan, Brian Lui, Julius Stener, Stanford 18/25

Page 19: High Frequency Trading - Stanford University...High Frequency Trading MSE 448 - Group 1 Thibaud Bruyelle Brian Lui Computational Engineering Computer Science thibaudb@stanford.edu

3. Pairs Trading - Clustering

I Another approaches to make associations within the portfoliousing unsupervised algorithms :clustering algorithm.

I K-means with Euclidean distance

K-means with PCA reduction

MSE 448 - Group 1 T. Bruyelle, T. Morvan, Brian Lui, Julius Stener, Stanford 19/25

Page 20: High Frequency Trading - Stanford University...High Frequency Trading MSE 448 - Group 1 Thibaud Bruyelle Brian Lui Computational Engineering Computer Science thibaudb@stanford.edu

3. Pairs Trading - Strategy

Financial Framework

We define a new asset:

S = nASA − nBSB

With nA, nB > 0 such that S ≈ 0I No exposure on market movementsI Cash balance ≈ 0

Statistics

We define:

Z =S − µSσS

Over a rolling time interval.

MSE 448 - Group 1 T. Bruyelle, T. Morvan, Brian Lui, Julius Stener, Stanford 20/25

Page 21: High Frequency Trading - Stanford University...High Frequency Trading MSE 448 - Group 1 Thibaud Bruyelle Brian Lui Computational Engineering Computer Science thibaudb@stanford.edu

3. Pairs Trading - Strategy

Day - 20181112

MSE 448 - Group 1 T. Bruyelle, T. Morvan, Brian Lui, Julius Stener, Stanford 21/25

Page 22: High Frequency Trading - Stanford University...High Frequency Trading MSE 448 - Group 1 Thibaud Bruyelle Brian Lui Computational Engineering Computer Science thibaudb@stanford.edu

3. Pairs Trading - Strategy

Algorithm Framework

Set parameters and start trading day

I At every time interval:I Retrieve Market DataI Update statisticsI Cancel all existing ordersI Decide to send a trade

I At every order message from exchange:I Check if our orders have been filledI Update portfolio

MSE 448 - Group 1 T. Bruyelle, T. Morvan, Brian Lui, Julius Stener, Stanford 22/25

Page 23: High Frequency Trading - Stanford University...High Frequency Trading MSE 448 - Group 1 Thibaud Bruyelle Brian Lui Computational Engineering Computer Science thibaudb@stanford.edu

3. Pairs Trading - Strategy

Day - 20181112

MSE 448 - Group 1 T. Bruyelle, T. Morvan, Brian Lui, Julius Stener, Stanford 23/25

Page 24: High Frequency Trading - Stanford University...High Frequency Trading MSE 448 - Group 1 Thibaud Bruyelle Brian Lui Computational Engineering Computer Science thibaudb@stanford.edu

3. Pairs Trading - Strategy

Day - 20181112

MSE 448 - Group 1 T. Bruyelle, T. Morvan, Brian Lui, Julius Stener, Stanford 24/25

Page 25: High Frequency Trading - Stanford University...High Frequency Trading MSE 448 - Group 1 Thibaud Bruyelle Brian Lui Computational Engineering Computer Science thibaudb@stanford.edu

Conclusion

Mean Reversion:

I Few hyper-parameters with high-dimensionality.

I Simulator is powerful, but makes multi-day backtesting slowand inefficient.

I Next Steps: Optimizing the backtesting Class to increase thedescent speed to optimum.

Pair Trading:

I A lot hyper-paramters.

I Simulator framework hard to backtest.

I Incorporating mean reversal idea to spot trends in pairs.

MSE 448 - Group 1 T. Bruyelle, T. Morvan, Brian Lui, Julius Stener, Stanford 25/25