The Alpha Architect white paper calls for the trading strategy to run on the universe of NYSE stocks, excluding financials, REITs, and ADRs. Thus our first step is to create universes that define these different groups of securities.
First, download a CSV of all NYSE securities from the securities master. We use fields="sharadar*"
to include all Sharadar master fields in the output. We use vendors="sharadar"
to limit to securities which are available from Sharadar.
from quantrocket.master import download_master_file
download_master_file("sharadar_nyse_securities.csv", exchanges="NYSE", fields="sharadar*", vendors="sharadar")
We can use the file to create the universe of all NYSE securities:
from quantrocket.master import create_universe
create_universe("nyse-stk", "sharadar_nyse_securities.csv")
Next we create a universe of financials. We'll exclude this universe (along with REITs and ADRs) when it comes time to run our backtest.
First load the securities into Pandas and list the sectors:
import pandas as pd
nyse_securities = pd.read_csv("sharadar_nyse_securities.csv")
nyse_securities.sharadar_Sector.unique()
In the Sharadar data, the financial sector is called "Financial Services". We filter the DataFrame to stocks in this sector, write them to a file (we use an in-memory file so as not to clutter the hard drive), and upload the file to create the universe of financial stocks:
nyse_securities[nyse_securities.sharadar_Sector == "Financial Services"].to_csv("sharadar_nyse_financials.csv")
create_universe("nyse-financials", "sharadar_nyse_financials.csv")
Next we create a universe of REITs. From inspecting the master file we know that REITs are identified in the "sharadar_Industry" column:
nyse_securities[nyse_securities.sharadar_Industry.fillna("").str.contains("REIT")].to_csv("sharadar_nyse_reits.csv")
create_universe("nyse-reits", "sharadar_nyse_reits.csv")
To create a universe of ADRs, we can take advantage of the "sharadar_Category" field in the Sharadar data, which contains this information. First have a peek:
nyse_securities.sharadar_Category.unique()
nyse_securities[nyse_securities.sharadar_Category.fillna("").str.startswith("ADR")][["sharadar_Ticker","sharadar_Name","sharadar_Category"]].head()
Then create the ADR universe:
nyse_securities[nyse_securities.sharadar_Category.fillna("").str.startswith("ADR")].to_csv("sharadar_nyse_adrs.csv")
create_universe("nyse-adrs", "sharadar_nyse_adrs.csv")