Directory of Open Source for Quantitative Finance and Trading
Username: Password: Not registered?
 
Quick Search:    (AJAX based: No need to press button)

Main : .NET : 


Category: .NET View Full Details
Download Now!Pairs trading application in C#
Submitter: vanna Date: 2011/2/10
Description:


To directly run the application without building the source code, please see http://www.quantcode.com/modules/mydownloads/singlefile.php?cid=15&lid=591

PS : GSL binaries are built on and will work only on 32bit. I will create a seperate folder for 64 bit later.


This application can be used for back testing pairs trading strategies using historical stock prices downloaded from Yahoo finance. It is based on WPF, and utilizes infrastructure of Tradelink library to do PL calculations.

Prerequisites:
1.Install WPF toolkit from http://wpf.codeplex.com/

Some FAQs:

How do I get to build and run the code?
1. Create a folder C:\Download.
2. Unzip attached download file and copy folder tratest1 into C:\downloads
3. Open project in Visual C# 2008 and build the application.

What is the green/red color box?
It is an indication of the confidence level of stationarity of the spread between the 2 stock prices. The series is obtained from log A - log B , as mentioned in (17) of paper http://www.yats.com/doc/cointegration-en.pdf pvalue reesult of augment dickey fuller test is used for interpolating green and red values.

How do I say if the pair can be profitable?
Keep moving the sliders for begin train time/ End training time. If it is green throughout the movements, the spread has been stationary during the entire history. It is thus more likely to be so in the near future.

What is the graph?
When checkbox for Show Graph is checked, and then calculate button is clicked, graph of spread will be shown of the training data, along with the follwing lines:
mean spread
mean +/- (upper threashold) * stddev
mean +/- (lower threashold) * stddev

If you find issues, please post your message in :
http://www.quantcode.com/modules/newbb/viewtopic.php?topic_id=315&post_id=593&order=0&viewmode=thread&pid=0&forum=1#forumpost593

If you are interested in learning more about doing charts in WPF, please see these links:
http://msdn.microsoft.com/en-us/library/dd456632.aspx
http://msdn.microsoft.com/en-us/library/system.windows.forms.datavisualization.charting.aspx
Downloaded 1989 times  1989  File Size 0 bytes  Supported Platforms C# .WPF NET Tradelink  Home Page http://www.quantcode.com/
Rating: 0.00 (0 votes)
Rate this File | Modify | Delete | Report Broken File | Tell a Friend | Comments (403)

Poster Thread
Anonymous
Posted: 2011/1/22 22:20  Updated: 2011/1/22 22:20
 C# GUI application for testing pairs trading strategies from Yahoo Finance
I am wondering about the cointegration code you made for C#.

Is it only using ADF? Is that a correct method for determining cointegration? I thought ADF was just a first step in for example using the Engle&Granger method for detemine cointegration, and that ADF in itself is not enough?

Could you please shine some light on this?

Regards,

Carl

Poster Thread
Anonymous
Posted: 2011/1/22 22:25  Updated: 2011/1/22 22:26
 C# GUI application for testing pairs trading strategies from Yahoo Finance
