Dataset Viewer (First 5GB)
Auto-converted to Parquet Duplicate
date
stringdate
1930-04-20 00:00:00
2025-07-20 00:00:00
industry_code
stringclasses
444 values
bioguide_id
stringlengths
7
7
weight
int64
-600,000
177M
event_type
stringclasses
1 value
1930-04-20
J1200
S000033
876
DONATION
1954-10-17
H3100
B001265
1,000
DONATION
2000-07-16
H4100
B001251
3,000
DONATION
2001-07-15
J1100
G000596
2,291
DONATION
2001-10-21
F1100
H001050
2,500
DONATION
2002-02-03
J1100
D000618
2,087
DONATION
2002-02-03
J1100
E000295
2,087
DONATION
2003-07-20
B1200
L000554
2,000
DONATION
2007-04-15
z9600
C001071
2,000
DONATION
2008-02-03
E1210
C000794
-1,000
DONATION
2008-04-20
z9600
C001071
1,000
DONATION
2008-10-19
F3300
E000287
-500
DONATION
2008-10-19
Z1100
B001269
1,000
DONATION
2009-02-01
Z1100
H001057
2,000
DONATION
2009-02-01
Z1100
J000290
1,000
DONATION
2009-02-01
z9600
C001071
1,500
DONATION
2009-04-19
E1620
B000944
-1,000
DONATION
2009-04-19
H1400
B001261
-2,500
DONATION
2009-04-19
Z9600
M000355
2,000
DONATION
2009-07-19
Z9600
C001071
-1,000
DONATION
2009-10-18
K1000
B000575
1,000
DONATION
2009-10-18
z9600
G000555
1,000
DONATION
2010-01-31
A4500
P000590
-1,000
DONATION
2010-01-31
F2000
C001071
-1,000
DONATION
2010-01-31
F2100
G000555
-2,000
DONATION
2010-01-31
F5100
B000944
-500
DONATION
2010-01-31
G6400
C001070
-100
DONATION
2010-01-31
H1130
B001261
-1,000
DONATION
2010-01-31
H4300
B000944
-2,500
DONATION
2010-01-31
K1000
C001060
500
DONATION
2010-01-31
K1000
L000569
500
DONATION
2010-01-31
Z9600
G000555
1,000
DONATION
2010-04-18
A2000
D000216
250
DONATION
2010-04-18
E1120
M001153
-500
DONATION
2010-04-18
F2100
G000555
-2,500
DONATION
2010-04-18
F4100
C001071
-1,500
DONATION
2010-04-18
F5100
B001265
-1,000
DONATION
2010-04-18
K1000
C001060
500
DONATION
2010-04-18
z9600
B001268
5,000
DONATION
2010-07-18
H4300
B000944
-1,000
DONATION
2010-07-18
z9600
P000590
1,000
DONATION
2010-10-17
C4100
M000133
-500
DONATION
2010-10-17
E1160
B000243
-1,000
DONATION
2010-10-17
E1160
R000307
-1,000
DONATION
2010-10-17
E1620
B000944
-2,400
DONATION
2010-10-17
F5100
W000437
-2,000
DONATION
2010-10-17
H4100
H000338
-1,000
DONATION
2010-10-17
K1000
C001060
1,000
DONATION
2010-10-17
T6250
L000554
-1,000
DONATION
2010-10-17
Z9600
C001070
8,500
DONATION
2010-10-17
Z9600
J000177
4,000
DONATION
2011-02-06
A2000
B001234
-1,000
DONATION
2011-02-06
B3200
T000193
2,500
DONATION
2011-02-06
C4100
B001267
-1,900
DONATION
2011-02-06
C4100
D000615
-500
DONATION
2011-02-06
D8000
L000573
-1,000
DONATION
2011-02-06
E1170
B001267
2,500
DONATION
2011-02-06
E1620
B000944
-1,000
DONATION
2011-02-06
F1100
F000458
-5,000
DONATION
2011-02-06
F1100
K000378
-2,500
DONATION
2011-02-06
F1100
S001186
-2,500
DONATION
2011-02-06
F2100
B001267
-2,500
DONATION
2011-02-06
F3300
L000573
-2,500
DONATION
2011-02-06
F3400
L000573
-2,500
DONATION
2011-02-06
G2600
S001189
-2,000
DONATION
2011-02-06
G2900
B001267
-2,500
DONATION
2011-02-06
G2900
F000458
-2,000
DONATION
2011-02-06
G6500
H001055
-3,750
DONATION
2011-02-06
H1130
K000375
-1,000
DONATION
2011-02-06
H4300
B000944
-1,000
DONATION
2011-02-06
H4300
F000458
-2,000
DONATION
2011-02-06
J2200
B001276
-5,000
DONATION
2011-02-06
J7000
S001170
18,571
DONATION
2011-02-06
J7120
E000172
44
DONATION
2011-02-06
J7120
L000576
44
DONATION
2011-02-06
L1300
M001148
1,064
DONATION
2011-02-06
L1500
B001234
-3,000
DONATION
2011-02-06
LB100
M000312
-5,000
DONATION
2011-02-06
LE100
B001242
0
DONATION
2011-02-06
LG100
C001078
1,460
DONATION
2011-02-06
LG100
F000043
-2,500
DONATION
2011-02-06
LG100
M000702
2,191
DONATION
2011-02-06
LG100
M001183
2,191
DONATION
2011-02-06
LG100
P000600
1,460
DONATION
2011-02-06
LG100
R000011
2,191
DONATION
2011-02-06
LG100
S000185
1,460
DONATION
2011-02-06
LG300
H001064
343
DONATION
2011-02-06
LG300
L000560
454
DONATION
2011-02-06
LG300
M001111
7,018
DONATION
2011-02-06
T5100
G000563
-1,000
DONATION
2011-02-06
T5100
L000573
-2,500
DONATION
2011-02-06
T5100
M001181
-1,500
DONATION
2011-02-06
Z9600
J000283
1,200
DONATION
2011-02-06
Z9600
L000573
4,950
DONATION
2011-02-06
Z9600
M001153
1,000
DONATION
2011-02-06
Z9600
R000595
1,000
DONATION
2011-02-06
Z9600
S001183
1,000
DONATION
2011-02-06
z9600
A000366
2,500
DONATION
2011-02-06
z9600
B001236
5,000
DONATION
2011-02-06
z9600
C001082
5,000
DONATION
End of preview. Expand in Data Studio

