Wrds 标志

Wrds

社区
Barrios88
wrds

This skill should be used when the user asks to "query WRDS", "access Compustat", "get CRSP data", "pull Form 4 insider data", "query ISS compensation", "download SEC EDGAR filings", "get ExecuComp data", "access Capital IQ", "query TRACE bond data", "clean TRACE", "merge FISD", "query TAQ", "pull intraday trades or quotes", "build NBBO", "compute effective spread", or needs WRDS PostgreSQL query patterns.

Add to TypingMind

概览

发布者Barrios88
代码仓库barrios-skills
技能名称wrds
星标数
64
复刻数
30
附带文件
12
许可协议MIT
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 12 个附带文件

    模型执行任务时可读取的脚本、模板和参考资料。这些文件为只读文件,绝不会被执行。

  • 开源

    由 Barrios88 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Wrds AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/Barrios88/barrios-skills/tree/main/skills/econometrics/wrds
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/Barrios88/barrios-skills.git /tmp/barrios-skills
mkdir -p .claude/skills
cp -r /tmp/barrios-skills/skills/econometrics/wrds .claude/skills/wrds
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Wrds,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Wrds。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Wrds 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

Barrios Skills — John Barrios's curated workflow for economists and accountants. Prioritize reproducible empirical work, clear identification language, and journal-ready output.

WRDS MCP (recommended for AI agents)

John Barrios's wrds-mcp server exposes WRDS to Cursor, Claude, and other MCP clients.

Before querying WRDS, the user must:

  1. Install the MCP from mcp/wrds-mcp/ — see install/wrds-mcp.md
  2. Set their own credentials: WRDS_USERNAME and WRDS_PASSWORD (from their WRDS account)
  3. Start the tunnel: bash mcp/wrds-mcp/tunnel/tunnel_up.sh and approve Duo MFA once per session
  4. Register the MCP with WRDS_TUNNEL_PORT=49600 in Cursor or Claude config

When to use WRDS instead / with EDGAR: Compustat fundamentals panels, CRSP returns, CCM links, ExecuComp, ISS, TRACE/TAQ — use this skill + wrds-mcp. For live filing text, XBRL facts, and public Forms 3/4/5 without WRDS panel infrastructure, use the sec-edgar skill + SEC EDGAR MCP.

When MCP tools are available (wrds_run_sql, wrds_get_compustat, etc.), prefer MCP over raw Python connections. Still apply all filter rules in this skill.

If the user has not configured MCP credentials, stop and walk them through install/wrds-mcp.md — do not guess usernames or passwords.

Contents

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. Claiming query success without sample inspection is LYING to the user about data quality.

Rationalization Table - STOP If You Think:

ExcuseRealityDo Instead
"I'll add filters later"You'll forget and pull bad dataAdd filters NOW, before execution
"User didn't specify filters"Standard filters are ALWAYS requiredApply Critical Filters section defaults
"Just a quick test query"Test queries with bad filters teach bad patternsUse production filters even for tests
"I'll let the user filter in pandas"Pulling millions of unnecessary rows wastes time/memoryFilter at database level FIRST
"The query worked, so it's correct"Query success ≠ data qualityINSPECT sample for invalid records
"I can use f-strings for simple queries"SQL injection risk + wrong type handlingALWAYS use parameterized queries

Red Flags - STOP Immediately If You Think:

  • "Let me run this query quickly to see what's there" → NO. Check Critical Filters section first.
  • "I'll just pull everything and filter later" → NO. Database-level filtering is mandatory.
  • "The table name is obvious from the request" → NO. Check Quick Reference section for exact names.
  • "I can inspect the data after the user sees it" → NO. Sample inspection BEFORE claiming success.

Query Validation Checklist

Before EVERY query execution:

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

  • Includes indfmt = 'INDL'
  • Includes datafmt = 'STD'
  • Includes popsrc = 'D'
  • Includes consol = 'C'
  • Uses parameterized queries for variables
  • Date range is explicitly specified

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

  • Post-query filter: sharetype == 'NS'
  • Post-query filter: securitytype == 'EQTY'
  • Post-query filter: securitysubtype == 'COM'
  • Post-query filter: usincflg == 'Y'
  • Post-query filter: issuertype.isin(['ACOR', 'CORP'])
  • Uses parameterized queries

For Form 4 queries (tr_insiders.table1):

  • Transaction type filter specified (acqdisp)
  • Transaction codes specified (trancode)
  • Date range is explicitly specified
  • Uses parameterized queries

