FinMath:Data

From FinMath

Jump to: navigation, search

The following allows for capturing real-time data from Interactive Brokers [1] trading software, Traders Workstation. Interactive Brokers provides free real-time data feeds that can be captured, analyzed and then used for trade recommendations. (The feed is free if you have an active brokerage account and process a minimum number of trades per month, otherwise there is a nominal charge if your account balance is below a certain level, see Interactive Brokers for details.)

For most real-time trading efforts you will need to populate the database with historic data. In upcoming versions, this Java code will have utilities that allow you to populate the database with historic data from a flat file or from an excel spread sheet. Clean, reasonably priced historical tick data (for futures, equity, options, ...) can be purchased from Tick Data.

In addition, upcoming versions of the software will automatically send trades to and receive confirmations from Interactive Brokers.


Capturing data from Interactive Brokers into a database

[edit] Setup


1.Install NetBeans for Java (6.0.1)[2]

2.Verify that you had an installation of Java SE with the NetBeans installation. If you did not get the installation with NetBeans you must install.[3]

3.Install JavaDB (Derby Database) [4]

4.Once you have the basic installation ensure the following environment variables are set in the System Settings:

       DERBY_HOME=C:\Program Files\Java\SDK\javadb ; Where the JavaDB is installed
       DERBY_INSTALL=C:\Program Files\Java\SDK\javadb; Where the JavaDB is installed
       JAVA_HOME =C:\Program Files\Java\SDK\jdk; Where the Java is installed
       PATH=%PATH%;C:\Program Files\Java\SDK\bin
       CLASSPATH=%CLASSPATH%;C:\PROGRA~1\Java\SDK\javadb\lib\derby.jar;C:\PROGRA~1\Java\SDK\javadb\lib\derbytools.jar;

5.Install InteractiveBrokers. [5]

       Use the demo login: edemo and passwd:demouser

6.Install the DB2Client from IBM. [6]. Skip this step if you don't want to extract data from the database to Microsoft Excel.If you need support for Microsoft Excel or other ODBC based clients. Then you must install the following to get an ODBC Driver. This installation can give users a significant ease in accessing the database and analyzing data on need basis or to run test programs. This can also give the users (developers access to writing to the database using C++ clients).


[edit] Development

Start NetBeans and Create a Project add the following files to the Project: 1.QTApplication 2.QTDBManager 3.QTLoginFrame 4.QTSubOrder 5.QTSubContract 6.QTWrapper


[edit] Interactive Brokers and Matlab

You can also connect directly Matlab and Interactive Brokers in order to get real time quotes, and pass automated orders. See http://www.matlabtrader.com for details.


Here is a short description how to do this :

Go to interactive brokers website.

1/ Download "Trader Workstation" on your computer and install it.

2/ Download the "Proprietary API" on your computer and install it. Look at the directory where it is installed (c:\jts by default).

3/ Open a Command Window in windows: Star Menu > Run > cmd. Type : regsrv32 "c:\directory_of_IB_api\activex\tws.ocx" (you can also drag & drop the tws.ocx to regsrv32 file (hidden in c:\windows\system32)


4/ Launch the Trader Workstation with your login/password of the paper account. Go to configure > API > check the ActiveX option.

5/ Download "IBevent.m" and "IBapi_examples.m" and put them in MATLAB working directory.

6/ Launch Matlab. Change the working direcory to the directory where you have stored "IBevent.m" and "IBapi_examples.m"

7/ Launch the "IBapi_examples.m" first lines :

global eventdata ordernumber eventdata = {};

f = figure; set(f,'Visible','off'); ib = actxcontrol('TWS.TwsCtrl.1',[0 0 50 50],f); ib.connect(, 7496, 2);

% Select which function will handle the events. ib.registerevent('IBevent');

8/ IB is going to ask you if you want to accept incoming connections. Say yes.


... then, you can execute commands detailed in the API of Interactive Brokers.




Source of information in case of problems :

- IP api: http://individuals.interactivebrokers.com/en/p.php?f=programInterface&ib_entity=llc

- matlab & ib: http://www.matlabtrader.com/index.php?project=InteractiveBrokers There is also a forum on IB & MATLAB where you can ask questions: http://www.matlabtrader.com/forum/

- Google on how to register a dll in windows (regsrv32 stuff)


- other API: http://www.trade-commander.org/twslink/twslink.htm

- other API: http://code.google.com/p/jsystemtrader/

- Java & MATLAB: http://math.carleton.ca/old/help/matlab/MathWorks_R13Doc/techdoc/matlab_external/ch_java.html



ADDENDUM:


It seems it works also without opening an account, just with the demo on interactive brokers website.

Do not execute steps 1/ and 4/.

Instead execute steps 2/ and 3/ then go to interactive brokers website. Go to Software > Trader Workstation > Demo. Launch Individual Demo. This should open the trader workstation software. Go to Configure > Global configuration > API change the socket port to 7496 and verify that the Enable ActiveX option is checked. These are not realtime prices by the way.

Execute steps 5/ 6/ and 7/

Personal tools