HillStreet: A Relational Dataset for Evaluating Information Channels in Congressional Trading

HillStreet is a large-scale, longitudinal dataset and multimodal dynamic graph formalizing the intersection of Capitol Hill and Wall Street. It spans 13.5 years of mandatory STOCK Act disclosures (July 2012–December 2025), unifying the congressional trading ecosystem into a single, machine-learning-ready framework.

Dataset Summary

The dataset represents the relationship between 1,137 legislators and 6,825 companies. By framing congressional trading as a dynamic bipartite graph, HillStreet allows researchers to treat trade signal validation as an edge classification task.

  • Nodes: Legislators (session-specific) and Publicly Traded Companies.
  • Target Edges: Individual stock trades.
  • Structural Edges: Lobbying records, campaign finance (PAC/527) contributions, and geographical/industrial-constituency alignments.

HillStreet ships two alternative graph constructions over the identical node universe, events, and labels — see Graph Constructions below. They differ only in how a structural relationship reaches the model, so they can be compared head-to-head.

Prerequisite: data you must acquire separately

Two inputs are not redistributed here because they are licensed from third parties and cannot be publicly reshared. They are nonetheless integral to the dataset, and you need both to rebuild anything or to train on the trade edges' market features:

Input Expected location What it is
Trade table data/processed/ml_dataset_continuous.csv One row per congressional filing: BioGuideID, Matched_Ticker, Filed, Transaction, Trade_Size_USD, Filing_Gap, and the forward excess-return excursions Max_Excess_Return_6M / Min_Excess_Return_6M.
Price history data/parquet/{TICKER}.parquet Per-ticker daily history (date index + close), one file per ticker. Needed for the 17 market features and for the excess-return excursions. Tickers with no parquet file are excluded from the dataset.

Everything else in this repository — the raw reference tables, the three processed structural-event tables, the prebuilt graph tensors, and the source code — is self-contained. The prebuilt .pt shards already embed the market features and labels, so if you only want to train a GNN on the shipped graphs you do not need either proprietary input. You need them to rebuild the graphs, to reproduce the excursion columns, or to run the tabular and blending baselines.

