Python code for IB historical data

Course Name: Momentum Trading Strategies, Section No: 6, Unit No: 5, Unit type: Notebook



Dear comunnity,



For a while I found that one of the hardest parts for auto trading is to maintain a healthy database, when I studied the unit above I´ve start to think if someone has python notebook that would handle the data updates for that strategy (SP500 closing prices). Thanks for the support!

Hi Guilherme,

In automated trading, handling of streaming price data is indeed a challenge.

But for the purpose of getting the closing prices of SP500 stocks, you can create your own notebook. 

The outline steps for making the new notebook are as follows:

  1. Fetch the closing prices of SP500 tickers at end of the day. You may use your broker's API service for this.
  2. Put these prices in a data frame with the names of the tickers as columns and the current date as the index.
  3. Append this data to an existing CSV. Note, that append adds a row value, keeping the old data intact.
Alternatively, you can read the CSV in the beginning, add the row for current day's close, and then replace the CSV with data from the appended data frame.

Hope this helps!

Data updates are a reliable way to create your own database. Most of the hedge fund create their own databases. However, it is difficult to do, Alternatively, you can get historical price data of daily frequency from yahoo finance or from data vendors such as Quandl. Thank you!