Wrds

From edwinhu/workflows · View interactive version

Wrds is an AI agent skill from the GitHub repository edwinhu/workflows. Use when "query WRDS", "access Compustat/CRSP/ExecuComp/Capital IQ", "Form 4 insider data", "Form 144 proposed insider sales (Thomson)", "13F institutional ownership (Thomson)", "13D/13G blockholders", "ISS governance/compensation/voting/directors", "proxy advisor recommendations", "shareholder prop

How to use this skill

Skill file

<!-- wc-probe: ignore-narrated-history -->

<!-- remaining dates are data cutoffs and coverage ends (2024-12-31 CIZ cutoff, 2020-12-31 DealScan cap) -->

What this skill carries — grep references/ for any subject the names below miss:

!d=${CLAUDE_SKILL_DIR}; command -v skill-toc >/dev/null 2>&1 && exec skill-toc "$d"; s=$HOME/.claude/skills/plugin-utils/bin/skill-toc; [ -x "$s" ] && exec "$s" "$d"; echo "(skill-toc unavailable: references and scripts are NOT listed here — install the plugin-utils plugin, or start a new session so its bin/ reaches PATH)"

Building a proxy-voting panel? Use the npx-ownership-panel skill, not

this one. It owns risk.voteanalysis_npx (238M rows / 329 GB), the ISS->CRSP

fund crosswalk, and the four-leg SGE pipeline that produces the analysis-ready

panel. This skill covers WRDS access patterns generally.

Contents

WRDS Login Node Enforcement

IRON LAW: NEVER RUN COMPUTE ON THE WRDS LOGIN NODE

<EXTREMELY-IMPORTANT>

The WRDS login node is shared infrastructure. Running parsers, bulk file reads, SAS jobs, or any process taking >30 seconds on the login node will get the account flagged.

ALWAYS write an SGE submission script and submit via qsub. No exceptions.

The login node is for: qsub, qstat, qdel, scp, ls, head, short psql queries.

Submission patterns and working array jobs: ${CLAUDE_PLUGIN_ROOT}/skills/edgar/references/edgar.md (§ SGE Submission Pattern), scripts/sec_index/submit_array.sh, scripts/parse_13f/sge/submit_shards.sh, and ../npx-ownership-panel/scripts/run_pipeline.sh.

</EXTREMELY-IMPORTANT>

Running compute on the login node is NOT HELPFUL — it gets the user's account flagged, the job killed, and the work lost. You run on the login node because qsub feels like overhead. The overhead is 5 minutes of script writing. The downside is account suspension and a rerun from scratch.

Login Node & Infrastructure Facts

Red Flags — STOP Immediately If You're About To:

EDGAR filings and filing parsers

Filing lists, filing text, exhibits, filing paths and every EDGAR extractor (scan_covers profiles, the two sanctioned record-table parsers, wrds_forms_reg): ${CLAUDE_PLUGIN_ROOT}/skills/edgar/SKILL.md. The scripts stay in this skill's scripts/.

WRDS Data Access

WRDS (Wharton Research Data Services) provides academic research data via PostgreSQL at wrds-pgdata.wharton.upenn.edu:9737.

Query Enforcement

IRON LAW: NO QUERY WITHOUT FILTER VALIDATION FIRST

Before executing ANY WRDS query, you MUST:

  1. IDENTIFY what filters are required for this dataset
  2. VALIDATE the query includes those filters
  3. VERIFY parameterized queries (never string formatting)
  4. EXECUTE the query
  5. INSPECT a sample of results before claiming success

This is not negotiable. Skipping sample inspection is NOT HELPFUL — the user builds analysis on data with undetected quality problems.

Red Flags

Query Validation Checklist

Before EVERY query execution:

For Compustat queries (comp.funda, comp.fundq):

For CRSP v2 queries (crsp.dsf_v2, crsp.msf_v2):

For Form 4 queries (tr_insiders.table1):

For ALL queries:

SAS ETL Enforcement

IRON LAW: NO SAS CODE WITHOUT PERFORMANCE VALIDATION FIRST

<EXTREMELY-IMPORTANT>