Dataset Structure

HillStreet is divided into pre-built graph objects for deep learning, a relational tabular database accessed via Hugging Face configurations, and the source code used to build everything from the raw tables.

1. Dynamic Graph Objects (.pt & .npy)

For immediate use in Graph Neural Networks (GNNs) and Temporal Graph Networks (TGNs), the core of HillStreet consists of annual PyTorch Geometric Temporal objects.

  • Graph Files: hillstreet_temporal_graph_YEAR.pt — one annual shard per active year. Yearly sharding exists only to keep file sizes manageable; the shards concatenate back into one chronological graph.
  • Temporal Integrity: Every node feature and edge is instantiated based on its public disclosure date, not its reference date, ensuring a look-ahead-bias-free environment for backtesting. Structural edges additionally carry a last_seen timestamp (most recent interaction) alongside t (the start of the relationship), so recency/days-since features can be computed at load time.
  • ID Mappings: src_id_map.npy (Legislator Bioguide IDs → row index) and dst_id_map.npy (Company Tickers → row index). These define the global node ordering the static node tensors are aligned to. Indexing is unified and bipartite: legislators occupy [0, n_pol) and companies [n_pol, n_pol + n_comp), and dst_id_map.npy already carries the n_pol offset.
  • Node Features: node_features_static.pt (the five static node tensors) plus node_features_meta.json (dimensions and categorical vocabularies). Produced by Phase 3 of the pipeline and aligned to the ID maps above. With the default configuration flags, legislator features combine a trading-performance summary, chamber/party/leadership indicators, DW-NOMINATE ideology coordinates (evaluated as of the snapshot date), and committee-membership indicators; company features encode the SIC industry division. Integer category indices for legislator state and company sector/industry are also provided for use as learned embeddings. Note that Census district employment enters the graph as geo edge weights (not node features), and SEC fiscal facts are shipped as a raw table that can be enabled as company node features via a configuration flag (off by default).

Each shard is a TemporalData object with these fields:

Field Dtype Shape Meaning
src long [E] legislator node index
dst long [E] company node index
t long [E] epoch seconds — for a trade, the filing time; for a collapsed structural edge, the earliest event in the pair
msg float [E, 24] or [E, 35] edge attributes (layout below)
y long [E] 1 / 0 on trade edges, -1 on structural edges (exclude these from supervision)
event_type long [E] 0 trade, 1 lobbying, 2 campaign finance, 3 geographical-industrial
last_seen long [E] epoch seconds of the most recent event in the collapsed edge; equals t for trades

Events within a shard are sorted strictly ascending by t; the builder asserts this before saving.

msg column layout. Positional order matters — downstream code indexes these columns by position.

Index Columns Group
0–2 Trade_Size_USD, Filing_Gap, Transaction trade mechanics
3–6 is_sponsorship, voted_yea, Fin_Amt, Geo_Weight structural-only
7–23 vol_20d, vol_60d, vol_120d, vol_252d, vol_of_vol_60d, vol_trend, idio_vol_60d, mom_60d, mom_252d, reversal_21d, beta_20d, beta_60d, downside_beta, excess_vol, max_dd_60d, skew_60d, sharpe_60d 17 market features
24–34 the 11 merged-history columns merged-edge construction only

Columns a stream does not carry are zero-filled: a lobbying edge has zeros in the trade-mechanic and market slots, and a trade edge has zeros in the structural-only slots. Trade_Size_USD is an ordinal 1–10 over the disclosure brackets ($1,001–$15,000 → 1 … Over $50,000,000 → 10); Transaction is 1.0 for a purchase and 0.0 for a sale. The 17 market features are anchored strictly at the filing date.

2. Relational Tables (Hugging Face Configs)

For researchers using flat-feature models (XGBoost, LightGBM) or custom graph builders, the structural connective tissue is provided as multiple dataset configurations. You can load these individually using the Hugging Face datasets library (e.g., load_dataset("benroodman/HillStreet", "processed_events_lobbying")).

Processed Edge Tables:

  • processed_events_lobbying: Mappings of legislative activity to corporate nodes.
  • processed_events_campaign_finance: Itemized PAC/527 donations broadcasted to corporate sectors.
  • processed_events_geographical_industry: Industrial-constituency edges linking legislators to companies in their districts.

