Though most of our features will come from the Sharadar price and fundamental data, we also wish to add some additional features that reflect the broad market. Specifically, we will include features relating to the S&P 500, the VIX, and the NYSE TRIN (aka Arms Index, a breadth measure).
This data will come from Interactive Brokers.
First, start IB Gateway:
from quantrocket.ibg import start_gateways
start_gateways(wait=True)
{'ibg1': {'status': 'running'}}
Next we collect the listings from IBKR. (For the S&P 500, we collect the SPY ETF because IBKR provides deeper history for SPY@ARCA than SPX@CBOE.)
from quantrocket.master import collect_ibkr_listings
collect_ibkr_listings(exchanges="ARCA", symbols="SPY", sec_types="ETF")
collect_ibkr_listings(countries="US", symbols=["VIX", "TRIN-NYSE"], sec_types="IND")
{'status': 'the IBKR listing details will be collected asynchronously'}
Monitor flightlog for the completion messages:
quantrocket.master: INFO Collecting ARCA ETF listings from IBKR website (SPY only)
quantrocket.master: INFO Requesting details for 1 ARCA ETF listings found on IBKR website
quantrocket.master: INFO Saved 1 ARCA ETF listings to securities master database
quantrocket.master: INFO Collecting US IND listings from IBKR website (VIX, TRIN-NYSE only)
quantrocket.master: INFO Requesting details for 2 US IND listings found on IBKR website
quantrocket.master: INFO Saved 2 US IND listings to securities master database
Look up the Sids for the various instruments:
from quantrocket.master import download_master_file
download_master_file("indices.csv", exchanges=["CBOE", "NYSE", "ARCA"], symbols=["SPY", "VIX", "TRIN-NYSE"], sec_types=["IND","ETF"], vendors="ibkr")
import pandas as pd
indices = pd.read_csv("indices.csv")
indices[["Sid", "Symbol", "Name", "Exchange"]]
Sid | Symbol | Name | Exchange | |
---|---|---|---|---|
0 | FIBBG000BDTBL9 | SPY | SPDR S&P 500 ETF TRUST | ARCX |
1 | IB13455763 | VIX | CBOE Volatility Index | XCBO |
2 | IB26718743 | TRIN-NYSE | NYSE TRIN (OR ARMS) INDEX | XNYS |
Next, we create a database for collecting 1-day bars for the indexes:
from quantrocket.history import create_ibkr_db
create_ibkr_db("market-1d",
sids=[
"FIBBG000BDTBL9",
"IB13455763",
"IB26718743",
],
bar_size="1 day")
{'status': 'successfully created quantrocket.v2.history.market-1d.sqlite'}
Then collect the data:
from quantrocket.history import collect_history
collect_history("market-1d")
{'status': 'the historical data will be collected asynchronously'}
Monitor flightlog for completion:
quantrocket.history: INFO [market-1d] Collecting history from IBKR for 3 securities in market-1d
quantrocket.history: INFO [market-1d] Saved 13302 total records for 3 total securities to quantrocket.v2.history.market-1d.sqlite