Engineering Equity Penetration Analysis with Large Language Models
This article explains how to build a production-ready equity penetration system, covering the problem definition, a three-part data model, graph traversal with cycle handling, scaling strategies, result explainability, quality checks, and deployment. It shows how to make calculation rules configurable, keep results traceable, and automate validation so that ownership chains and ultimate beneficiary sets remain reliable at scale.
1. Problem Definition: What Is Equity Penetration
Equity penetration means starting from an entity and traversing ownership relationships layer by layer, either upward or downward, until a specific termination condition is met. The result is a set of actual controllers, a set of ultimate beneficiaries, or a complete control chain. It is essentially a multi-hop traversal problem on a directed graph, not a simple join between two tables.
Three basic concepts must be defined clearly:
- Nodes: legal entities, natural persons, partnerships, asset management plans, and similar subjects.
- Edges: ownership relationships, carrying attributes such as ratio, subscribed/paid-in capital, and change time.
- Termination conditions: ownership ratio below a threshold, reaching a natural person, reaching a listed entity, reaching the maximum number of layers, and so on.
Engineering practice must distinguish direct ownership from indirect ownership. Indirect ownership is usually calculated by multiplying along a chain, while when multiple chains converge on the same target, a probability-style merge formula, 1 - Π(1 - single-chain ratio), is used. Inconsistent calculation rules are the root cause of most disputes over penetration results. Therefore, the first step is to express the rules as configuration rather than scattering them throughout the code.
2. Data Model Design
A three-part structure is recommended: an entity table, a relation table, and a snapshot table. The entity table stores stable identifiers and types; the relation table stores edge attributes and effective intervals; the snapshot table stores materialized results at a given point in time for auditing and retrospection.
-- Entity tableCREATE TABLE entity (entity_id BIGINT PRIMARY KEY,unified_code VARCHAR(64) UNIQUE, -- Unified identifier; nullable when missingname VARCHAR(256) NOT NULL,entity_type SMALLINT NOT NULL -- 1 legal entity, 2 natural person, 3 partnership, 4 asset management plan);-- Relation table (edges)CREATE TABLE share_relation (src_id BIGINT NOT NULL,dst_id BIGINT NOT NULL,ratio DECIMAL(10,6) NOT NULL, -- 0~1effective_from DATE NOT NULL,effective_to DATE,source_type SMALLINT, -- Data source markerPRIMARY KEY (src_id, dst_id, effective_from));-- Penetration snapshotCREATE TABLE penetration_snapshot (task_id VARCHAR(64),start_id BIGINT,as_of_date DATE,path_json TEXT,merged_ratio DECIMAL(10,6),PRIMARY KEY (task_id, start_id));
There are three design points. First, all ratios should use fixed-point numbers rather than floating-point numbers to avoid accumulation errors from multiplication. Second, relations must carry time intervals, because penetration is inherently a “view as of a given date” problem. Third, data source markers should be retained so that, when disagreements arise, the issue can be traced to a specific source.
3. Traversal Algorithm and Cycle Handling
The most straightforward implementation is depth-first search, but real equity graphs contain many cycles (cross-shareholding, nested employee stock ownership platforms), which must be handled explicitly.
def penetrate(graph, start, as_of, threshold=0.01, max_depth=8):results = {} # terminal node -> merged ratiostack = [(start, 1.0, [start])]while stack:node, acc, path = stack.pop()if len(path) > max_depth:continuefor edge in graph.out_edges(node, as_of):nxt, ratio = edge.dst, edge.ratioif nxt in path: # Cycle: truncate and record a markercontinuenew_acc = acc * ratioif new_acc < threshold: # Pruningcontinueif graph.is_terminal(nxt):merged = results.get(nxt, 0.0)results[nxt] = merged + new_acc - merged * new_accelse:stack.append((nxt, new_acc, path + [nxt]))return results
Three engineering lessons apply here. After truncating a cycle, add a marker instead of silently dropping it; otherwise, it becomes impossible to explain why a certain chain does not appear. Threshold pruning can significantly reduce the search space, but the threshold must be configurable and output together with the results. The maximum layer limit is a fallback; normal data should not trigger it frequently, and frequent triggering indicates data quality problems.
4. Performance and Scalability
When nodes reach the millions and edges reach the tens of millions, recursive queries in a relational database become a bottleneck. The available options, in increasing order of complexity, are:
- Recursive common table expressions: simple to implement and suitable for small to medium scale and offline batch processing, but performance degrades noticeably at greater depth.
- Materialized path tables: reachability relations for a limited number of layers are expanded in advance, making queries very fast, at the cost of storage expansion and update overhead.
- Graph databases or graph computing frameworks: suitable for deep, variable queries and online interactive analysis.
A practical compromise is to use a layered approach: hot data (recent changes, high-frequency entities) is served by an in-memory graph structure for online queries, while the full dataset goes through offline batch processing to generate snapshots, with the two aligned through the snapshot table. The cache key is best designed as (start_id, as_of_date, rule version). When the rule version changes, the entire cache must be invalidated; otherwise, a subtle defect arises from mixing old and new rules.
5. Explainability and Quality Validation
If penetration results cannot be explained, the business side will not trust them. It is recommended to output three things: a complete list of chains, the multiplication process for each chain, and statistics on the reasons for pruning and truncation. At the same time, four types of automated validation should be established:
- Consistency check: whether the sum of chain ratios is consistent with the merged ratio.
- Coverage check: the proportion of entities missing a unified identifier; if the proportion is too high, the data must be completed first.
- Cycle detection report: count cycles per entity to identify data entry errors.
- Regression baseline: fix a batch of sample entities, compare differences after each rule or data change, and perform manual review.
6. Deployment and Operations
For production, tasks can be split into a five-stage pipeline: collection, cleaning, graph construction, penetration computation, and result distribution. The stages are decoupled through a message queue, computation tasks are containerized and elastically scaled by a container platform, raw and snapshot data are stored in object storage, and runtime metrics are connected to logging services and monitoring alerts. Baidu AI Cloud offers corresponding capabilities in these general categories, and teams can freely combine them according to their existing technology stack, avoiding strong coupling to a specific framework.
7. Common Pitfalls
The first pitfall is treating penetration as finished once a natural person is found, ignoring scenarios where holdings below the threshold still need to be disclosed. The second is using floating-point multiplication, which leads to disputes over rounding differences. The third is not recording the time dimension, so historical ownership changes cannot be reproduced. The fourth is performing only forward penetration while ignoring the reverse question of “who ultimately benefits,” causing two types of problems to share one set of rules and contaminate each other. Making rules configurable, keeping the process traceable, and automating validation are the three things that must be done well before equity penetration capability is truly production-ready.