Raw Source Tables: The raw, underlying tables are also available as distinct configurations for custom aggregations and feature engineering:

  • Campaign Finance: raw_cf_* and raw_527_* configs.
  • Legislator Data: raw_voteview_* configs and raw_committee_assignments.
  • Corporate & Industry: raw_sec_financials, raw_naics_* crosswalks, and raw_district_industries_* configs.
  • Lobbying: raw_lobbyview_* configs.

These configurations are unrelated source tables with deliberately different schemas, so each is declared separately. The .pt / .npy graph tensors and the source files are not dataset configs — browse them in the Files tab or fetch them with huggingface_hub.hf_hub_download.

3. Source Code (src/)

The complete pipeline that turns the raw tables into the processed edge tables and graph objects is included. The package is laid out as:

src/
├── config.py                          # central paths + feature flags
├── build_graph_multi_edge_type.py     # orchestrator — multi-edge-type graph
├── build_graph_merged_edges.py        # orchestrator — merged-edge graph
├── build_tabular_merged_dataset.py    # orchestrator — flat-CSV analogue of the merged graph
└── data_prep/
    ├── build_lobbying_events.py
    ├── build_campaign_events.py
    ├── build_geographical_edges.py
    ├── build_clean_dataset.py
    ├── ticker_normalizer.py
    ├── price_utils.py
    ├── append_price_features.py
    ├── labeling.py
    ├── node_features.py
    └── feature_lookups.py

Orchestrators.

  • config.py — Resolves the project root and centralizes every input/output path and the feature flags (which structural channels and node-feature blocks are enabled). The data-prep scripts import it via from src import config.
  • build_graph_multi_edge_type.py — Builds the multi-edge-type graph. Ingests the trade table and the three processed event tables, bakes the label, broadcasts sector-level structural events to individual tickers, collapses repeated structural pairs into single weighted edges (keeping both first-seen time and last_seen), writes the per-channel edge parquets, and shards the unified edge stream into annual TemporalData objects with global node-id maps. It then invokes Phase 3 to build the aligned static node tensors.
  • build_graph_merged_edges.py — Builds the merged-edge graph. Reuses Phase 1 of the multi-edge-type builder verbatim, then replaces Phase 2 with the fan-out-weighted as-of merge that folds each pair's prior structural history onto its trade edges. Writes to its own directories so the two constructions never clobber each other.
  • build_tabular_merged_dataset.py — Emits ml_dataset_continuous_merged.csv: the trade table plus the same 11 merged-history columns the merged GNN's decoder sees, plus the label y. It reads the merged trade parquet rather than recomputing the merge, so the tabular and graph inputs are byte-identical and the comparison is fair. Required by the GNN × tabular blending and stacking studies.

Data preparation.

  • build_lobbying_events.py — Maps lobbying clients to tickers (via NAICS→SIC→ticker crosswalks) and links them to sponsoring legislators, writing data/processed/events_lobbying.csv.
  • build_campaign_events.py — Aggregates corporate PAC and 527 contributions above a conviction threshold, maps donors to legislators, and writes data/processed/events_campaign_finance.csv.
  • build_geographical_edges.py — Builds industrial-constituency edges from Census County Business Patterns district data (top industries per district by employment), writing data/processed/events_geographical_industry.csv.
  • build_clean_dataset.py — Turns the raw STOCK Act filings into ml_dataset_continuous.csv: ticker normalization, then the forward excess-return excursions at eight horizons. Only needed if you hold the raw filings and are regenerating the trade table yourself.
  • ticker_normalizer.py — Conservative ticker→parquet matching with a manual map for known ambiguities (e.g. BRK.ABRK). Verifies the parquet file exists before matching and emits a full unmatched report. Imported by build_clean_dataset.py.
  • price_utils.py — Cached parquet loading; forward excess-return excursions at eight horizons (1–24 months) and backward technical features, all filing-date anchored with no lookahead. Imported by build_clean_dataset.py.
  • append_price_features.py — Computes the 17 market features and writes them into the trade CSV. Also defines PRICE_FEATURE_COLUMNS, whose order fixes the msg tensor layout, so it is imported by the orchestrators and by node_features.py whether or not you ever run it standalone. Exposes ensure_price_features(), which the orchestrators call automatically — it is idempotent and a no-op when the columns are already present.
  • labeling.pySingle source of truth for the label y. Imported by both label bakes (graph and tabular) so the two targets are byte-identical. See The Label.
  • node_features.py — Phase 3. Once an orchestrator has written src_id_map.npy / dst_id_map.npy, build_node_features() assembles the five static node tensors (legislator features, legislator state embedding index, company features, company sector and industry embedding indices) aligned to those maps, saving node_features_static.pt and node_features_meta.json. It is called automatically by the orchestrators (skip with --skip_node_features); it is not run standalone. It also defines the canonical MSG_COLUMNS order and provides load_combined_graph(), which recombines the annual shards into one static graph and attaches the node bundle.
  • feature_lookups.py — Helper module imported by node_features.py. Provides the as-of-date lookup classes (TermLookup, PoliticianBioLookup, IdeologyLookup, CommitteeLookup, CompanySICLookup, CompanyFinancialsLookup) that resolve a legislator's or company's attributes from the raw tables (congress terms, DW-NOMINATE ideology, committee assignments, company SIC, SEC financials) at a given snapshot date. It is not executed directly.

