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 trade finder from Yahoo Finance in C#
Submitter: vanna Date: 2011/2/1
Description:
This application loops over a list of symbols given in a file, and starts calculating cointegration statistic for pair combinations.


1. The left side window displays Downloads in progress
2.Center window displays cointegration calculations in progress
3. Rightmost window displays the top 50 pairs selected so far. It is updated by a timer every 10 seconds, and is sorted by pvalue.


Prerequisite
1. Setup MySQL server, and ADO .NET connector. If you have not setup yet, please see http://www.quantcode.com/modules/smartfaq/faq.php?faqid=100
2. Install schema for the tables from http://www.quantcode.com/modules/docmanager/view_file.php?curent_file=395&curent_dir=19

If you are interested in looking at graph of the spread:
1. Download .csv files for the symbols using this link (change symbol name):
http://ichart.finance.yahoo.com/table.csv?s=AAV&d=0&e=22&f=2011&g=d&a=0&b=2&c=2005&ignore=.csv
2. Feed input files to http://www.quantcode.com/modules/mydownloads/singlefile.php?cid=15&lid=579 , and use sliders to scroll across the training data set. Remember to click on check box for Show graph when hitting the calculate button

will add more details as I get time..

Got a question or problem with this link? Just enter your message and click on submit. No registration is required.

Note: A copy of this message will also be emailed to the submitter of this link
Downloaded 826 times  826  File Size 0 bytes  Supported Platforms C# .NET WPF MySQL  Home Page http://www.quantcode.com/
Rating: 0.00 (0 votes)
Rate this File | Modify | Delete | Report Broken File | Tell a Friend | Comments (31)

Poster Thread
Anonymous
Posted: 2011/2/3 21:41  Updated: 2011/2/3 21:41
 Pairs trade finder from Yahoo Finance in C#
I tried building this application but received the following error. Any help would be greatly appreciated.

System.Windows.Markup.XamlParseException was unhandled
Message="Cannot create instance of 'Window1' defined in assembly 'yahootest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation. Error in markup file 'Window1.xaml'."
Source="PresentationFramework"
LineNumber=0
LinePosition=0
StackTrace:
at System.Windows.Markup.XamlParseException.ThrowException(String message, Exception innerException, Int32 lineNumber, Int32 linePosition, Uri baseUri, XamlObjectIds currentXamlObjectIds, XamlObjectIds contextXamlObjectIds, Type objectType)
at System.Windows.Markup.XamlParseException.ThrowException(ParserContext parserContext, Int32 lineNumber, Int32 linePosition, String message, Exception innerException)
at System.Windows.Markup.BamlRecordReader.ThrowExceptionWithLine(String message, Exception innerException)
at System.Windows.Markup.BamlRecordReader.CreateInstanceFromType(Type type, Int16 typeId, Boolean throwOnFail)
at System.Windows.Markup.BamlRecordReader.GetElementAndFlags(BamlElementStartRecord bamlElementStartRecord, Object& element, ReaderFlags& flags, Type& delayCreatedType, Int16& delayCreatedTypeId)
at System.Windows.Markup.BamlRecordReader.BaseReadElementStartRecord(BamlElementStartRecord bamlElementRecord)
at System.Windows.Markup.BamlRecordReader.ReadElementStartRecord(BamlElementStartRecord bamlElementRecord)
at System.Windows.Markup.BamlRecordReader.ReadRecord(BamlRecord bamlRecord)
at System.Windows.Markup.BamlRecordReader.Read(Boolean singleRecord)
at System.Windows.Markup.TreeBuilderBamlTranslator.ParseFragment()
at System.Windows.Markup.TreeBuilder.Parse()
at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
at System.Windows.Application.LoadBamlStreamWithSyncInfo(Stream stream, ParserContext pc)
at System.Windows.Application.LoadComponent(Uri resourceLocator, Boolean bSkipJournaledProperties)
at System.Windows.Application.DoStartup()
at System.Windows.Application.<.ctor>b__0(Object unused)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.Run()
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at System.Windows.Application.Run()
at yahootest.App.Main() in C:\Documents and Settings\Mike\Desktop\yahootest\yahootest\obj\Release\App.g.cs:line 0
InnerException: System.Reflection.TargetInvocationException
Message="Exception has been thrown by the target of an invocation."
Source="mscorlib"
StackTrace:
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Windows.Markup.BamlRecordReader.CreateInstanceFromType(Type type, Int16 typeId, Boolean throwOnFail)
InnerException: MySql.Data.MySqlClient.MySqlException
Message="Unable to connect to any of the specified MySQL hosts."
Source="MySql.Data"
ErrorCode=-2147467259
Number=1042
StackTrace:
at MySql.Data.MySqlClient.NativeDriver.Open()
at MySql.Data.MySqlClient.Driver.Open()
at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection()
at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
at MySql.Data.MySqlClient.MySqlPool.GetConnection()
at MySql.Data.MySqlClient.MySqlConnection.Open()
at yahootest.Window1..ctor() in C:\Documents and Settings\Mike\Desktop\yahootest\yahootest\Window1.xaml.cs:line 45
InnerException: System.ArgumentException
Message="Invalid handle.\r\nParameter name: handle"
Source="mscorlib"
ParamName="handle"
StackTrace:
at System.IO.FileStream..ctor(SafeFileHandle handle, FileAccess access, Int32 bufferSize, Boolean isAsync)
at MySql.Data.Common.NamedPipeStream.Open(String path, FileAccess mode, UInt32 timeout)
at MySql.Data.Common.NamedPipeStream..ctor(String path, FileAccess mode, UInt32 timeout)
at MySql.Data.Common.NamedPipeStream.Create(String pipeName, String hostname, UInt32 timeout)
at MySql.Data.Common.StreamCreator.GetStream(UInt32 timeout)
at MySql.Data.MySqlClient.NativeDriver.Open()
InnerException:

Poster Thread
Anonymous
Posted: 2011/2/4 0:48  Updated: 2011/2/4 0:48
 Pairs trade finder from Yahoo Finance in C#
Hi,
Thanks for your feedback. I am guessing it is an error in database connection.
Can you please change this line in file Window1.xaml.cs:
"static string _connstr = "User ID=root; Protocol=pipe; Password=mypassword;Host=localhost;Database=test;";"
"mypassword" will need to be replaced with h your chosen password during MySql installation, and "test" database with the name of your chosen database.
Please let me know if you still find issue.
A note : There is a memory leak during cointegration check, and application was getting killed after 5 minutes. Hence I have a timer which restarts the application after every 1 min. (It is a temporary fix, I think I have found the cause and will post the fix in a few days.)
Thanks for using QuantCode - vanna

Poster Thread
Anonymous
Posted: 2011/2/4 15:23  Updated: 2011/2/4 15:46
 Pairs trade finder from Yahoo Finance in C#
Replaced "mypassword" as requested. I assume that the database to be referenced is the file from step 2 above: 2. Install schema for the tables from http://www.quantcode.com/modules/docmanager/view_file.php?curent_file=395&curent_dir=19
Is this correct? Or am I missing a step?

Poster Thread
Anonymous
Posted: 2011/2/4 15:54  Updated: 2011/2/4 15:54
 Pairs trade finder from Yahoo Finance in C#
I think I had hard coded databasename in the filw to "test", eg., I was referencing test.dailydata. my bad!
Can you please either of the below :
1. Create a databse called "test", and install the script in that database.
2. If you have already installed it in you rdatabase, please change "test.dailydata" (similarly for other tables) to your datbasename eg., "mydbname.dailydata"
Sorry for the trouble.
Regards - vanna

Poster Thread
Anonymous
Posted: 2011/2/4 15:55  Updated: 2011/2/4 15:55
 Pairs trade finder from Yahoo Finance in C#