Before writing or executing ANY SAS code on WRDS, you MUST validate performance patterns. This is not negotiable.

  1. MERGE STRATEGY — Is hash or sort-merge appropriate? Justify the choice.
  2. WHERE CLAUSES — Are all date/string filters index-friendly? No functions on indexed columns.
  3. PARALLELISM — Can this job run as an SGE array? Year-by-year is always parallelizable.
  4. SQL OPTIMIZATION — For PROC SQL: pass-through opportunity? Indexed join columns?

Writing SAS code that forces full table scans when indexes exist is NOT HELPFUL — the user's job runs 100x slower than necessary and may timeout.

</EXTREMELY-IMPORTANT>

SAS Code Validation Checklist

Before EVERY SAS program execution:

For probing inputs (do this FIRST — metadata only, seconds):

For merges/joins:

For WHERE clauses (CRITICAL):

For batch processing:

For PROC SQL:

For macros:

SAS Performance Facts

SAS Red Flags - STOP Immediately If You're About To:

SAS Reference

See references/sas-etl.md for complete patterns:

Quick Reference: Table Names

| Dataset | Schema | Key Tables |

|---------|--------|------------|

| Compustat | comp | company, funda, fundq, secd |

| ExecuComp | comp_execucomp | anncomp |

| CRSP | crsp | dsf, msf, stocknames, ccmxpf_lnkhist |

| CRSP v2 | crsp | dsf_v2, msf_v2, stocknames_v2 |

| Form 4 / 144 Insiders | tr_insiders | table1, header, company, form144 |

| ISS Incentive Lab | iss_incentive_lab | comppeer, sumcomp, participantfy |

| Capital IQ | ciq (views), ciq_pplintel, ciq_common | wrds_professional (board/professional panel), ciqcompanyrel (company-to-company), wrds_compensation. Account-split: ciq_pplintel and boardex_na are on opposite WRDS accounts; ciq_transactions is denied on both. See references/capiq.md |

| BoardEx | boardex_na (edwin_hu only) | na_wrds_org_composition (directors + senior managers — filter seniority), na_wrds_company_names, na_dir_profile_details (usualname = nickname). History starts 1999, ~20k mostly-large companies. See references/boardex.md |

| WRDS People Link | wrdsapps_plink_exec_ciq, _exec_boardex, _exec_trinsider, _trinsider_ciq | pairwise PERSON id links (execid ↔ directorid ↔ CIQ personid ↔ TR personid). plink_boardex_ciq denied unless the account holds both. See references/people-linking.md |

| Audit Analytics activism | audit_corp_legal (edwin_hu only) | feed31_shareholder_activism — one row per SC 13D/13D-A: subject CIK, filer, accession, stake, purpose keys. Query it before parsing 13D covers. No proxy-fight/settlement fields. See references/audit-analytics.md |

| IBES | tr_ibes | det_epsus, statsum_epsus |

| Form D / Reg D | wrdssec | wrds_vc_formd (parsed, 2000–2020); index: wrdssec_all.wrds_forms (every header CIK, with accession and wrdsfname), see ${CLAUDE_PLUGIN_ROOT}/skills/edgar/references/wrds-forms-tables.md |

| SEC EDGAR | wrdssec_all | wrds_forms (every header CIK per filing, accession, wrdsfname — default), forms (same CIKs, no accession), wrds_forms_reg (CIK roles), wciklink_cusip — the filing route is the edgar skill |

| SEC Search | wrds_sec_search | filing_<form> (full text + indexed filing_tsv), registrant — server-side full-text search; never select filing in bulk. See ${CLAUDE_PLUGIN_ROOT}/skills/edgar/references/sec-text-search.md |

| Fama-French | ff | factors_monthly, factors_daily |

| LSEG/Datastream | tr_ds | ds2constmth, ds2indexlist |

| FJC (Federal Judicial Center) | fjc | civil, criminal, bankruptcy, appeals |

| FJC Linking | fjc_linking | wrds_civil_link, wrds_criminal_link |

| SDC New Issues (IPO/SEO/Debt) | tr_sdc_ni | wrds_ni_details — equity + debt offerings |

