SPY Data Collection

We will backtest the trading strategy using the SPY ETF. The data collection process consists of collecting US Stocks listings, then collecting 1 minute bars for SPY.

Collect SPY listing

First, collect US Stock listings:

In [1]:
from quantrocket.master import collect_usstock_listings
collect_usstock_listings()
Out[1]:
{'status': 'success', 'msg': 'successfully loaded US stock listings'}

Lookup SPY

Next, we look up the Sid (security ID) for SPY. We use the command line interface because less typing is required.

Prefixing a line with ! allows running terminal commands from inside a notebook.

In [2]:
!quantrocket master get --symbols 'SPY' --sec-types 'ETF' --fields 'Sid' 'Symbol' 'Exchange' --json | json2yaml
---
  - 
    Sid: "FIBBG000BDTBL9"
    Symbol: "SPY"
    Exchange: "ARCX"

Collect historical data

Next, we create a Zipline bundle for collecting 1-min bars for SPY:

In [3]:
from quantrocket.zipline import create_usstock_bundle
create_usstock_bundle("usstock-1min")
Out[3]:
{'status': 'success', 'msg': 'successfully created usstock-1min bundle'}

Then collect the data for SPY:

In [4]:
from quantrocket.zipline import ingest_bundle
ingest_bundle("usstock-1min", sids="FIBBG000BDTBL9")
Out[4]:
{'status': 'the data will be ingested asynchronously'}

Monitor flightlog for completion:

quantrocket.zipline: INFO [usstock-1min] Collecting minute bars for 1 securities in usstock-1min bundle
quantrocket.zipline: INFO [usstock-1min] Collecting daily bars for usstock-1min bundle
quantrocket.zipline: INFO [usstock-1min] Collecting adjustments for usstock-1min bundle
quantrocket.zipline: INFO [usstock-1min] Collecting assets for usstock-1min bundle
quantrocket.zipline: INFO [usstock-1min] Completed collecting data for 1 securities in usstock-1min bundle

Next Up

Part 2: Moonshot Backtest