Skip to content

Get started

assayinganomalies is a Python package that builds a research database from CRSP and Compustat on your own machine and runs the protocol on it. This page takes you from an empty environment to a first report. The guide then goes through a signal of your own, and the manual documents every function.

The code is at github.com/velikov-mihail/AssayingAnomalies under the MIT license, and the package is on PyPI.

What you need

  • A WRDS subscription with CRSP monthly and daily stock files (the current format, CIZ), the CRSP/Compustat merged link table, Compustat annual and quarterly fundamentals, and the Fama-French factors. The database is built from your own account. The published anomalies come from the public Chen-Zimmermann Open Source Asset Pricing data and need no subscription.
  • Python 3.11 or 3.12.
  • Memory and time. A build of the full sample needs a machine with about 70 to 80 GB of RAM and takes a few hours; a protocol run takes about two hours on 16 cores. See Time and memory.
  • LaTeX with latexmk, to turn the report into a PDF. Without it you still get the .tex file and the figures.

Without WRDS you can try the package on synthetic data, or submit a signal and let us run it.

Install

In a fresh environment, with whichever environment manager you use:

python3 -m venv .venv                 # Windows: py -3.11 -m venv .venv
source .venv/bin/activate             # Windows: .venv\Scripts\activate
python -m pip install --upgrade pip
python -m pip install "assayinganomalies[analytics]"

python3 must be 3.11 or newer (python3 --version). On macOS it is often Apple's Python 3.9, and the install then fails with requires a different Python. Install a newer one (brew install python@3.11, or the installer from python.org) and create the environment with python3.11 -m venv .venv.

conda create -n assaying-anomalies python=3.11
conda activate assaying-anomalies
pip install "assayinganomalies[analytics]"
uv venv --python 3.11 .venv
source .venv/bin/activate             # Windows: .venv\Scripts\activate
uv pip install "assayinganomalies[analytics]"

A uv environment has no pip of its own: use uv pip install, not a bare pip install.

The analytics extra brings in what the protocol and its report need (scipy, scikit-learn, matplotlib, seaborn, jinja2). To reproduce a result, pin the version: pip install "assayinganomalies[analytics]==0.9.0". aa --version prints the installed one.

Run aa --help to confirm the install; it lists the commands used below.

Check which aa you are running

The package installs a command-line tool, aa. If another Python environment on your machine also has the package, a bare aa can be that environment's copy, with other versions of numpy and scipy, and your results will differ without a warning. Before a long run:

which aa              # macOS / Linux
where aa              # Windows, Command Prompt
Get-Command aa        # Windows, PowerShell
python -c "import assayinganomalies, sys; print(sys.executable, assayinganomalies.__file__)"

Both paths should be inside the environment you just created. zsh and bash remember where they last found a command, so after installing into an environment that was already active, run rehash (zsh) or hash -r (bash) and check again.

Quickstart

1. Choose a project folder and set parameters

The project folder holds the database (Data/aa.duckdb, with your settings stored inside it) and the outputs (Scratch/Assay/). Set it once; every later command finds it from any folder.

aa set-params --project-dir ~/research/my-project
aa set-params --sample-start 1963          # sample_end defaults to 'latest'
aa show-config

sample_end defaults to the last complete calendar year on WRDS when the build runs. For a paper, pin a year (aa set-params --sample-end 2025) so that a later rebuild covers the same window. aa show-config lists every setting with the flag that changes it.

The build downloads the published anomalies from Hugging Face near its end. Some networks block Hugging Face or its download servers, so we recommend downloading the two files before you start. Each release is a branch of the dataset OpenSourceAP/CrossSection; the release of October 2026 is Data-Release-2026.10. From the release's branch, download

  • signed_predictors_dl_wide.parquet (about 1.9 GB, under Firm Level Characteristics), and
  • SignalDoc.csv,

and save both, under those names, in the Data/ folder of your project folder. To build with a particular release, set it first: aa set-params --cz-release-version 2026.10.

If you skip this step and the download fails, the rest of the database is still built, and aa setup-database --start-from fetch-cz-anomalies fetches the anomalies later.

3. Build the database

export WRDS_USERNAME=your_username   # Windows PowerShell: $env:WRDS_USERNAME = "your_username"
export WRDS_PASSWORD=your_password   # Windows PowerShell: $env:WRDS_PASSWORD = "your_password"
aa setup-database

With neither set, the command asks for your username and password and offers to save them in ~/.pgpass. It logs in to WRDS once, before its first stage: approve the Duo push on your phone when it says so. The build writes Data/aa.duckdb and, beside it, a run manifest (aa.manifest.json) with the code version, the sample, the hashes of the inputs and the dates of the WRDS downloads.

4. Run the protocol on a signal

Save your signal as a CSV with the columns permno, dates (YYYYMM) and one column named after the signal's acronym (Prepare a signal file):

permno,dates,MYSIG
10006,197501,-2.18
10006,197502,-2.76

Then, from any folder:

aa run-protocol --signal mysig.csv \
    --acronym MYSIG --signal-name "My Signal" \
    --authors "Your Name and Coauthor Name" --paper-title "Your Paper"

The run writes the report (MYSIG.tex, its eight figures and, with LaTeX installed, MYSIG.pdf) under the project folder's Scratch/Assay/tex/, the results (MYSIG_Results.pkl) and the run's manifest (MYSIG_manifest.json). Run the protocol yourself has the options and the Python call.

The package's building blocks are public functions you can use on their own: portfolio sorts, factor regressions, Fama-MacBeth regressions, trading costs and generalized alphas. The quickstart notebook runs a sort and a regression, and chapters 12 to 15 of the tutorial document them.

Time and memory

Measured on one workstation with 16 cores, for the full sample (1925 to 2024):

Step Time
aa setup-database, from scratch 2 h 45 min
aa run-protocol on one signal, including the PDF about 2 h

The WRDS downloads are a large share of the build and depend on your connection. The finished database is about 16 GB, and the build also downloads about 10 GB of Chen-Zimmerman files.

The build's memory use peaks while it processes the CRSP daily file and grows with the sample:

Sample start Recommended RAM
1925 80 GB
1963 72 GB
1973 68 GB
1990 52 GB

aa setup-database checks this before its first stage and stops if the machine has less, naming the earliest sample start that would fit. The protocol's main process needs roughly 30 to 40 GB at full sample, and each worker process about 4 GB; the run sizes its worker pools to the machine's memory. If a run is killed by the operating system, lower the number of workers (aa run-protocol ... --n-jobs 4).

Trading costs

The build estimates each stock-month's trading cost, an effective half-spread, for the protocol's results net of costs. By default (tcosts_type = lf_combo) it averages four low-frequency estimators computed from CRSP daily data, and you need to do nothing. The paper's results use full, which takes high-frequency TAQ and ISSM spreads where they exist. That needs a file, hf_monthly.csv, which we cannot distribute: you build it on WRDS Cloud with Chen and Velikov's public code, which needs TAQ and ISSM subscriptions. Trading-cost inputs has the steps.

Trying it without WRDS

aa setup-database --demo

builds a small database from synthetic data so that you can try the functions. It is stamped as synthetic: the protocol refuses it unless you pass --allow-demo-data, and then labels every output as synthetic demo data. Never use it for research.

Where next