| SDC Mergers & Acquisitions | tr_sdc_ma | wrds_ma_details — M&A transactions |

| TAQ Legacy | taq | mast_YYYY, wrds_iid_YYYY — second-level (1993–2006) |

| TAQ Millisecond | taqmsec | mastm_YYYY, wrds_iid_YYYY, ctm_YYYYMM, complete_nbbo_YYYYMMDD |

| Thomson S12 (Mutual Fund Holdings) | tfn (SAS) / tr_mutualfunds (PG) | s12 — 13F/N-CSR fund holdings |

| Thomson S34 (13-F Institutional) | tfn (SAS) / tr_13f (PG) | s34 — 13-F institutional holdings |

| FISD / Mergent (Corporate Bonds) | fisd_fisd | fisd_mergedissue, fisd_mergedissuer — corporate/agency/Treasury; NOT the muni source (issuer_type='M' munis are incidental) |

| Municipal trades (MSRB RTRS) | msrb | msrb (trades + inline CUSIP master: coupon, maturity), msrb_lookup; also msrb_all, msrbsamp. Primary muni source. See references/muni-bonds.md |

| Municipal new issues (SDC) | tr_sdc_municipals | deal-level: ratings, GO/rev, bank-qualified, callable, size, sector — but SELECT is permission-denied on this subscription (not licensed); msrb is the only readable muni schema. See references/muni-bonds.md |

| PitchBook | pitchbk_companies_deals, pitchbk_investors_funds_lps, pitchbk_fund_returns | deal, company, fund, wrds_fund_returns — dealsize in USD millions |

Connection

Initialize PostgreSQL connection to WRDS:

import psycopg2

conn = psycopg2.connect(
    host='wrds-pgdata.wharton.upenn.edu',
    port=9737,
    database='wrds',
    sslmode='require'
    # Credentials from ~/.pgpass
)

Configure authentication via ~/.pgpass with chmod 600:

wrds-pgdata.wharton.upenn.edu:9737:wrds:USERNAME:PASSWORD

Connect via SSH tunnel:

ssh wrds

This uses ~/.ssh/wrds_rsa for authentication.

Critical Filters

Compustat Standard Filters

Always include for clean fundamental data:

WHERE indfmt = 'INDL'
  AND datafmt = 'STD'
  AND popsrc = 'D'
  AND consol = 'C'

CRSP v2 Common Stock Filter

Equivalent to legacy shrcd IN (10, 11):

df = df.loc[
    (df.sharetype == 'NS') &
    (df.securitytype == 'EQTY') &
    (df.securitysubtype == 'COM') &
    (df.usincflg == 'Y') &
    (df.issuertype.isin(['ACOR', 'CORP']))
]

Form 4 Transaction Types

WHERE acqdisp = 'D'  -- Dispositions
  AND trancode IN ('S', 'D', 'G', 'F')  -- Sales, Dispositions, Gifts, Tax

Parameterized Queries

Always use parameterized queries (never string formatting):

Use scalar parameter binding for single values:

cursor.execute("""
    SELECT gvkey, conm FROM comp.company WHERE gvkey = %s
""", (gvkey,))

Use ANY() for list parameters:

cursor.execute("""
    SELECT * FROM comp.funda WHERE gvkey = ANY(%s)
""", (gvkey_list,))

Additional Resources

Reference Files

Detailed query patterns and table documentation:

Example Files

Working code from real projects:

Scripts

Local Sample Notebooks

WRDS-provided samples at ~/resources/wrds-code-samples/:

Date Awareness

When querying historical data, leverage current date context for dynamic range calculations.

Current date is automatically available via datetime.now(). Apply this to:

Implement dynamic date ranges in queries:

from datetime import datetime, timedelta

# Query last 5 years of data
end_date = datetime.now()
start_date = end_date - timedelta(days=5*365)

query = """
SELECT * FROM comp.funda
WHERE datadate BETWEEN %s AND %s
"""
df = pd.read_sql(query, conn, params=(start_date, end_date))

Always incorporate current date awareness in date-dependent queries to ensure results remain fresh across time.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.