Engineering Equity Penetration Analysis with Large Language Models

    This article explains how to turn equity penetration analysis into a graph computation problem and build it in production. It covers the data model with node, edge, and caliber-version tables, recursive CTE traversal with depth limits and cycle detection, handling of circular and cross-shareholding, termination rules, result validation and explainability, and practical performance guidance such as indexing, caching, incremental refresh, and resource isolation. Readers will also find common pitfalls to avoid, including floating-point ratios, missing time-point filtering, and discarding cycles.

    1. The Core Problem: Reducing Equity Penetration to Graph Computation

    Equity penetration analysis answers one central question: given a target entity, trace upward through all of its shareholders until you reach natural persons, state-owned entities, listed companies, or another designated terminal type, while aggregating the shareholding ratio and the ultimate beneficial ratio along every path. This is not a table lookup. It is a multi-path traversal on a directed graph with path-wise product accumulation.

    In the model, there are typically two node types (entities and natural persons) and two edge types (direct and indirect shareholding), with the edge weight being the shareholding ratio (a decimal between 0 and 1). Let the target node be T and a path be T <- A <- B <- C. The path contribution is the product of the ratios along the edges, and the ultimate beneficial ratio is the sum of contributions across all paths.

    1. ultimate_benefit(T) = Σ over paths( Π edge weight )

    Two general constraints must be emphasized. First, the ratio definition must be consistent (whether concert parties are included, and whether ratios are based on subscribed or paid-in capital). Second, circular shareholding must be handled, or the recursion will not converge.

    2. Data Model Design: Fix the Definition First, Then Query

    A three-layer structure is recommended: a node table, an edge table, and a caliber-version table. The node table stores entity type and terminal flags; the edge table stores the ratio, acquisition date, expiry date, and source data batch; the caliber-version table records the terminal type set and thresholds used in a given calculation.

    1. -- Illustrative structure, only to convey the modeling idea
    2. CREATE TABLE node(
    3. id BIGINT PRIMARY KEY,
    4. type STRING, -- COMPANY / PERSON / STATE / LISTED
    5. is_terminal BOOLEAN
    6. );
    7. CREATE TABLE edge(
    8. src BIGINT, dst BIGINT,
    9. ratio DECIMAL(9,6), -- 0~1
    10. valid_from DATE, valid_to DATE,
    11. batch_id STRING
    12. );

    In engineering practice, the time point must be treated as a first-class citizen: equity changes over time, and penetration results for the same target can differ completely across dates. Queries must therefore filter with as_of_date using valid_from <= as_of_date < valid_to; otherwise results are neither reproducible nor auditable.

    3. Recursive Query Implementation: From Naive Recursion to Controlled Depth

    Most relational databases support recursive common table expressions, which can directly express multi-path traversal and use a depth column for pruning and cycle detection.

    1. WITH RECURSIVE walk(root, cur, depth, prod, path) AS (
    2. SELECT id, id, 0, CAST(1 AS DECIMAL(9,6)), ARRAY[id] FROM node WHERE id = :target
    3. UNION ALL
    4. SELECT w.root, e.src, w.depth + 1,
    5. w.prod * e.ratio,
    6. array_append(w.path, e.src)
    7. FROM walk w JOIN edge e ON e.dst = w.cur
    8. WHERE w.depth < :max_depth
    9. AND NOT e.src = ANY(w.path) -- cycle detection
    10. AND e.valid_from <= :as_of_date AND e.valid_to > :as_of_date
    11. )
    12. SELECT cur AS shareholder, SUM(prod) AS benefit
    13. FROM walk WHERE depth > 0 GROUP BY cur;

    There are three key engineering points. First, max_depth must be set (commonly 8–12) to prevent blowups caused by anomalous data. Second, cycle detection should use the path array rather than a global visited set, so that distinct paths are not pruned by mistake. Third, prod should use fixed-point decimals rather than floating point to avoid accumulated ratio errors.

    When the graph is large (over a million edges), relational recursion hits a performance bottleneck. In that case, move to a graph processing engine or a distributed graph computing framework, expand in parallel using layered BFS with prefix products, and perform deduplication and merging at each layer.

    4. Cycles, Cross-Shareholding, and Termination Conditions

    Circular shareholding (A holds B, B holds A) is common in practice. There are two handling strategies. One is path-level pruning (as above), which only guarantees no repetition within a single path. The other is strongly connected component compression, which collapses nodes inside a cycle into a super node before computing, suitable for scenarios that need an “overall caliber.”

    Termination conditions should be configured explicitly: whether to continue upward for natural persons, state-owned entities, listed companies, employee stock ownership platforms, and so on; for fund products, also decide whether to penetrate to unit holders. Different terminal types can produce vastly different results, so the terminal set must be written into the caliber version and stored together with the results.

    5. Result Validation and Explainability

    Penetration results must be explainable: every final ratio should be traceable back to a specific set of paths. It is recommended to output three artifacts — the aggregated result, the path details, and the data batch ID. Validation should cover at least four checks: whether the ratios sum to more than 100% (indicating double counting), whether there are dangling nodes that were not terminated, whether ratios inside cycles are counted more than once, and whether the difference from the previous batch exceeds a threshold.

    1. Example validation rules
    2. 1) SUM(benefit) <= 1 + ε
    3. 2) all leaf nodes have is_terminal = true
    4. 3) nodes inside a cycle are counted only once
    5. 4) a batch-to-batch difference > 5% triggers manual review

    6. Performance and Production Recommendations

    First, indexing: build an index on the edge table by dst, valid_from and on the node table by type. Second, caching: materialize results for unchanged historical time points, keyed by target + as_of_date + caliber version. Third, layered computation: refresh incrementally one hop at a time, then two hops, to avoid full recomputation. Fourth, resource isolation: place penetration computation in a separate compute queue so it does not degrade online queries.

    For cloud deployment, container platforms can host compute tasks, object storage can hold batch snapshots, message queues can distribute tasks, and logging and monitoring with alerting can track failure rates and latency. These are generic capability categories and do not point to any specific product.

    7. Common Pitfalls

    Pitfall one: storing ratios as floating point, causing the total to drift. Pitfall two: doing only single-point recursion with no depth limit, so dirty data leads to timeouts. Pitfall three: ignoring the time point and producing conclusions that cannot be reproduced. Pitfall four: treating cycles as anomalies and dropping them outright, causing missing ratios. Pitfall five: providing only aggregates without paths, making results unauditable. The prerequisite for avoiding these problems is to manage the caliber, the time point, and the paths as first-class data assets.