Graph Constructions

The same nodes, the same events, the same labels — two different answers to "how should a structural relationship reach the model?"

Multi-edge-type Merged-edge
Shards + id maps data/processed/pyg_graph/ data/processed/pyg_graph_merged/
Edge parquets data/processed/master_edges_parquet/ data/processed/master_edges_parquet_merged/
Node bundle data/processed/node_features_static.pt data/processed/pyg_graph_merged/node_features_static.pt
Builder src/build_graph_multi_edge_type.py src/build_graph_merged_edges.py
msg width 24 35 (24 base + 11 merged)
Structural relations separate edges, tagged by event_type folded onto the trade edge as point-in-time history
Approx. size ~0.15 GB ~0.19 GB

Where the node bundle lives differs between the two. The merged-edge pipeline writes its bundle inside pyg_graph_merged/, so that directory is self-contained. The multi-edge-type pipeline writes its bundle to data/processed/node_features_static.pt, one level up. The two never collide, but if you download only the multi-edge-type graph, remember its bundle does not sit in pyg_graph/.

Multi-edge-type

Lobbying, campaign-finance, and geographical-industrial relations are carried as their own edges alongside the trade edges, each declaring its kind through event_type (0 trade, 1 lobbying, 2 campaign, 3 geo). All four streams share the one 24-column msg layout, zero-filled where a stream carries nothing. Message passing therefore sees each relation type as a distinct edge that a model can route, weight, or ablate separately.

Merged-edge

The alternative hypothesis: instead of a separate campaign-finance edge linking a legislator to a company, fold a point-in-time summary of that prior relationship onto the trade edge the same pair later transacts. If legislator P received industry money mapping to company C, and P later trades C, the trade edge's features should already "know" about that link.

For every trade (legislator, company, Filed) the builder looks back over all prior structural events between that exact pair, strictly before the filing time, and appends 11 columns:

Block Columns
Lobbying (3) m_lobby_count, m_lobby_recency, m_lobby_flag
Campaign finance (4) m_camp_logamt, m_camp_count, m_camp_recency, m_camp_flag
Geographical-industrial (4) m_geo_logwt, m_geo_count, m_geo_recency, m_geo_flag

They are appended after the original 24, so code indexing the base layout positionally stays valid, and they are non-zero only on trade rows. The structural streams are still written to the merged shards, so the node universe and node features are identical to the multi-edge-type construction — a driver simply chooses not to route them into message passing.

Fan-out normalization. Campaign-finance and geo events link a legislator to every ticker in an industry or sector, not to one company: a single industry-PAC donation fans out across every ticker in that SIC. Each broadcast edge is therefore down-weighted by its fan-out — the number of distinct tickers the originating event reached:

effective count  = Σ over prior events of  1 / fanout_e
effective amount = Σ over prior events of  amount_e / fanout_e

