Data Collection

The data collection process consists of collecting US stock listings, creating a universe of leveraged ETFs, then collecting 1 minute bars for the leveraged ETFs.

Collect ETF listings

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'}

Define universe of leveraged ETFs

Next we download a CSV of several leveraged ETFs:

In [2]:
from quantrocket.master import download_master_file
download_master_file(
    "leveraged_etfs.csv",
    exchanges="ARCX",
    sec_types="ETF", 
    symbols=[
        "SPXL", # DIREXION DLY S&P 500 BULL 3X
        "TNA",  # DIREXION DLY SM CAP BULL 3X
        "ERX",  # DIREXION DLY ENERGY BULL 3X
        "TMF",  # DRX DLY 20+ YR TREAS BULL 3X
        "UPRO", # PROSHARES ULTRAPRO S&P 500
        "DRN",  # DRX DLY REAL ESTATE BULL 3X
        "YINN", # DRX DLY FTSE CHINA BULL 3X
        "UDOW", # PROSHARES ULTRAPRO DOW30
        "URTY", # PROSHARES ULTRAPRO RUSS2000
        "FAS",  # DIREXION DAILY FIN BULL 3X
        "EDC",  # DIREXION DLY EMG MKT BULL 3X
        "RUSL", # DIREXION DLY RUSSIA BULL 3X
        "JNUG", # DIREXION DLY JR GOLD BULL 3X
        "NUGT", # DRX DLY GOLD MINERS BULL 3X
    ])

Then upload the CSV to create the "leveraged-etf" universe:

In [3]:
from quantrocket.master import create_universe
create_universe("leveraged-etf", infilepath_or_buffer="leveraged_etfs.csv")
Out[3]:
{'code': 'leveraged-etf',
 'provided': 14,
 'inserted': 14,
 'total_after_insert': 14}

Collect historical data

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

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

Then collect the data for the leveraged ETFs:

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

Monitor flightlog for completion:

quantrocket.zipline: INFO [usstock-1min] Collecting minute bars for 14 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 14 securities in usstock-1min bundle

Next Up

Part 2: Moonshot Backtest