Code covered by the BSD License  

Highlights from
Cointegration and Pairs Trading with Econometrics Toolbox

4.3
4.3 | 10 ratings Rate this file 81 Downloads (last 30 days) File Size: 11.1 MB File ID: #31060 Version: 1.0
image thumbnail

Cointegration and Pairs Trading with Econometrics Toolbox

by

Stuart Kozola (view profile)

 

Demo files from the webinar of same title.

| Watch this File

File Information
Description

Files used in the April 14, 2011 webinar titled Cointegration and Pairs Trading with Econometrics Toolbox.

It is recomended that you watch the recording of the webinar: http://www.mathworks.com/videos/cointegration-and-pairs-trading-with-econometrics-toolbox-81799.html

Required Products Econometrics Toolbox
MATLAB release MATLAB 7.12 (R2011a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (37)
07 Dec 2014 Lfarin

Lfarin (view profile)

Folks, to create ODBC to connect to MSAccess u need go to Data Sources (ODBC) and Add in System DSN the path to database.

Comment only
09 Oct 2014 alessandro caserta

Good morning
i have two questions

1) What is this ratio? res / reg1.RMSE;

2) I do not understand what it does 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.

Comment only
27 May 2014 Koranit

Error in getMinuteDataFromDB (line 25)
e = fetch(e);

how to fix?

Comment only
13 May 2014 puqiao

puqiao (view profile)

I just look the title for interest, I thank you first here.

24 Apr 2014 EHSAN ramezanifar  
24 Apr 2014 EHSAN ramezanifar

It's good but not practical.

Comment only
24 Apr 2014 Koranit

how to download ??

Comment only
24 Apr 2014 Koranit

good !!

22 Jan 2014 Peter O

Demo1 works fine, but Demo2 is a non-starter. When I tried to run/evaluate the section "Load Intraday from a database" I get the following:

Undefined function 'setdbprefs' for input arguments of type 'struct'.

Error in getMinuteDataFromDB (line 17)
setdbprefs(s)

Running the whole demo at once gives me similar data issues. Any idea how to fix?

Comment only
18 Aug 2013 Stephen Wang

the quantity on y(:,1) should be -1/reg1.coeff(2)./s(i:i+N-1,2);

Comment only
18 Aug 2013 Stephen Wang

yea i think there is a look forward bias as well for generating the trading signal based on forward looking residuals predicted by egcitest.

30 May 2013 Mirko

Mirko (view profile)

Stuart, thanks for your contribution. It Looks to me that this is not able for real live trading because the "reg2" value "res" (of the egcitest) is changing its history with every new datapoint. If for example the res value at Bar 8 is -.9 for bar 7 the res value might be +0.8 for bar 7 at bar 20. Do you know a solution for this issue?

Comment only
10 May 2013 SteffenR88

is the file offline?
I have a problem with opening the file!

Comment only
10 May 2012 Peter Park

Hi,
Could you explain what does it mean if the date is 734548.554861111 in Access file? In other words, what is year,month,date,hour,minutes,second?
Thank you so much.

Comment only
19 Apr 2012 Carl Sutcliffe

Stuart, I am having problems with downloading the intra-day data from the access db. I receive the error "??? Undefined function or method 'getMinuteDataFromDB' for input arguments of type 'char'."
Is there anyway to fix this?

Comment only
13 Apr 2012 Fuzhi Cheng

I do not think there is a forward bias, but it indeed is a kind of curve-fitting based on historical data. I did simulated trading based on this strategy on a daily and intra-day basis, and it has been a losing one.

Comment only
07 Apr 2012 gill0055 yeremenko

Thats very very true Andy. It contains forward data contamination bias.

Comment only
06 Apr 2012 Andrew Baxter

Please be aware that this demo is not representative of what is achievable in reality. The demo has look ahead bias as it looks at future data to determine the trading signal to use on that data.

See pairs.m "Compute residuals over the next N days"

Comment only
06 Apr 2012 Semin Ibisevic  
21 Mar 2012 David Snaphaan

Dear Community,

