part 1 back testing quantitative trading strategies · 1 of 21 february 27, 2017 qf206 week 9 a...

21
1 of 21 February 27, 2017 QF206 Week 9 A Guide to Your Team Project © Christopher Ting Part 1 Back Testing Quantitative Trading Strategies

Upload: phamdieu

Post on 29-Jul-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

1 of 21 February 27, 2017

QF206 Week 9

A Guide to Your Team Project

© Christopher Ting

Part 1 Back TestingQuantitative Trading Strategies

2 of 21 February 27, 2017

QF206 Week 9

Pre-requisite

© Christopher Ting

The most important ingredient to any quantitative trading strategy is data that are compatible with the nature of the strategy.

For example, for intra-day trading strategy, you need at least one-minute bar data.

For HFT, you need at leas tick data for backtesting.

For ulta HFT, you need low-level messages received by the exchanges.

3 of 21 February 27, 2017

QF206 Week 9

Data Example

© Christopher Ting

Period: 1-minute intervalTime 1: time at which the first trade in the 1-minute interval occursTime 2: time at which the last trade in the 1-minute interval occursOF_Trades: order flow in number of trades over 1minute OF_Vol: order flow in signed volume over 1 minute

S/N Date Period Time1 Time2 Open High Low Close Trades VolumeOF_

TradesOF_Vol

0 2016-12-08 7:00:00 7:00:00 7:00:57 18650 18650 18630 18630 3 7 -2 -21 2016-12-08 7:01:00 7:00:57 7:00:57 18630 18630 18630 18630 0 0 0 02 2016-12-08 7:02:00 7:02:19 7:02:25 18635 18635 18635 18635 5 7 -3 -33 2016-12-08 7:03:00 7:03:32 7:03:32 18630 18630 18625 18625 2 2 -2 -24 2016-12-08 7:04:00 7:03:32 7:03:32 18625 18625 18625 18625 0 0 0 05 2016-12-08 7:05:00 7:03:32 7:03:32 18625 18625 18625 18625 0 0 0 06 2016-12-08 7:06:00 7:03:32 7:03:32 18625 18625 18625 18625 0 0 0 07 2016-12-08 7:07:00 7:03:32 7:03:32 18625 18625 18625 18625 0 0 0 08 2016-12-08 7:08:00 7:08:20 7:08:59 18620 18620 18620 18620 2 5 0 3

4 of 21 February 27, 2017

QF206 Week 9

Intra-Day BackTesting on One-Minute Data?

© Christopher Ting

You have a trading strategy, and it has a parameter denoted by θ.

You have historical data of futures (or any other financial instruments).

Suppose in your historical data, your trading strategy finds 200 trading signals to short (or to long).

Suppose the parameter θ is the holding period before squaring off your position.

You separate the 200 signals into two portions:

o Say, 70% of the signals are used for finding an optimal value of θsuch that it gives the best in-sample performance in this 70%.

o Fix this optimal θ, and measure the out-of-sample performance of the trading strategy in the other 30% of the signals.

5 of 21 February 27, 2017

QF206 Week 9

Buying and Selling in Back-Testing

© Christopher Ting

Ideally, you should have the best bid price and the best ask price at the beginning and also at the end of every minutes.

When selling one contract at the beginning of t+1, you sell at the best bid price.

When buying one contract at the end of t+1+θ, you buy at the best offer price.

Your task is to find an optimal θ that gives the best performance after all costs such as commissions and clearing fees (if any).

For the project, the per-contract commission is assumed to be 500 yens.

6 of 21 February 27, 2017

QF206 Week 9

In-Sample “Training” of θ

© Christopher Ting

For every signal, the size of your position is one contract.

You need to know the commission for trading one contract (assumed to be 500 yens per contract).

When the signal is generated at time t, you cannot trade at time t but at (the beginning of) time t+1.

As a risk management policy, you must square off any outstanding position before the trading session closes.

At time t, you short, and at time t+1+θ, you square off your short position.

Your task is to find an optimal θ that gives the best performance.

7 of 21 February 27, 2017

QF206 Week 9

Specifically>>>>

© Christopher Ting

You let θ equal to 1 minute. Measure the performance for the 70% in-sample signals.

You let θ equal to 2 minute. Again measure the in-sample performance.

Do likewise, for θ up to 20 minutes.

Obviously, as θ becomes larger, the number of tradable signals is smaller as time t+1+θ could be after the end of the trading session

8 of 21 February 27, 2017

QF206 Week 9

What is a good performance measure?

© Christopher Ting

Before answering the question, look at the numbers generated by back-testing.

A sequence of P&Ls after round-trip commission costs and other costs

Based on the P&Ls, categorize the signals as correct and incorrect

Count the numbers of correct and incorrect signals, which are denoted by Nc and Ni, respectively.

The winning probability is

Obviously, higher p is better.

𝑝 =𝑁𝑐

𝑁𝑐 + 𝑁𝑖

9 of 21 February 27, 2017

QF206 Week 9

Reward-to-Risk Ratio

© Christopher Ting

Compute the average positive P&Ls of correct signals. Do likewise for incorrect signals. Let these averages be Ac and Ai, respectively.

So Ac can be interpreted as the average gain when the signal is correct, and Ai is the average loss amount if the signal is incorrect.

The reward-to-risk ratio is

Obviously, higher r is better.

𝑟 =𝐴𝑐𝐴𝑖

10 of 21 February 27, 2017

QF206 Week 9

Compute the average P&L from the sequence of n number of P&Ls. Denote it by Mn.