A pair in a 2-ticker industry counts ~25× more than one in a 50-ticker industry. Recency and the *_flag indicator are not normalized. Fan-out is computed exactly for campaign and geo (each pre-broadcast event is tagged and its expansion counted). For lobbying it is a documented proxy: events_lobbying.csv is already exploded to ticker level and the originating client/bill identity is gone, so fan-out is taken as the number of distinct tickers linked to that legislator on that filing date.

Leakage boundary. The lookback is a merge_asof(direction="backward", allow_exact_matches=False), so each trade sees only structural events strictly before its own filing time — the same standard applied to the trade's market features. Because the merge is anchored to the trade's own timestamp rather than to a moving backtest cutoff, it is fold-independent and is baked into the shards once.

Which one should I use?

They answer different questions, and both are shipped so the comparison can be run head-to-head. Use multi-edge-type when you want the model to learn how to route each relation type. Use merged-edge when you want the relational history available directly to the trade-edge decoder without message passing having to carry it. ml_dataset_continuous_merged.csv is the flat-feature analogue of the merged-edge graph — the same 11 columns as tabular features — so gradient-boosted baselines can be compared against the GNNs on byte-identical inputs.


The Label

y is direction-adjusted, peak-based, and thresholded at the top quartile within each direction.

For each trade, the signal is the direction-adjusted peak six-month excess return over SPY — the most favorable excursion the excess-return path reaches at any point in the horizon, measured in the direction the legislator actually bet:

buy   :  signal =  Max_Excess_Return_6M     (best favorable long excursion)
sell  :  signal = -Min_Excess_Return_6M     (inverted: the adverse excursion of the excess path)

y = 1  iff  signal >= q_0.75  over all trades of that same direction

Inverted sell scoring is the key asymmetry. A sale is a correct call when the stock lagged SPY at some point in the window, so the sell side is scored on the negated minimum of the excess path, not its maximum. Scoring both directions on Max would reward a legislator for selling a stock that then outperformed.

Three further properties are worth stating explicitly:

  • It is a path maximum, not an endpoint return. The question is whether the trade reached the threshold at any point in the six months, not where it closed.
  • It is excess over SPY, not raw return.
  • It is anchored on the filing date, not the trade date. This is the copy-trading frame: the earliest moment the public could have acted on the disclosure.

Two thresholds are estimated once over the whole dataset — one per direction — giving roughly 25% positives on each side. This is deliberately not fold-local: the threshold is global by design, so the label can be baked at build time and every downstream consumer simply reads y. Trades whose horizon has not resolved yield a NaN signal, fail the >= test, and land at y = 0 rather than corrupting the threshold. Structural edges carry y = -1 and must be excluded from supervision.

The definition lives in src/data_prep/labeling.py and is imported by both label bakes, so the graph and tabular targets are byte-identical.

Evaluation Protocol

Results on this dataset use a gap-aware walk-forward split, anchored on Filed + horizon_days:

  • TrainFiled < test_start and Filed + horizon < test_start (fully resolved outcomes only)
  • GapFiled < test_start and Filed + horizon >= test_start (excluded from supervision; the outcome is not yet known at test time)
  • TestFiled ∈ [test_start, test_start + 1 month), walked forward month by month

The primary metric is pooled AUROC: pool every per-trade prediction across the full test year, then compute a single AUROC. The average of monthly AUROCs is a diagnostic, not the headline number. The secondary metric is precision among the top 10% of highest-confidence predictions per month — the actionable copy-trading measure.


Reproduction Pipeline

All commands are run from the repository root, with data/processed/ml_dataset_continuous.csv and data/parquet/ in place (see Prerequisite). Use the python -m form throughout: it puts the repository root on sys.path, and build_clean_dataset.py uses package-relative imports that require it.

Requirements: Python 3.12, torch==2.9.1, torch-geometric==2.7.0, plus pandas, numpy, pyarrow, duckdb, scikit-learn, scipy, tqdm. The CPU build of PyTorch is sufficient — a GPU only speeds up model training, not dataset construction. Install PyTorch and PyG before the rest.

# 0. (Only if regenerating the trade table from raw filings)
python -m src.data_prep.build_clean_dataset        # -> data/processed/ml_dataset_continuous.csv

# 1. Build the three processed structural-event tables (any order)
python -m src.data_prep.build_lobbying_events
python -m src.data_prep.build_campaign_events
python -m src.data_prep.build_geographical_edges