I have the same problem as Lee in Aug 2011: ??? Undefined function or method 'fetch' for input arguments of type 'struct'.

Error in ==> getMinuteDataFromDB at 25
e = fetch(e);

Unfortunately the hint is no help for me. Do I have to change s.th. in the M-file?

Many Thanks,

Dave

Comment only
21 Mar 2012 Shichang

Fuad: Agree with you, should be -1/reg1.coeff(2)

Comment only
01 Mar 2012 Fuad

Fuad (view profile)

When calculating the trading ratio should the first leg qty be calculated as -1/reg1.coeff(2) instead of just -reg1.coeff(2)? Since the second leg is fixed at 1 we are effectively dividing through by the coeff of the second leg or have I miss interpreted the script... (This is in the pairs.m function)

Comment only
01 Mar 2012 Fuad

Fuad (view profile)

When calculating the trading ratio should the first leg qty be calculated as -1/reg1.coeff(2) instead of just -reg1.coeff(2)? Since the second leg is fixed at 1 we are effectively dividing through by the coeff of the second leg or have I miss interpreted the script...

16 Feb 2012 Mate 2u

Using demo 2, if I have second-second data from 2.30pm to 9pm what adjustments would need to be made to create and backtest a strategy?

Comment only
11 Jan 2012 faruto

faruto (view profile)

it's cooool~

26 Dec 2011 Jason

Jason (view profile)

for those who got this kind of error messages: "Error using ==> Lagmatrix at 25 lagmatrix: wrong # of input arguments," you must be using the MFEToolbox which calls in the lagmatrix function from the USCD toolbox. From R2011a or -b, Matlab has introduced a built-in function with the same name. That should be why.

Comment only
26 Oct 2011 Stuart Kozola

Stuart Kozola (view profile)

Data_Canada is in Econometrics Toolbox. You need a R2011a in order to run the demo.

Comment only
17 Oct 2011 Michael Nam

I am missing Data_Canada needed in Demo1_CIWebinar.m from the zip file.

Comment only
13 Sep 2011 lee

lee (view profile)

thank you,yes,now I know how to do;but I want to know there is someone use it to trade in futures markets,by .m to dll;I come from China,maybe someone can give me useful information,

Comment only
31 Aug 2011 Kittikorn Tongnimitsawat

When you down load files, you shall see MS Access file in a folder. This code will connect to this database.

Therefore you will have to create ODBC to connect to MSAccess.

Hope this helps.

Comment only
31 Aug 2011 lee

lee (view profile)

??? Undefined function or method 'fetch' for input arguments of type 'struct'.

Error in ==> getMinuteDataFromDB at 25
e = fetch(e);

help!help!help!
I don't know how to solve,anyone can help me,it would be greatly appreciated!!!

Comment only
14 Aug 2011 Suny Mou

Is it possible to see a format of the data file as I don't have the odbc download capability?

Comment only
15 Jul 2011 Cathal fLANAGAN

Guys, similar to Andy, i am getting the "Error using ==> Lagmatrix at 25 lagmatrix: wrong # of input arguments issue.....

Any ideas?

Comment only
24 Jun 2011 PAvlos Giannakopoulos  
16 Jun 2011 Andy

Andy (view profile)

I am having problems running the code for some reason. I get errors trying to run the egcitest(series). "Error using ==> Lagmatrix at 25 lagmatrix: wrong # of input arguments. If anyone could help, it would be greatly appreciated.

Comment only
08 Jun 2011 Fuzhi Cheng

Expecting to see the use of Johansen procedure in the determination of cointegrating relationship in a multiple-assets stat arb trading environment. The pairs trading part of the webinar still focused on two series and EG -- no big change from previous webinar.

29 Apr 2011 Lars

Lars (view profile)

Great contribution! This actually gave me the nugde to write a thesis about the subject. However, I struggle with accessing the odbc material on win7 x64, r2011a. I have spent too much time on troubleshooting now, I found some discussions online but never an resolution. I was hoping someone in here have had the same issue, and have resolved it. Thanks!

Contact us