The file link you have given is correct - vanna

Poster Thread
Anonymous
Posted: 2011/2/5 21:28  Updated: 2011/2/5 21:28
 Pairs trade finder from Yahoo Finance in C#
I am struggling to figure out how to use MySql more than anything...not sure how to create the database

Poster Thread
vanna
Posted: 2011/2/5 22:15  Updated: 2011/2/5 22:41
Just can't stay away
Joined: 2007/3/21
From:
Posts: 104
 Re: Pairs trade finder from Yahoo Finance in C#
Step 1:
Open SQL workbench and click on Local host




Step 2:
Click on "Create new schema button" and create it with name "test" (as per terminology, schema is a database in MySql)




Step 3:
Select default schema as "test", and then copy paste text from script file in pairsdb.sql. Then click on execute button



Poster Thread
Anonymous
Posted: 2011/2/5 22:07  Updated: 2011/2/5 22:07
 Pairs trade finder from Yahoo Finance in C#
is it local connection, i.e., did you use pipe or tcp/ip ? pipe is much simpler.

Poster Thread
Anonymous
Posted: 2011/4/5 12:50  Updated: 2011/4/5 12:50
 Pairs trade finder from Yahoo Finance in C#
I set the proper database name and password and still get the "Message="Cannot create instance of 'Window1' defined in assembly 'yahootest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation." issue. What can I do to resolve this?

Poster Thread
Anonymous
Posted: 2011/4/5 12:55  Updated: 2011/4/5 12:55
 Pairs trade finder from Yahoo Finance in C#
More info:

System.Windows.Markup.XamlParseException was unhandled
Message="Cannot create instance of 'Window1' defined in assembly 'yahootest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation. Error in markup file 'Window1.xaml' Line 1 Position 9."
Source="PresentationFramework"
LineNumber=1
LinePosition=9
StackTrace:
at System.Windows.Markup.XamlParseException.ThrowException(String message, Exception innerException, Int32 lineNumber, Int32 linePosition, Uri baseUri, XamlObjectIds currentXamlObjectIds, XamlObjectIds contextXamlObjectIds, Type objectType)
at System.Windows.Markup.XamlParseException.ThrowException(ParserContext parserContext, Int32 lineNumber, Int32 linePosition, String message, Exception innerException)
at System.Windows.Markup.BamlRecordReader.ThrowExceptionWithLine(String message, Exception innerException)
at System.Windows.Markup.BamlRecordReader.CreateInstanceFromType(Type type, Int16 typeId, Boolean throwOnFail)
at System.Windows.Markup.BamlRecordReader.GetElementAndFlags(BamlElementStartRecord bamlElementStartRecord, Object& element, ReaderFlags& flags, Type& delayCreatedType, Int16& delayCreatedTypeId)
at System.Windows.Markup.BamlRecordReader.BaseReadElementStartRecord(BamlElementStartRecord bamlElementRecord)
at System.Windows.Markup.BamlRecordReader.ReadElementStartRecord(BamlElementStartRecord bamlElementRecord)
at System.Windows.Markup.BamlRecordReader.ReadRecord(BamlRecord bamlRecord)
at System.Windows.Markup.BamlRecordReader.Read(Boolean singleRecord)
at System.Windows.Markup.TreeBuilderBamlTranslator.ParseFragment()
at System.Windows.Markup.TreeBuilder.Parse()
at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
at System.Windows.Application.LoadBamlStreamWithSyncInfo(Stream stream, ParserContext pc)
at System.Windows.Application.LoadComponent(Uri resourceLocator, Boolean bSkipJournaledProperties)
at System.Windows.Application.DoStartup()
at System.Windows.Application.<.ctor>b__0(Object unused)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler)
at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter)
at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.Run()
at System.Windows.Application.RunDispatcher(Object ignore)
at System.Windows.Application.RunInternal(Window window)
at System.Windows.Application.Run(Window window)
at System.Windows.Application.Run()
at yahootest.App.Main() in C:\downloads\yahootest\obj\Debug\App.g.cs:line 0
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: System.Reflection.TargetInvocationException
Message="Exception has been thrown by the target of an invocation."
Source="mscorlib"
StackTrace:
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Windows.Markup.BamlRecordReader.CreateInstanceFromType(Type type, Int16 typeId, Boolean throwOnFail)
InnerException: MySql.Data.MySqlClient.MySqlException
Message="Unable to connect to any of the specified MySQL hosts."
Source="MySql.Data"
ErrorCode=-2147467259
Number=1042
StackTrace:
at MySql.Data.MySqlClient.NativeDriver.Open()
at MySql.Data.MySqlClient.Driver.Open()
at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection()
at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
at MySql.Data.MySqlClient.MySqlPool.GetConnection()
at MySql.Data.MySqlClient.MySqlConnection.Open()
at yahootest.Window1..ctor() in C:\downloads\yahootest\Window1.xaml.cs:line 45
InnerException: System.ArgumentException
Message="Invalid handle.\r\nParameter name: handle"
Source="mscorlib"
ParamName="handle"
StackTrace:
at System.IO.FileStream..ctor(SafeFileHandle handle, FileAccess access, Int32 bufferSize, Boolean isAsync)
at MySql.Data.Common.NamedPipeStream.Open(String path, FileAccess mode, UInt32 timeout)
at MySql.Data.Common.NamedPipeStream..ctor(String path, FileAccess mode, UInt32 timeout)
at MySql.Data.Common.NamedPipeStream.Create(String pipeName, String hostname, UInt32 timeout)
at MySql.Data.Common.StreamCreator.GetStream(UInt32 timeout)
at MySql.Data.MySqlClient.NativeDriver.Open()
InnerException:

