13.08.2022 Views

advanced-algorithmic-trading

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

402

Hence we can "long the spread" if the forecast error drops below the negative standard

deviation of the spread. Respectively we can "short the spread" if the forecast error exceeds the

positive standard deviation of the spread. The exit rules are simply the opposite of the entry

rules.

The dynamic hedge ratio is represented by one component of the hidden state vector at time

t, θ t , which we will denote as θt 0 . This is the "beta" slope value that is well known from linear

regression.

"Longing the spread" here means purchasing (longing) N units of TLT and selling (shorting)

⌊θt 0 N⌋, where ⌊x⌋ is the "floor" representing the highest integer less than x. The latter is

necessary as we must transact a whole number of units of the ETFs. "Shorting the spread" is

the opposite of this. N controls the overall size of the position.

e t represents the forecast error or residual error of the prediction at time t, while Q t represents

the variance of this prediction at time t.

For completeness, the rules are specified here:

1. e t < − √ Q t - Long the spread: Go long N shares of TLT and go short ⌊θt 0 N⌋ units of IEI

2. e t ≥ − √ Q t - Exit long: Close all long positions of TLT and IEI

3. e t > √ Q t - Short the spread: Go short N shares of TLT and go long ⌊θt 0 N⌋ units of IEI

4. e t ≤ √ Q t - Exit short: Close all short positions of TLT and IEI

The role of the Kalman filter is to help us calculate θ t , as well as e t and Q t . θ t represents

the vector of the intercept and slope values in the linear regression between TLT and IEI at

time t. It is estimated by the Kalman filter. The forecast error/residual e t = y t − ŷ t is the

difference between the value of TLT today and the Kalman filter’s estimate of TLT today. Q t is

the variance of the predictions and hence √ Q t is the standard deviation of the prediction.

For more detail on where these quantities arise please see the previous chapter on State Space

Models and the Kalman Filter.

The implementation of the strategy involves the following steps:

1. Receive daily market OHLCV bars for both TLT and IEI

2. Use the recursive "online" Kalman filter to estimate the price of TLT today based on

yesterdays observations of IEI

3. Take the difference between the Kalman estimate of TLT and the actual value, often called

the forecast error or residual error, which is a measure of how much the spread of TLT

and IEI moves away from its expected value

4. Long the spread when the movement is negatively far from the expected value and correspondingly

short the spread when the movement is positively far from the expected value

5. Exit the long and short positions when the series reverts to its expected value

28.1.1 Data

In order to carry out this strategy it is necessary to have OHLCV pricing data for the period

covered by this backtest. In particular it is necessary to download the following:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!