QuantRocket logo

Disclaimer

Define a universe

QuantRocket relies heavily on the concept of universes, which are user-defined groupings of securities. Universes provide a convenient way to refer to and manipulate groups of securities when collecting historical data, running a trading strategy, etc. You can create universes based on exchanges, security types, sectors, liquidity, or any criteria you like. A universe could consist of one or two securities or thousands of securities.

Query securities

To create our first universe, we will query securities from the securities master database, optionally pare them down to a subset of securities, then upload the pared down securities to create our universe. Learn more about universes in the usage guide.

Security listings for our sample stocks were automatically collected during historical data collection. We query the stock listings from the securities master database using the get_securities function, which loads them into a pandas DataFrame:

Note the Sid index in the DataFrame: Sid is short for "security ID" and is the unique identifier for a particular security or contract. Sids are used throughout QuantRocket to refer to securities.

Create universe

To create a universe consisting of these securities, we simply upload the list of sids to the create_universe function. We'll name the universe "usstock-free":

The function output confirms the name and size of our new universe.

Filter securities

As a demonstration, we could also pare down the securities to create a universe from a subset of securities. For example, we might limit the universe to currently listed securities:

Then we can create a universe from the filtered securities.


Next Up

Part 3: Momentum Factor Research