File Exchange

image thumbnail

Cointegration and Pairs Trading with Econometrics Toolbox

version 1.0.0.1 (11.1 MB) by Stuart Kozola
Demo files from the webinar of same title.

21 Downloads

Updated 01 Sep 2016

View License

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

Comments and Ratings (41)

Cihan Ulas

Hi Guys, did you solved the problem in getMinuteDataFromDB.m? I have this:
Error in getMinuteDataFromDB (line 17)
setdbprefs(s)
If I cancel it out and runt the function I get 0 as result....I proved with different DB but always the same.

Thank you for any answer

polar

could someone please describe how to get Demo2 work? I'm fed up with all these webinars that don't make users able to make them run. Thanks

li li

very good

Lfarin

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

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.

Koranit

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

how to fix?

puqiao

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

It's good but not practical.

Koranit

how to download ??

Koranit

good !!

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?

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

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

Mirko

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?

SteffenR88

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

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.

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?

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.

gill0055

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

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"

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

Shichang

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

Fuad

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)

Fuad

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...

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?

faruto

it's cooool~

Jason

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.

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

Michael Nam

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

lee

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,

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.

lee

??? 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!!!

Suny Mou

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

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

Any ideas?

Andy

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.

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.

Lars

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!

Updates

1.0.0.1

Updated license

MATLAB Release Compatibility
Created with R2011a
Compatible with any release
Platform Compatibility
Windows macOS Linux