# 2. Build edge parquets, annual PyG shards, node-id maps, and aligned node features.
#    Run either or both constructions; each writes to its own directories.
#    (Phase 3 node features run automatically at the end of each.)
python -m src.build_graph_multi_edge_type          # -> pyg_graph/        + master_edges_parquet/
python -m src.build_graph_merged_edges             # -> pyg_graph_merged/ + master_edges_parquet_merged/

# 3. (Optional) the flat-CSV analogue, for tabular and blending baselines
python -m src.build_tabular_merged_dataset         # -> ml_dataset_continuous_merged.csv

The orchestrators do not call the three structural builders themselves — they read their CSV outputs — but each does invoke node_features.py (which imports feature_lookups.py) as its final phase, so both must be present.

The 17 market features are handled automatically: the orchestrators call ensure_price_features(), which appends them to the trade CSV only if they are absent. There is no separate manual step. Pass --refresh_price_features to recompute them (e.g. after rebuilding the price parquets) or --skip_price_features to leave the CSV untouched and fail if the columns are missing.

Other useful flags: --start_date YYYY-MM-DD bounds the graph timeline (the STOCK Act era begins July 2012); --skip_node_features emits edges and shards only; --snapshot_date pins the as-of date for time-varying node features; --force (merged builder) rebuilds the edge parquets rather than reusing them. build_tabular_merged_dataset.py does not read the structural CSVs itself — it reuses the merged trade parquet, so run build_graph_merged_edges.py first or pass --build_merged to have it build that parquet in-process.

Loading the Tensors

import torch, numpy as np

shard = torch.load("data/processed/pyg_graph_merged/hillstreet_temporal_graph_2023.pt",
                   weights_only=False)
print(shard.src.shape, shard.msg.shape)          # [E], [E, 35]

# Supervised trade edges only
trades = shard.event_type == 0
X, y = shard.msg[trades], shard.y[trades]

# Node indices back to entity ids
src_map = np.load("data/processed/pyg_graph_merged/src_id_map.npy", allow_pickle=True).item()
bioguide_of = {v: k for k, v in src_map.items()}

# Static node features
bundle = torch.load("data/processed/pyg_graph_merged/node_features_static.pt",
                    weights_only=False)
x_pol, x_comp = bundle["x_pol"], bundle["x_comp"]
print(bundle["meta"]["n_pol"], bundle["meta"]["n_comp"], bundle["meta"]["snapshot_date"])

node_features.load_combined_graph() does the same work at a higher level: it recombines the annual shards into one static graph, converts the unified node ids to the bipartite-local convention the models expect, and attaches the node bundle.

Feature Engineering & Normalization

To stabilize variance in graph training, continuous features are transformed using signed log-scaling: x=sign(x)×log(1+x)x' = \text{sign}(x) \times \log(1 + |x|)

Counts and amounts follow the same treatment: edge weights use log1p(total_count) normalized by the maximum, trade size is an ordinal bracket, and filing gap is log1p(days) winsorized at 120 days.

Caveats

  • Volatility features are strong, and are not leakage. vol_120d measured at the filing date is the single most predictive feature for flat-feature baselines. High-volatility stocks mechanically reach a top-quartile peak more often — a real, known-at-filing-time relationship rather than lookahead — but any analysis should account for it.
  • Broadcast relations are diffuse. Campaign-finance and geo events are industry-level, so they connect a legislator to every ticker in an industry. The merged-edge construction down-weights by fan-out; the multi-edge-type construction does not, leaving that to the model.
  • Lobbying fan-out is a proxy. See Merged-edge.
  • Structural edges are collapsed. Repeated events for the same (legislator, company, event_type) are merged into one weighted edge, with t the earliest event and last_seen the most recent. Trades are never collapsed — each is a distinct supervised event.
  • Tickers without price history are dropped from the dataset entirely.
  • The graph is bipartite. There are no legislator↔legislator or company↔company edges.

Intended Use

  • Trade Signal Validation: Determining if a trade constitutes a meaningful price signal based on political context.
  • Graph Representation Learning: A benchmark for GNNs and TGNs.

Non-Intended Use: This dataset is for research purposes only. It is not designed for legal determinations of insider trading nor for real-time automated trading.

Downloads last month
151