Skip to content

Trading-cost inputs

The database's per-stock trading costs (tcost in ccm_panel, used for the protocol's net-of-cost results) are effective half-spreads, estimated each stock-month by the compute-tcosts stage of aa setup-database. Most of the estimators run on the CRSP daily file the build already downloads. Two inputs are not on that file:

Input Needed for Where it comes from
crspgibbs.csv: Hasbrouck's Gibbs estimates every tcosts_type Ships with the package. Nothing to do.
hf_monthly.csv: high-frequency effective spreads from TAQ and ISSM tcosts_type=full only You build it on WRDS Cloud (below).

Choosing tcosts_type

tcosts_type Spread estimate for each stock-month Inputs beyond CRSP
lf_combo (default) Average of four low-frequency estimators: Hasbrouck's Gibbs, Corwin–Schultz high–low, Abdi–Ranaldo close–high–low, and Kyle–Obizhaeva volume-over-volatility the Gibbs file
full The high-frequency TAQ/ISSM effective spread wherever one exists; the lf_combo average elsewhere the Gibbs file and hf_monthly.csv
gibbs Gibbs alone the Gibbs file

In every case, stock-months with no estimate are filled from the nearest stock by size and idiosyncratic volatility, and the result is halved into a one-way cost. This follows Chen and Velikov, "Zeroing in on the Expected Returns of Anomalies" (JFQA, 2023).

Which to pick. lf_combo needs nothing you have to build and is the default. full replaces the low-frequency estimate with the directly measured spread wherever TAQ or ISSM has one, which is more accurate, but it requires the extra subscriptions and the hour-long WRDS job below. The two give different numbers, so state which one your tables use. gibbs exists for comparison with work that used Gibbs alone.

Set it before building:

aa set-params --tcosts-type full      # or lf_combo, or gibbs
aa setup-database

To change it on a database that is already built, rerun the trading-cost stage and the stages after it, without repeating the WRDS downloads:

aa set-params --tcosts-type full
aa setup-database --start-from compute-tcosts

The Gibbs file

crspgibbs.csv holds Gibbs estimates of the Roll model (Hasbrouck, "Trading Costs and Returns for U.S. Equities: Estimating Effective Costs from Daily Data", JF 2009) for every CRSP stock-year from 1926 to 2024. WRDS does not provide it: it is the output of Hasbrouck's SAS code run over CRSP daily data, which takes many hours. So the repository ships it, in inputs/gibbs/, along with the SAS code and instructions for rebuilding it.

You do not need to do anything. aa setup-database looks for the file in this order and uses the first it finds:

  1. the file you set with aa set-params --gibbs-path /path/to/crspgibbs.csv;
  2. any crspgibbs*.csv under Data/staging/, then under Data/;
  3. inputs/gibbs/crspgibbs.csv, when you run from a clone of the repository;
  4. any crspgibbs*.csv under the directory you run aa from;
  5. a download from this repository's gibbs-data-v1 tag into Data/staging/crspgibbs.csv.

Step 5 is what a pip install (no clone) uses. The download is about 42 MB, happens once (later builds find the copy in Data/staging/), and is checked against a SHA-256 fingerprint recorded in the package; a file that does not match is refused and not saved. The check happens before the first WRDS stage, so a failure costs you seconds, not hours.

Offline, or behind a proxy that blocks GitHub? Download https://raw.githubusercontent.com/velikov-mihail/AssayingAnomalies/gibbs-data-v1/inputs/gibbs/crspgibbs.csv on another machine (or copy inputs/gibbs/crspgibbs.csv from a clone) and save it as Data/staging/crspgibbs.csv in your project directory.

Want estimates the shipped file lacks? Rebuild it on WRDS Cloud with the SAS code in inputs/gibbs/; inputs/gibbs/README.md walks through it step by step. Note that the code reads CRSP's legacy daily file, which ends in December 2024, so it cannot yet produce estimates for 2025 and later. Point the build at your file with aa set-params --gibbs-path; your own file is used as is, without the fingerprint check.

Building hf_monthly.csv

Only for tcosts_type=full. The file holds monthly effective spreads per permno, computed by Chen and Velikov's public code, hf-spreads-all, from intraday data: ISSM for 1983–1992 and WRDS's TAQ Intraday Indicators for later years. It covers essentially all NYSE and AMEX trading from 1983 and almost all NASDAQ trading from 1987 (about eight months of 1987–1991 NASDAQ data are missing from ISSM). It is not shipped because it is derived from TAQ and ISSM, which are licensed to subscribers.

The file used for Novy-Marx and Velikov, "Assaying Anomalies", runs from January 1983 through December 2025. To get a file that reaches past December 2024 you have to make one change to the public code first (below).