Thanks for your feedback. ADF is a test for stationarity of a time series. Cointegration of a pair happens when their ratio is stationary, hence ADF test on Log A - log B is used to determine whether 2 series are staionary. (this is mentioned in mentioned in (17) of paper http://www.yats.com/doc/cointegration-en.pdf)
There is however a limitation with ADF test. ADF test on logA-logB could a different result that logB-logA. Hence Joahansen's test is preferred to ADF test since it does not suffer from this pitfall.

vanna

Poster Thread
Anonymous
Posted: 2011/1/22 22:27  Updated: 2011/1/22 22:27
 C# GUI application for testing pairs trading strategies from Yahoo Finance
Ok, thanks I see. Do you have any experience on Engle-Grange?

Do you have any plans of writing Johansens test in C++ or C#?

I don't have the ability to do it myself although I have some experience in programming some simple trading systems. I am very interested in pair trading cointegrated pairs.

Do you trade yourself or do you only concentrate on programming and "quant stuff"

Regards,

Carl

Poster Thread
Anonymous
Posted: 2011/1/23 12:22  Updated: 2011/1/23 12:22
 C# GUI application for testing pairs trading strategies from Yahoo Finance
Hi,

I have two follow up questions to your answer.

What is the way of choosing lag order for the cointegration test? On my opinion I should compute the results with many possible lag orders for both "A and B" and "B and A" and then take the lowest p-value?

Regards,

Carl

Poster Thread
Anonymous
Posted: 2011/1/23 12:24  Updated: 2011/1/23 12:24
 C# GUI application for testing pairs trading strategies from Yahoo Finance
Hi Carl,
I assume you mean ADF test? It is an optimal lag order based on sample size.

-vanna

Poster Thread
Anonymous
Posted: 2011/1/24 11:03  Updated: 2011/1/24 11:03
 C# GUI application for testing pairs trading strategies from Yahoo Finance
I want to make use of option prices to formulate my strategy, and thinking if it would make sense to prefer the pair which has high implied volatities on the 1 year option for both the stocks. Asuming that implied volatility is a decent predictor of realized volatiltiy, it would mean that there will be many times that the spread would cross the threashold boundaries, and I could cash in. I would appreciate if someone has done a similar research and share his experience.

Poster Thread
Anonymous
Posted: 2011/1/24 13:18  Updated: 2011/1/24 13:18
 C# GUI application for testing pairs trading strategies from Yahoo Finance
Hi Carl,
I think you are right that the p-value statistic is not accurate when we use ADF testing on residual of log(A)-log(B). This is because ADF test assumes original series, but our input is a residual. Engle and Yo have computed a set of different statistics which use residuals as an input. In that case, the ADF test is same but the zSurface of DF statistic and p-value lookup will be different. I cannot get a hold of their table. Can someone be kind enough to post it?
- vanna


Poster Thread
Anonymous
Posted: 2011/1/24 13:19  Updated: 2011/1/24 13:19
 C# GUI application for testing pairs trading strategies from Yahoo Finance
PS : Keep the critical and all feedback coming. Thanks in advance
-vanna

Poster Thread
Anonymous
Posted: 2011/1/24 13:42  Updated: 2011/1/24 13:42
 C# GUI application for testing pairs trading strategies from Yahoo Finance
I am interested in using Johansen's procedure, but can't find anything which explains how to construct portfolio. Do I need to do a multiple linear regression on the stocks, or just pick up the best pairs and do a simple linear regresion?

Ramesh Iyer,
Infosys International, Banagalore


Poster Thread
Anonymous
Posted: 2011/1/24 14:22  Updated: 2011/1/24 14:22
 C# GUI application for testing pairs trading strategies from Yahoo Finance
how does one achieve diversification in pairs trading? an article link will be highly appreciated.
Bob

Poster Thread
Anonymous
Posted: 2011/1/24 14:41  Updated: 2011/1/24 14:41
 C# GUI application for testing pairs trading strategies from Yahoo Finance
pairs trading has been fully exploited. worked a decade ago, is no longer profitable in my opinion.

Poster Thread
Anonymous
Posted: 2011/1/24 17:20  Updated: 2011/1/24 17:20
 C# GUI application for testing pairs trading strategies from Yahoo Finance
When we do ADF testing on the residuals, will it matter whether we use as input the residuals from
a) log S1 - log S2
b) log S1 - beta* log S2

Gabriel

Poster Thread
Anonymous
Posted: 2011/1/24 17:22  Updated: 2011/1/24 17:22
 C# GUI application for testing pairs trading strategies from Yahoo Finance
Reason I am asking this, if we choose b) we would be closer to the actual execution strategy
Gabriel

PS : I could not find option to edit my earlier message..

Poster Thread
Anonymous
Posted: 2011/1/26 13:18  Updated: 2011/1/26 13:18
 Pairs trading application in C#
There are many views on what is ideal approach to do cointegration testing - use ADF test with DF statistics, Engle Yo surface, Johansonen method, etc.
After getting my hands wet with playing around the data, I feel that choosing one approach over other does not differ very much. The biggest headache however is that stationarity is not consistent over the rollover. Any ideas on how to overcome this?
cruizerfish

Poster Thread
Anonymous
Posted: 2011/1/26 13:32  Updated: 2011/1/26 13:32
 Pairs trading application in C#
