I have a question about pairs trading

Good Morning I watched the pairs trading webminar. I would like to ask if anyone can give me some information about the operation of certain parts of the code.
Is regression implemented in this part?
% The strategy:
% 1 Compute residuals over next N days
res = series2 (i: i + N-1, 1) ...
- (Reg1.coeff (1) + reg1.coeff (2). * Series2 (i: i + N-1, 2));
-------------------------------------------------- -----------------------------------
I am also not clear about this part:
% 2 If the residuals are large and positive, then the first series
% Is Likely to decline vs. the second series. Short the first
% Series by a scaled number of shares and long the second series by
1% share. If the residuals are large and negative, do the
% Opposite.
indicated (i: i + N-1) = res / reg1.RMSE;
s (i: i + N-1, 2) = (res / reg1.RMSE> spread) ...
- (Res / reg1.RMSE <-spread);
s (i: i + N-1, 1) = -reg1.coeff (2). * s (i: i + N-1, 2);
end
end
Thank you for your concern and time. Best regards, Caserta

5 Comments

When computing the residuals, regression statistics (struct reg1) are computed by doing the cointegration regression with the egcitest function. So, yes, regression is used and computed at line 49 of pairs.m.
As for the second part, this is explained by the comment. s is the output trading signal returned by the pairs function. The signal will be short one series and long the other (or do the opposite) based on which residuals are the largest.
Thank you very much for your answer
However, I'm sorry to bother you again but I would like to know if you can help me on these questions
res = series2 (i: i + N-1, 1) - (reg1.coeff (1) + reg1.coeff (2). * series2 (i: i + N-1, 2));
1) why do we use this part? (reg1.coeff (1) + reg1.coeff (2). * series2 (i: i + N-1, 2)); ? What is?
2) What is this retio ? res / reg1.RMSE;
3) I do not understand what this piece of code: s (i: i + N-1, 1) = -reg1.coeff (2). * s (i: i + N-1, 2);
Thank you very much for your time and for your cooperation.
Alessandro,
I am not familiar with the code and my background is not in economics or finance but here is what I understand about the code:
1) If cointegration is inferred, reg1 contains regression statistics that can model the series. Line 56 of pairs.m computes the residuals of the regression: we take the difference between the first series and the cointegrated second series.
2) RMSE is the root mean squared error. On this line the residuals are normalized by the standard deviation so that we can compare the residuals to the spread.
3) This is the opposite signal of lines 66-67.
Sorry I cannot help you more. You might want to post a message on the File Exchange submission and ask the author directly. He will know his code more than I do.
thank you very much for all your invaluable help.
Good morning
I ask you another little help.
I can not understand how they are calculated returns in this part of the code.
s (i: i + N-1, 1) = -reg1.coeff (2). * s (i: i + N-1, 2);
return = sum ([0 0; s (1: end-1, : ). * diff (series2) - abs (diff (s)) * cost / 2], 2);
the prices of the series that I have to examine must be standardized ?
thank you so much for your time and cooperation regards

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!