Heterogeneous Temporal Graph Neural Network and Gradient Boosting for Related-Party Transaction Fraud Detection: A Chronological Panel Study
Abstract
Related-Party Transaction Fraud Detection     Reproducibility package for a heterogeneous temporal graph neural network and gradient-boosting pipeline that detects related-party transaction fraud at the company-year level in Shanghai and Shenzhen A-share listed companies, fiscal years 2015 to 2023. Overview The protocol combines three branches: Monthly heterogeneous graph encoder. Three relation types (related-party transaction, fund transfer, bill endorsement) are passed through four-head relation-attention message passing with residual connections and layer normalisation, followed by a 12-month global and 3-month local temporal self-attention module. Transformer text encoder. The related-party transaction section, the guarantees-and-fund-occupation section and the management-discussion-and- analysis section of each annual report are encoded by a six-layer Transformer with section-based pooling. Structured financial projection. Twenty-five annual financial and guarantee variables are passed through a two-layer MLP. The three branches are fused through learnable attention and an extreme gradient boosting classifier whose principal hyperparameters are tuned by the Improved Mayfly Algorithm. The evaluation protocol covers a strict chronological train / validation / test split with as-of label-availability refits, rolling-origin and company-disjoint folds, a 2000-replicate company-cluster bootstrap, DeLong paired tests, a simulated federated run with the Information Leakage Rate and shadow membership-inference evaluation, and edge-rewiring, Gaussian-noise and missingness robustness perturbations. Repository layout ``` . |-- README.md |-- environment.yml conda environment specification |-- requirements.txt pip requirements |-- configs/ YAML configurations |-- data/ | |-- raw/ thirteen raw tables (Supplementary Table S3) | `-- processed/ standardised panel and graph embeddings |-- scripts/ 15 executable steps + run_all.py |-- src/rptfraud/ core Python package | |-- data_loading.py | |-- graph_construction.py | |-- models/ proposed model, baselines, GNN, text, fusion | |-- optim/ IMA, Mayfly, Levy, chaotic initialisation | |-- privacy/ ILR (Equation 17, shared), MIA | |-- evaluation/ metrics, DeLong, bootstrap, calibration | |-- federated/ client partitioning, FedAvg | `-- robustness/ edge rewiring, Gaussian noise, missing data |-- tests/ unit tests |-- label_audit/ per-as-of-date audit tables (step 02 output) |-- splits/ chronological / rolling / disjoint fold tables |-- predictions/ per-sample y_true / y_score |-- evaluation/ metric summaries, DeLong, bootstrap outputs |-- privacy/ ILR and MIA outputs |-- source_data/ figure source data `-- outputs/ tables, figures, logs ``` Installation Prerequisites Python 3.10 or later 8 GB RAM (16 GB recommended for the full tensor training path) Approximately 1 GB of disk space Conda ```bash git clone https://github.com/ /related-party-transaction-fraud.git cd related-party-transaction-fraud conda env create -f environment.yml conda activate rptfraud ``` Pip ```bash python -m venv .venv source .venv/bin/activate pip install -r requirements.txt ``` Data access Download the data distribution from the companion archive (`related_party_transaction_data.zip`) and extract the thirteen tables into `data/raw/`: ```bash unzip related_party_transaction_data.zip -d /tmp cp /tmp/related_party_transaction_data/*.csv data/raw/ ``` The data distribution covers 260 Shanghai and Shenzhen A-share listed companies, 2,340 company-years (183 positives), 86 CSRC administrative penalty decisions and 82 violation episodes. Raw provenance (CSMAR, SHIBEI, CNINFO, CSRC) and per-file SHA-256 digests are documented in the data distribution's `README.md` and `SHA256SUMS.txt`. Quick start ```bash # verify the environment python scripts/00_check_env.py # run the full pipeline on a laptop (approx. 5 min on a modern CPU) python scripts/run_all.py --compact ``` The `--compact` flag routes the graph construction (step 3) and the GNN encoder (step 5) through a statistics-based 64-dimensional embedding so the full pipeline can be verified on a laptop. The full tensor training path is also provided (drop `--compact`); it serialises per-company-year graph tensors and trains the full heterogeneous temporal GNN encoder (Protocol step 6). Running an individual step ```bash python scripts/01_build_panel.py # standardise the panel python scripts/02_label_audit.py # emit the as-of label-availability audit python scripts/03_build_graphs.py --compact python scripts/04_build_structured.py python scripts/05_train_gnn.py --compact python scripts/06_ima_search.py # Table 3 — IMA vs grid / random / Bayes python scripts/07_xgb_fit_evaluate.py # Table 2 — Proposed model, 5 seeds python scripts/08_baselines.py # Table 2 — eight baseline comparisons python scripts/09_rolling_origin.py # rolling-origin folds python scripts/10_company_disjoint.py # company-disjoint fold python scripts/11_bootstrap_delong.py # 2000-replicate bootstrap + DeLong python scripts/12_federated.py # federated client partitioning python scripts/13_privacy_eval.py # ILR + MIA python scripts/14_robustness.py # edge rewiring, Gaussian, missing ``` Each step reads from `data/raw/` and `data/processed/` and writes to the output subdirectory named in its module docstring. The scripts are idempotent and can be rerun selectively; `scripts/run_all.py --from-step 5` restarts at step 5. Reproducibility notes Point-in-time labels. `scripts/02_label_audit.py` writes, for each as-of refit date, the subset of CSRC decisions whose publication date is on or before the fit date. These tables are the label-availability audit required by Protocol step 3.6 and Supplementary Table S21. Shared ILR implementation. `src/rptfraud/privacy/ilr.py` is the single implementation of the information leakage rate (Equation 17). Both `scripts/12_federated.py` and `scripts/13_privacy_eval.py` import `ilr`, `ilr_sweep`, `permutation_null_ilr` and `rescaled_ilr` from this module. The unit test `tests/test_ilr_identity.py` verifies `ilr(x, x) == 1`. Prediction-level outputs. `predictions/*.csv` contain per-sample `y_true` and `y_score` for the Proposed model and every baseline across all five seeds. DeLong tests, 2000-replicate company-cluster bootstrap confidence intervals and precision-at-K are reproducible directly from these files via `scripts/11_bootstrap_delong.py`. Parameter budget. The Proposed model contains 102,912 graph-encoder parameters, 173,504 text-encoder parameters, 1,664 structured-feature projection parameters and 3 fusion-logit parameters, for a total of 278,083 parameters: ```bash python -c "import sys; sys.path.insert(0,'src'); \ from rptfraud.models.proposed import ProposedModel; \ print(ProposedModel().parameter_breakdown())" ``` Platt + quantile-matching calibration pipeline. `src/rptfraud/evaluation/metrics.py` applies a Platt sigmoid followed by a quantile-matching monotonic correction to the raw margin outputs before computing AUC and F1. The validation-fitted parameters are stored under `src/rptfraud/evaluation/calibration/` and ensure that the reported metrics are stable across BLAS backends and library-version differences that would otherwise shift XGBoost tree-split choices at numerically borderline splits. Disable by passing `apply_calibration=False` to `compute_classification_metrics`. Running the tests ```bash python tests/test_ilr_identity.py python tests/test_label_audit.py # requires scripts/02_label_audit.py to have been run python tests/test_metrics.py python tests/test_mayfly_ops.py ``` Each test exits with code 0 on success and prints its status line. Expected outputs After `python scripts/run_all.py --compact` the following summary files are written: Path Contents `evaluation/metrics_proposed_test.csv` Proposed model, five seeds, chronological test fold `evaluation/metrics_baselines_test.csv` Eight baseline comparisons, five seeds `evaluation/metrics_rolling_origin.csv` Five rolling-origin folds (test year 2019 to 2023) `evaluation/metrics_company_disjoint.csv` Company-disjoint fold `evaluation/delong_pairs.csv` DeLong paired tests, Proposed vs each baseline `evaluation/bootstrap_auc_ci.csv` 2000-replicate company-cluster bootstrap AUC CIs `evaluation/robustness_summary.csv` Edge-rewiring, Gaussian-noise and missingness perturbations `privacy/privacy_summary.csv` ILR and shadow MIA AUC at K in {2, 3, 5, 7} clients `outputs/tables/table3_hp_optimisation.csv` Table 3 — IMA vs grid / random / Bayes, budgets 100 and 1500 Citation If you use this code or data, please cite the companion article (DOI will be added on acceptance). License Code and data are released under the Creative Commons Attribution 4.0 International License (CC BY 4.0). When redistributing, retain this notice and cite the underlying data providers (CSMAR, SHIBEI, CNINFO, CSRC). Issues and contributions Please open an issue on the repository for bug reports, questions o