Collect data

To run the sample strategy we need 1-day bars for a single symbol. Any symbol will work, we will use AAPL. Create a database for free sample data (if it doesn't already exist):

In [1]:
from quantrocket.history import create_usstock_db
create_usstock_db("usstock-free-1d", bar_size="1 day", universe="FREE")
Out[1]:
{'status': 'successfully created quantrocket.v2.history.usstock-free-1d.sqlite'}

Then collect the data:

In [2]:
from quantrocket.history import collect_history
collect_history("usstock-free-1d")
Out[2]:
{'status': 'the historical data will be collected asynchronously'}

Use flightlog to monitor the progress:

quantrocket.history: INFO [usstock-free-1d] Collecting FREE history from 2007 to present
quantrocket.history: INFO [usstock-free-1d] Collecting updated FREE securities listings
quantrocket.history: INFO [usstock-free-1d] Collecting additional FREE history from 2020-04 to present
quantrocket.history: INFO [usstock-free-1d] Collected 160 monthly files in quantrocket.v2.history.usstock-free-1d.sqlite

Next we look up the Sid for AAPL (using the CLI in this example):

In [1]:
!quantrocket master get --symbol 'AAPL' --json | json2yml
---
  - 
    Sid: "FIBBG000B9XRY4"
    Symbol: "AAPL"
    Exchange: "XNAS"
    Country: "US"
    Currency: "USD"
    SecType: "STK"
    Etf: 0
    Timezone: "America/New_York"
    Name: "APPLE INC"
    PriceMagnifier: 1
    Multiplier: 1
    Delisted: 0
    DateDelisted: null
    LastTradeDate: null
    RolloverDate: null

We'll use this Sid in our backtrader script.


Next Up

Part 3: Strategy code