I have a question about pairs trading
Show older comments
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
Bruno Pop-Stefanov
on 8 Oct 2014
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.
alessandro caserta
on 9 Oct 2014
Bruno Pop-Stefanov
on 10 Oct 2014
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.
alessandro caserta
on 11 Oct 2014
alessandro caserta
on 16 Oct 2014
Answers (0)
Categories
Find more on Cointegration Analysis in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!