Poster Thread
Anonymous
Posted: 2012/1/30 12:08  Updated: 2012/1/30 21:05
 Pairs trade finder from Yahoo Finance in C#
Your zip file does not appear to include the lib_gsl_d.dll or libgslcblas_d.dll. I found those libraries elsewhere. When I try to run the program, it crashes inside DoMultiParameterFit with the message: "A call to PInvoke function 'yahootest!yahootest.GSL::gsl_vector_alloc' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature."

Poster Thread
Anonymous
Posted: 2012/2/24 1:53  Updated: 2012/3/18 11:08
 Pairs trade finder from Yahoo Finance in C#
I downloaded your 64-bit gsl library to replace the 32-bit, but the problem of "A call to PInvoke function 'yahootest!yahootest.GSL::gsl_vector_alloc' has unbalanced " Still exist...how can this be solved? thanks

Poster Thread
Anonymous
Posted: 2012/2/24 2:55  Updated: 2012/3/18 11:08
 Pairs trade finder from Yahoo Finance in C#
i also having this problem, how can this be solved?

Poster Thread
Anonymous
Posted: 2012/3/22 11:21  Updated: 2012/5/6 19:24
 Pairs trade finder from Yahoo Finance in C#
Will this run in XP64 with Excel 2007 & MYSQL Server 5.1 & MYSQL Workbench 5.2 CE?
Is the code available?
It appears, for each equity, the entire file is downloaded rather than updated. For a few equities, this is ok, but for hundreds it does not seem practical.
In your snapshot, it appears you have many stocks; how many were there and how long did the entire run take?
What are the parameters? Can they be modified?
Where are the list of stocks defined; I’d prefer to analyze several small groups rather than the entire collection against itself. How can this be done?

Poster Thread
Anonymous
Posted: 2012/3/30 1:23  Updated: 2012/5/6 19:24
 Pairs trade finder from Yahoo Finance in C#
It works if you switch the target framework to .NET Framework 3.5.

Discuss this file. Just enter your message and click on submit. No registration is required.
Similar Links:

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