By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
SmartData Collective
  • Analytics
    AnalyticsShow More
    data analytics in sports industry
    Here’s How Data Analytics In Sports Is Changing The Game
    6 Min Read
    data analytics on nursing career
    Advances in Data Analytics Are Rapidly Transforming Nursing
    8 Min Read
    data analytics reveals the benefits of MBA
    Data Analytics Technology Proves Benefits of an MBA
    9 Min Read
    data-driven image seo
    Data Analytics Helps Marketers Substantially Boost Image SEO
    8 Min Read
    construction analytics
    5 Benefits of Analytics to Manage Commercial Construction
    5 Min Read
  • Big Data
  • BI
  • Exclusive
  • IT
  • Marketing
  • Software
Search
© 2008-23 SmartData Collective. All Rights Reserved.
Reading: More Matlab/IB Code
Share
Notification Show More
Latest News
big data mac performance
Data-Driven Tips to Optimize the Speed of Macs
News
3 Ways AI Has Helped Marketers and Creative Professionals Streamline Workflows
3 Ways AI Has Helped Marketers and Creative Professionals Streamline Workflows
Artificial Intelligence
data analytics in sports industry
Here’s How Data Analytics In Sports Is Changing The Game
Big Data
data analytics on nursing career
Advances in Data Analytics Are Rapidly Transforming Nursing
Analytics
data analytics reveals the benefits of MBA
Data Analytics Technology Proves Benefits of an MBA
Analytics
Aa
SmartData Collective
Aa
Search
  • About
  • Help
  • Privacy
Follow US
© 2008-23 SmartData Collective. All Rights Reserved.
SmartData Collective > Analytics > Predictive Analytics > More Matlab/IB Code
Predictive Analytics

More Matlab/IB Code

Editor SDC
Last updated: 2009/03/01 at 11:03 PM
Editor SDC
5 Min Read
SHARE

Here is some more Matlab code to interact with Interactive Brokers’ API. Check the previous tutorial on connecting Matlab to IB if this is new to you and of interest.

This script, sys3.m, is what I run to execute all the IB commands. It defines the futures contracts, turns them into IBContract objects, connects to TWS, downloads historical data, and then processes the data into usable periodic return format. This is not intended to trade real time so do not expect that functionality; however adding that yourself would not be difficult with this as an example.

Here are all the files you need (if something’s missing, leave a comment please):
sys3.m (same as above)
connecttws.m
loaddatatws2.m
preprocess.m
twsevent.m (very important)

To test it, download the files into the current Matlab directory, run Matlab, run and login to TWS and wait for it to fully load, then at the prompt type > sys3 and hit enter. Wait until it has said “end” seven times- it’s currently configured to download historical data for seven futures, ‘VIX’ ‘ZB’ ‘YC’ ‘YM’ ‘GE’ ‘ES’ ‘HE’ – “end” signals each data stream download finishing. Historical data from IB will then be in the variable “returndata”, o…

More Read

predictive analytics helps Albanian bitcoin investors

Albanian Bitcoin Investors Tap the Power of Predictive Analytics

Predictive Analytics Improves Trading Decisions as Euro Rebounds
Can Predictive Analytics Help Traders Navigate Bitcoin’s Volatility?
Perks of Predictive Analytics for Businesses Big and Small
How can CIOs Build Business Value with Business Analytics?


Here is some more Matlab code to interact with Interactive Brokers’ API. Check the previous tutorial on connecting Matlab to IB if this is new to you and of interest.

This script, sys3.m, is what I run to execute all the IB commands. It defines the futures contracts, turns them into IBContract objects, connects to TWS, downloads historical data, and then processes the data into usable periodic return format. This is not intended to trade real time so do not expect that functionality; however adding that yourself would not be difficult with this as an example.

Here are all the files you need (if something’s missing, leave a comment please):
sys3.m (same as above)
connecttws.m
loaddatatws2.m
preprocess.m
twsevent.m (very important)

To test it, download the files into the current Matlab directory, run Matlab, run and login to TWS and wait for it to fully load, then at the prompt type > sys3 and hit enter. Wait until it has said “end” seven times- it’s currently configured to download historical data for seven futures, ‘VIX’ ‘ZB’ ‘YC’ ‘YM’ ‘GE’ ‘ES’ ‘HE’ – “end” signals each data stream download finishing. Historical data from IB will then be in the variable “returndata”, ordered by security definitions, so you can play around with it. Look through the code to see what else is going on.

If it keeps saying “waiting”, that means there is a problem receiving the data so you probably need to cut it off. On my computer it does not say waiting more than a few times, if any. For those who are interested, it waits for each data stream to arrive before requesting new ones because it is received asynchroniously and this is the simplest way to keep straight which is which.

In sys3.m you can see that I had to tediously enter the contract details for each future from IB’s website by hand. I have another function which does this automatically, but it has not been integrated into the main script yet. After running the sys3 script, run this one- reqdet.m (abbrev. for “requestdetails.m”). In the variable “secTest”, in Matlab, you will find fully completed contract information for the securities. This only requires specifying the symbols for each security you want in a list and the expiration data for all of them. reqdet.m will make it much easier to download data from a huge list of futures.

I could use help from anyone else working on Matlab/IB in answering two questions:
1) How do you find out which futures/expiries have decent volume? Futures are relatively new to me and compared to stocks, there is no “volume” number.
2) How do you create a stream of historical data that goes back a long time, over multiple expiration dates? I’ve looked up “continuous contract” and it sounds like what I want, but the implementation is not simple because contracts don’t all have the same expiration dates. Perhaps you know of another data source that provides this already (does IB?)?

Also, please share any scripts and funtions you have created to do similar things. I would especially like to see alternative event handler functions. I welcome questions/comments too.

Editor SDC March 1, 2009
Share this Article
Facebook Twitter Pinterest LinkedIn
Share

Follow us on Facebook

Latest News

big data mac performance
Data-Driven Tips to Optimize the Speed of Macs
News
3 Ways AI Has Helped Marketers and Creative Professionals Streamline Workflows
3 Ways AI Has Helped Marketers and Creative Professionals Streamline Workflows
Artificial Intelligence
data analytics in sports industry
Here’s How Data Analytics In Sports Is Changing The Game
Big Data
data analytics on nursing career
Advances in Data Analytics Are Rapidly Transforming Nursing
Analytics

Stay Connected

1.2k Followers Like
33.7k Followers Follow
222 Followers Pin

You Might also Like

predictive analytics helps Albanian bitcoin investors
Blockchain

Albanian Bitcoin Investors Tap the Power of Predictive Analytics

9 Min Read
benefits of data analytics for financial management
Predictive Analytics

Predictive Analytics Improves Trading Decisions as Euro Rebounds

10 Min Read
predictive analytics can help bitcoin traders predict future price movements
Blockchain

Can Predictive Analytics Help Traders Navigate Bitcoin’s Volatility?

8 Min Read
predictive analytics
Predictive Analytics

Perks of Predictive Analytics for Businesses Big and Small

6 Min Read

SmartData Collective is one of the largest & trusted community covering technical content about Big Data, BI, Cloud, Analytics, Artificial Intelligence, IoT & more.

data-driven web design
5 Great Tips for Using Data Analytics for Website UX
Big Data
AI and chatbots
Chatbots and SEO: How Can Chatbots Improve Your SEO Ranking?
Artificial Intelligence Chatbots Exclusive

Quick Link

  • About
  • Contact
  • Privacy
Follow US

© 2008-23 SmartData Collective. All Rights Reserved.

Removed from reading list

Undo
Go to mobile version
Welcome Back!

Sign in to your account

Lost your password?