Compute the unbiased standard deviation, denoted by Sn.

“Sharpe ratio” is simply the risk-adjusted P&L

Given the null hypothesis of zero mean P&L, the t-statistic is, with n being the total number of signals in the sample,

Sharpe Ratio and t statistic

© Christopher Ting

Sharpe =𝑀𝑛

𝑆𝑛

𝑡 = 𝑛𝑀𝑛

𝑆𝑛

11 of 21 February 27, 2017

QF206 Week 9

THE Performance Measure

© Christopher Ting

The t statistic is a statistically sound measure. It shows the level of significance of the average P&L against the amount of variation in the in-sample P&L.

Therefore, you mainly use the t statistic as the benchmark. You want to find θ* such that t is the largest possible.

In other words, you are solving this maximization problem:

n

n

S

Mnmaxargθ*

12 of 21 February 27, 2017

QF206 Week 9

An Example of In-Sample Performance

© Christopher Ting

Holding Time

Number of Trades

Total P&L (after comms)

Average Gain

Average Loss

Probability of win

t-statistic

3 70 $2,917.00 $120.05 $129.16 60.02 2.064 70 $3,007.00 $118.05 $130.91 61.99 2.125 67 $3,198.00 $121.39 $131.71 64.58 2.216 67 $3,876.00 $138.74 $129.65 66.17 2.277 67 $3,911.00 $140.20 $119.28 67.17 2.438 66 $3,958.00 $141.33 $114.38 68.18 2.869 66 $3,633.00 $150.50 $135.86 66.67 2.37

10 66 $4,208.00 $170.14 $122.42 63.64 2.6411 66 $3,708.00 $155.93 $173.25 69.70 2.1612 62 $3,906.00 $176.41 $158.43 66.13 2.2013 60 $4,155.00 $192.05 $128.30 61.67 2.3414 60 $4,080.00 $202.58 $133.88 60.00 2.2815 57 $4,316.00 $200.84 $155.75 64.91 2.4016 55 $4,290.00 $199.18 $192.88 69.09 2.35

13 of 21 February 27, 2017

QF206 Week 9

What is the Performance of the Trading Strategy?

© Christopher Ting

It is the performance of the trading strategy on out-of-sample signals.

Typically, in-sample performance measure is higher than that of out-of-sample.

If the t statistic of out-of-sample performance is bigger than 2, then the quantitative trading strategy may generate consistent alpha.

14 of 21 February 27, 2017

QF206 Week 9

When does a trading strategy stop working?

© Christopher Ting

No trading strategy will work forever.

A good strategy may deteriorate over time!

When to pull the plug?

As a rule of thumb, look at the rolling 30-signal tstatistic. If it becomes statistically insignificant, stop the trading strategy.

15 of 21 February 27, 2017

QF206 Week 9

Equity Curve

© Christopher Ting

From the in-sample subsequence of P&Ls, xt , you can construct an equity curve as follows:

In other words,

C1= x1,

C2 = C1 + x2 = x1 + x2 ,

C3 = C2 + x2 = x1 + x2 + x3 ,

and so on

Cn = Cn-1 + xn = x1 + x2 +….. + xn

t

s

st xC1

16 of 21 February 27, 2017

QF206 Week 9

Illustration of Equity Curve and Drawdown

© Christopher Ting

Source: Quantitative Trading: How to Build Your Own Algorithmic Trading Business (2009)

or longest

17 of 21 February 27, 2017

QF206 Week 9

Performance Metrics: Maximum Drawdown

© Christopher Ting

The maximum drawdown characterises the largest peak-to-trough drop in the equity curve over a particular time period (usually annual). This is most often quoted as a percentage.

LFT strategies will tend to have larger drawdowns than HFT strategies, due to a number of statistical factors.

A historical backtest will show the past maximum drawdown, which is a good guide for the future drawdown performance of the strategy.

18 of 21 February 27, 2017

QF206 Week 9

Sensitivity Analysis

© Christopher Ting

Sound, fundamental reasoning for parameter choices should, with all other factors considered, lead to a smoother parameter curve or surface. If you have a very jumpy performance surface, it often means that a parameter is not robust.

There is a vast literature on multi-dimensional optimisation algorithms and it is a highly active area of research.

19 of 21 February 27, 2017

QF206 Week 9

Good example:

Sharpe ratio increases then decreases

Bad example

Sharpe ratio appears random

Examples of Sensitivity Analysis

© Christopher Ting

Parameter 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3

Sharpe Ratio 10.0% 10.3% 11.1% 11.5% 14.2% 12.8% 10.9% 9.2% 8.7%

Parameter 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3

Sharpe Ratio 11.0% 6.3% 16.0% -5.5% 19.4% 2.0% 11.9% 19.2% 9.7%

20 of 21 February 27, 2017

QF206 Week 9

Project Administration

© Christopher Ting

What you need to prepare as a team: a project report and a set of presentation slides.

Each team member will evaluate the performance and contribution of other members in the team, so as to be fair to the hard working, and persons with brilliant idea and strong skillset.

If you are not presenting, you are to evaluate the presentation performance of the other teams.

21 of 21 February 27, 2017

QF206 Week 9

Additional Incentives

© Christopher Ting

My ex prop firm is looking for a full-time quantitative researcher.

Other boutique hedge funds are also looking for quantitative researchers.

Usually a quant researchers, if doing exceptionally well, can transit to the role of a trader after a few years.

If you worry too much about your academic grade, you probably won’t survive in the jungle of trading.