Hi, I am a trader and highly interested in trying your application.
I would recommend adding these features if possible - search factors such as rising/decreasing pair RSI, rising/decreasing price ratio, and other factors of doing technical analysis on individual stocks. - waltbx

Poster Thread
Anonymous
Posted: 2011/1/26 20:47  Updated: 2011/1/26 20:47
 Pairs trading application in C#
Did someone try GLD-GDX and USO-OIL ?

Poster Thread
Anonymous
Posted: 2011/2/3 19:37  Updated: 2011/2/3 19:37
 Pairs trading application in C#
Thanks for the WPF chart reference link vanna, this is what I was looking for

Poster Thread
Anonymous
Posted: 2011/2/4 3:26  Updated: 2011/2/4 3:26
 Pairs trading application in C#
FYI, I have updated it to add online yahoo quotes query

Poster Thread
Anonymous
Posted: 2011/2/4 11:01  Updated: 2011/2/4 11:01
 Pairs trading application in C#
I am getting this error in my Vista PC (it is working fine in my other PC whcih has Windows XP)

Description:
Stopped working

Problem signature:
Problem Event Name: CLR20r3
Problem Signature 01: tradtest1.exe
Problem Signature 02: 1.0.0.0
Problem Signature 03: 4d4bb4b3
Problem Signature 04: tradtest1
Problem Signature 05: 1.0.0.0
Problem Signature 06: 4d4bb4b3
Problem Signature 07: 71
Problem Signature 08: f
Problem Signature 09: System.BadImageFormatException
OS Version: 6.0.6002.2.2.0.768.3
Locale ID: 1033

Poster Thread
Anonymous
Posted: 2011/2/4 11:05  Updated: 2011/2/4 11:05
 Pairs trading application in C#
yeah, it errors out on 64bit PC. I still have to figure out how to conditionally deploy in clickonce. (it is happending becuase the libgsl_d.dll is built for 32bit arch, while Vista is mostly 64bit)
-vanna

Poster Thread
Anonymous
Posted: 2011/3/30 17:45  Updated: 2011/3/30 17:45
 Pairs trading application in C#
when I try to build the file there are 20 some errors? I don't know what I am doing wrong.

Poster Thread
Anonymous
Posted: 2011/3/30 18:12  Updated: 2011/3/30 18:12
 Pairs trading application in C#
can you copy paste your first few errors?

Poster Thread
Anonymous
Posted: 2011/12/12 18:00  Updated: 2012/1/28 18:41
 Pairs trading application in C#
You mentioned the 64-bit library of the GSL binaries. Is there a link to those somewhere?

Poster Thread
Anonymous
Posted: 2011/12/15 9:11  Updated: 2012/1/28 18:41
 Pairs trading application in C#
Im running the ADF test multiple times in a loop and it is causing serious memory leaks. The seems to occur when hitting the GSLClass.

Poster Thread
Anonymous
Posted: 2012/1/8 9:14  Updated: 2012/1/28 18:41
 Pairs trading application in C#
realy good work;)

Poster Thread
Anonymous
Posted: 2012/2/7 6:57  Updated: 2012/3/18 11:14
 Pairs trading application in C#
Hi, I am tring to build your project using VS2010 and a new download of the TradeLink libraries. I am getting Error: Cannot implicitly convert type 'TradeLink.API.OrderDelegate' to 'TradeLink.API.OrderSourceDelegate'. I see you have a line commented out above using OrderSourceDelegate instead of OrderDelegate, but it seems they may have changed the method, as I get Error: No overload for 'b_SendOrder' matches delegate 'TradeLink.API.OrderSourceDelegate' if I try to change it. Have you run into this/any ideas? Thanks.

Poster Thread
Anonymous
Posted: 2012/4/26 15:32  Updated: 2012/5/6 19:16
 Pairs trading application in C#
Please fix the 64bit problem! I am really looking forward to using this :)

-Vanna you kick some ass!

Poster Thread
Anonymous
Posted: 2013/1/3 5:16  Updated: 2013/2/10 12:50
 Pairs trading application in C#
I have win7 64bit and installed visual studio 8
48 errors
most of them "type or namespace name ___________could not be found(are you missing a using directive or an assembly reference?)"
Similar Links:

Subscribe to RSS or daily email updates of latest quantitative finance code listings
Email address :
Copyright 2011 QuantCode Inc. All rights reserved.