What you need

  • A WRDS account that can log in to WRDS Cloud (SSH to wrds-cloud.wharton.upenn.edu).
  • Subscriptions, through your institution, to ISSM, Daily TAQ, Monthly TAQ and WRDS TAQ IID (the WRDS Intraday Indicators), plus CRSP. The code reads ISSM from /wrds/issm/sasdata and the IID tables from /wrds/nyse/sasdata/wrds_taqs_iid_v1/ and /wrds/nyse/sasdata/wrds_taqms_iid/; without access to these, the job fails.

Steps

  1. Log in to WRDS Cloud from a terminal, with your WRDS username in place of your_username (here and in step 5):

    ssh -l your_username wrds-cloud.wharton.upenn.edu
    
  2. Get the code into your home directory:

    git clone https://github.com/chenandrewy/hf-spreads-all.git
    cd hf-spreads-all
    

    (Or download the repository as a zip on your own machine, upload it with scp -o User=your_username hf-spreads-all-master.zip wrds-cloud.wharton.upenn.edu:, and unzip it there.)

  3. Fix the email line in main.sh. The script asks the scheduler to email its author when the job starts and ends: the line starting #$ -M holds the author's address. Put your own address there, or delete that line and the #$ -m abe line above it:

    nano main.sh
    
  4. For months after December 2024, change add_permnos.sas as described below. Without the change the job runs, but no spread after December 2024 gets a permno, so the file ends there.

  5. Submit the job, as the repository's instructions say:

    qsub main.sh
    

    qstat shows whether it is still running; qdel <job number> cancels it. It takes about an hour, mostly for the ISSM years. SAS logs go to ~/temp_log/.

  6. Download the result into your project folder (the one you gave to aa set-params --project-dir). The job writes ~/temp_output/hf_monthly.csv on WRDS Cloud. From your own machine, in the project folder:

    scp -o User=your_username wrds-cloud.wharton.upenn.edu:temp_output/hf_monthly.csv .
    

    The file can sit anywhere in the project folder; see Where the build looks.

  7. Build with it:

    aa set-params --tcosts-type full
    aa setup-database                               # a new database
    aa setup-database --start-from compute-tcosts   # or: an existing one
    

One change for months after December 2024

The public code gives each TAQ symbol its CRSP permno in add_permnos.sas, from the CRSP names file crsp.msenames. That file belongs to CRSP's legacy format, which CRSP froze in December 2024, so it has no ticker history after that month and later spreads are left without a permno. In CRSP's current format (CIZ) the same history is in crsp.stksecurityinfohist. In the data step of add_permnos.sas that reads the names file:

  • read crsp.stksecurityinfohist instead of crsp.msenames;
  • take the start and end of each link from secinfostartdt and secinfoenddt, where the legacy file has namedt and nameendt;
  • take the share class from shareclass, where the legacy file has shrcls;
  • drop the rows with a blank ticker. They cannot match a TAQ symbol, and the new file has enough of them to make the join very slow.

Nothing else in the code changes. Check the result: the last yearm in hf_monthly.csv should be the last month of your TAQ data, not 202412.

Where the build looks for hf_monthly.csv

  1. Data/staging/, then Data/, with their subfolders. The first file found is used.
  2. The rest of the project folder, with its subfolders, except Scratch/ and folders whose name starts with a dot (such as .venv). So a file in the project folder itself or in a folder of your own, such as inputs/, is found from whatever folder you run aa in.
  3. The folder you run aa from, with its subfolders.

In steps 2 and 3 the build stops with an error that lists the files if it finds more than one hf_monthly.csv. The spreads file changes every net return, so the build does not choose between copies. Keep one, or put the one to use in Data/staging/, which is searched first. The build's run manifest (Data/aa.manifest.json) records the file it read and its SHA-256.

When a file is missing

The build checks these inputs before its first stage, so a missing file stops it before any WRDS download, and the error message says what to do.

Situation Normal build aa setup-database --demo
No Gibbs file found locally Downloads it into Data/staging/ Does not download; warns and builds trading costs without the Gibbs measure
Gibbs download fails or fails the SHA-256 check Stops with MissingInputError, naming the URL, where to save the file by hand, and --gibbs-path (not attempted)
--gibbs-path names a file that does not exist Stops with FileNotFoundError Same
tcosts_type=full and no hf_monthly.csv Stops with MissingInputError, pointing here and at --tcosts-type lf_combo Stops at the compute-tcosts stage, same error
tcosts_type=full and more than one hf_monthly.csv outside Data/ Stops with AmbiguousInputError (a MissingInputError), listing the files Stops at the compute-tcosts stage, same error

Once you have the file, resume without repeating the WRDS stages:

aa setup-database --start-from compute-tcosts

Calling make_trading_costs from Python directly behaves the same way: without gibbs_path it raises MissingInputError unless you pass demo=True.

The Kyle–Obizhaeva estimator also uses the CPI series (CPIAUCNS), which the build downloads from FRED. If that download fails, the estimator runs without the inflation adjustment and the build logs a warning; nothing else changes.

Each build records the files it read, with their SHA-256 fingerprints, in its run manifest (Data/aa.manifest.json), and the gibbs_path setting with the other scientific settings.