For TAQ queries (taqm_YYYY.ctm_ / cqm_ / complete_nbbo_*):**

  • Using taqm_YYYY (daily partitioned) for post-2003 work, not legacy taq
  • Trade filter: tr_corr = '00' (string, not integer)
  • Trade conditions: drop tr_scond containing Z, O, T, U, G, B (non-regular)
  • Regular trading hours: time_m BETWEEN '09:30:00' AND '16:00:00'
  • Price > 0 and size > 0 sanity checks
  • For NBBO: use complete_nbbo_* (not nbbom_* — incomplete by design)
  • If joining to CRSP: use wrdsapps_link_crsp_taqm with sdate/edate bounds
  • Consider wrds_iid_YYYY for pre-computed daily liquidity measures
  • Never SELECT * — specify columns (ctm has 20, cqm/nbbom are huge)
  • Sort explicitly by (time_m, time_m_nano, tr_seqnum) — insertion order not guaranteed

For TRACE queries (trace_enhanced.trace_enhanced):

  • Using trace_enhanced (uncapped) not trace_standard (capped) for research
  • Dick-Nielsen cleaning applied: drop trc_st IN ('X','C','W','Y') + matched originals
  • Pre-/post-2012-02-06 logic branch selected correctly
  • Agency double-count filter: NOT (cmsn_trd='Y' AND cntra_mp_id='D')
  • Commissioned trades handled (cmsn_trd='N' for price/yield work)
  • Special trades excluded: spcl_trd_fl != 'Y' (for price/liquidity analysis)
  • FISD merge for bond characteristics (coupon, maturity, rating, issuer)
  • Date range is explicitly specified on trd_exctn_dt
  • Uses parameterized queries

For ALL queries:

  • Sample inspection with .head() or .sample() BEFORE claiming success
  • Row count verification (is result size reasonable?)
  • NULL value check on critical columns
  • Date range validation (does min/max match expectations?)

Quick Reference: Table Names

DatasetSchemaKey Tables
Compustatcompcompany, funda, fundq, secd
ExecuCompcomp_execucompanncomp
CRSPcrspdsf, msf, stocknames, ccmxpf_lnkhist
CRSP v2crspdsf_v2, msf_v2, stocknames_v2
Form 4 Insiderstr_insiderstable1, header, company
ISS Incentive Labiss_incentive_labcomppeer, sumcomp, participantfy
Capital IQciqwrds_compensation
IBEStr_ibesdet_epsus, statsum_epsus
SEC EDGARwrdssecwrds_forms, wciklink_cusip
SEC Searchwrds_sec_searchfiling_view, registrant
EDGARedgarfilings, filing_docs
Fama-Frenchfffactors_monthly, factors_daily
LSEG/Datastreamtr_dsds2constmth, ds2indexlist
TRACE Enhanced (bonds, uncapped)trace_enhancedtrace_enhanced, trace_btds144a_enhanced, trace_agency_enhanced
TRACE Standard (bonds, capped)trace_standardtrace, trade_summary
FISD bond characteristics (Mergent)fisdfisd_mergedissue, fisd_mergedissuer, fisd_issue, fisd_issuer
TAQ Daily MSEC (ticks, µs)taqm_YYYYctm_YYYYMMDD, cqm_YYYYMMDD, complete_nbbo_YYYYMMDD, nbbom_YYYYMMDD, mastm_YYYY, wrds_iid_YYYY
TAQ Monthly (legacy, 1993–2014, sec)taqmonthly consolidated trades/quotes
CRSP↔TAQ linkwrdsapps_link_crsp_taqmlink table

Connection

Initialize PostgreSQL connection to WRDS:

python
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:

bash
ssh wrds

This uses ~/.ssh/wrds_rsa for authentication.

Critical Filters

Compustat Standard Filters

Always include for clean fundamental data:

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

CRSP v2 Common Stock Filter

Equivalent to legacy shrcd IN (10, 11):

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

Form 4 Transaction Types

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

TAQ Standard Cleaning (Holden-Jacobsen 2014)

Minimum filter for academic intraday work:

sql
-- Trades (ctm_YYYYMMDD)
WHERE tr_corr = '00'                               -- uncorrected
  AND price > 0 AND size > 0
  AND time_m BETWEEN '09:30:00'::time AND '16:00:00'::time
  AND (tr_scond IS NULL OR tr_scond = ''
       OR tr_scond !~ '[BGJKLOTUWZ4567]')          -- regular-way only

