QuantRocket logo
Disclaimer


Moonshot Intro › Part 1: Data Collection


Collect US Stock Data¶

To collect end-of-day sample data for US stocks, create a database and specify free=True. We will name the database "usstock-free-1d":

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

This creates an empty database. Next, we need to fill up the database with data. Data collection runs asynchronously (that is, in the background), so it's a good idea to open a terminal for flightlog if you haven't already done so in order to monitor the progress. You can start a flightlog terminal from the Launcher menu or by executing the %flightlog magic command in a notebook:

In [2]:
%flightlog

Then collect the data:

In [3]:
from quantrocket.history import collect_history
collect_history("usstock-free-1d")
Out[3]:
{'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 Up¶

Part 2: Universe Selection