-- Quotes (cqm_YYYYMMDD)
WHERE bid > 0 AND ask > 0 AND ask > bid
  AND bidsiz > 0 AND asksiz > 0
  AND qu_cond IN ('A','B','H','O','R','W')
  AND time_m BETWEEN '09:30:00'::time AND '16:00:00'::time

Always prefer complete_nbbo_* over nbbom_* — the raw NBBO feed is incomplete when one exchange holds both sides of the top of book. If re-deriving, UNION nbbom with cqm records where natbbo_ind='1' OR nasdbbo_ind='4'. See references/taq.md.

TRACE Enhanced Cleaning (Dick-Nielsen 2014)

Apply BEFORE any price/volume analysis:

sql
-- Post-2012-02-06: drop cancels, corrections, reversals + their matched originals.
-- Match originals on (cusip_id, entrd_vol_qt, rptd_pr, trd_exctn_dt,
-- trd_exctn_tm, rpt_side_cd, cntra_mp_id, msg_seq_nb).
WHERE trc_st = 'T'                              -- keep only clean originals
  AND NOT (cmsn_trd = 'Y' AND cntra_mp_id = 'D') -- drop agency double count
  AND spcl_trd_fl != 'Y'                         -- drop special-condition trades
  AND wis_fl != 'Y'                              -- drop when-issued
  -- For price/yield work, also:
  AND cmsn_trd = 'N'

Pre-2012-02-06 data uses asof_cd = 'R' for reversals instead of trc_st = 'Y'; use the pre-2012 branch. See references/trace.md.

Parameterized Queries

Always use parameterized queries (never string formatting):

Use scalar parameter binding for single values:

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

Use ANY() for list parameters:

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

Additional Resources

Reference Files

Detailed query patterns and table documentation:

  • references/compustat.md - Compustat tables, ExecuComp, financial variables
  • references/crsp.md - CRSP stock data, CCM linking, v2 format
  • references/insider-form4.md - Thomson Reuters Form 4, rolecodes, insider types
  • references/iss-compensation.md - ISS Incentive Lab, peer companies, compensation
  • references/edgar.md - SEC EDGAR filings, URL construction, DCN vs accession numbers
  • references/trace.md - TRACE bond transactions, Dick-Nielsen cleaning, FISD merge, pre-/post-2012 logic
  • references/taq.md - TAQ/TAQMSEC intraday trades, quotes, complete NBBO, Holden-Jacobsen filters, WRDS Intraday Indicators
  • references/connection.md - Connection pooling, caching, error handling

Example Files

Working code from real projects:

  • examples/form4_disposals.py - Insider trading analysis (from SVB project)
  • examples/wrds_connector.py - Connection pooling pattern

Scripts

  • scripts/test_connection.py - Validate WRDS connectivity

Local Sample Notebooks

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

  • ResearchApps/CCM2025.ipynb - Modern CRSP-Compustat merge
  • ResearchApps/ff3_crspCIZ.ipynb - Fama-French factor construction
  • comp/sas/execcomp_ceo_screen.sas - ExecuComp patterns

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:

  • Data range validation (e.g., "get data for last 5 years")
  • Fiscal year calculations
  • Event study windows

Implement dynamic date ranges in queries:

python
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.

附带文件

技能加载后,模型会按需读取这些文件。它们仅作为可读文件提供,绝不会被执行。

常见问题

Wrds AI 技能有什么作用?

This skill should be used when the user asks to "query WRDS", "access Compustat", "get CRSP data", "pull Form 4 insider data", "query ISS compensation", "download SEC EDGAR filings", "get ExecuComp data", "access Capital IQ", "query TRACE bond data", "clean TRACE", "merge FISD", "query TAQ", "pull intraday trades or quotes", "build NBBO", "compute effective spread", or needs WRDS PostgreSQL query patterns.

为什么在 TypingMind 中使用 Wrds?

因为您只需安装一次,就能搭配任何模型使用。Wrds 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Wrds?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/Barrios88/barrios-skills/tree/main/skills/econometrics/wrds。TypingMind 会读取其中的 SKILL.md,打包相关文件,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Wrds?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Wrds 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Wrds 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Wrds AI 技能免费吗?

是的。Barrios88 已在 GitHub 上根据 MIT 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