Equity Penetration Analysis with LLMs: A Technical Implementation Guide
This article outlines a practical engineering approach to equity penetration analysis, the recursive calculation of who ultimately owns a company through multi-layer holding structures. It covers core concepts and formal definitions, a five-layer system architecture, key algorithms with sample Python code for depth-first traversal, cycle detection, and ratio aggregation, plus reverse tracing, batch computation, and result pruning. It also details data quality checks, performance and deployment considerations, common pitfalls, and a phased rollout plan built on a clear division of labor: language models handle understanding and extraction, while deterministic code handles calculation and reconciliation.
1. Background: Why Equity Penetration Needs Engineering
In enterprise risk control, compliance review, and post-investment management, knowing who holds shares directly is far from enough. Real ownership structures are often multi-layered: a limited partnership holds shares in a target company, the partnership is funded by multiple individuals or institutions, and those institutions may in turn be backed by listed entities or state-owned platforms. What business teams actually want to know is: who are the ultimate natural-person beneficiaries, what percentage each layer holds, whether circular funding exists, and whether any chain touches a blacklisted related party.
These questions share one characteristic: recursive computation on a graph. If each entity is treated as a node and each holding relationship as a weighted directed edge, penetration becomes a graph problem of traversing outward from a starting point, multiplying ratios along the way, and aggregating at the endpoints. This does not conflict with general-purpose LLM capabilities: models are good at understanding unstructured material, generating extraction rules, and explaining calculation results, while precise recursion and numeric aggregation should still be done by deterministic code. Dividing the work between the two is the key to whether such a system can actually be deployed.
2. Core Concepts and Formal Definitions
A few concepts need to be aligned before implementation, otherwise the calculation basis will keep shifting later on.
- Node: enterprises, partnerships, natural persons, government or public institutions, distinguished by a unified identifier and type.
- Holding edge: includes the holding ratio, subscribed and paid-in capital information, holding method (direct or through contractual control), and the data date.
- Penetration path: a directed sequence from start to end, whose weight is the product of the ratios along its edges.
- Terminal: a natural person or entity that is no longer expanded outward, or that cannot be penetrated further.
- Penetration basis: whether to use subscribed or paid-in capital, and whether to rely on business registration records or contractual arrangements, must be declared explicitly at the entry point.
Formally, let the start be s and a path p = (e1, e2, …, ek); its contribution is ∏ ratio(ei), and the aggregated holding of a terminal is the sum of contributions from all reachable paths. The definition looks simple, but the real engineering difficulty concentrates on four problem types: cycles, duplicate paths, mixed calculation bases, and missing data.
3. Layered Architecture
It is advisable to split the system into five layers that communicate through explicit data contracts, so the algorithms and storage do not pollute each other.
- Data ingestion layer: connects to business-registration-style data, internal ledgers, and manually supplemented spreadsheets, and normalizes everything into nodes and edges.
- Graph storage layer: adjacency lists are enough for small and medium scale; at tens of millions of edges, consider a graph database or sharded storage.
- Computation engine layer: recursive traversal, cycle detection, ratio aggregation, and result pruning.
- Service layer: three query types — single-entity penetration, batch penetration, and reverse tracing (who indirectly holds through multiple layers).
- Explanation and audit layer: retains path evidence for every result and supports manual review and result traceback.
The direct benefit of this layering: a data source change only affects the ingestion layer, a change to the calculation basis only affects the computation engine, and audit needs are met independently by the explanation layer.
4. Key Algorithms and Sample Code
4.1 Depth-First Traversal with Ratio Multiplication
The most straightforward implementation is recursion with a path stack. The path stack also serves cycle detection: if the next node is already in the stack, circular funding has occurred, so an alert should be recorded and that branch terminated.
def penetrate(start, adj, max_depth=12):results = {} # terminal -> aggregated ratioevidence = {} # terminal -> list of pathsstack = [(start, 1.0, [start])]while stack:node, ratio, path = stack.pop()outs = adj.get(node, [])if not outs: # reached a terminalresults[node] = results.get(node, 0.0) + ratioevidence.setdefault(node, []).append(path)continueif len(path) >= max_depth: # depth guard against exploding bad datacontinuefor nxt, edge_ratio in outs:if nxt in path: # cycle detectionaudit_log(node, nxt, path)continuestack.append((nxt, ratio * edge_ratio, path + [nxt]))return results, evidence
Three reminders: max_depth is a required safeguard, since real data contains many dirty cycles; multiplying ratios with floating point introduces trailing error, so fixed-point or fractional representations are recommended for reconciliation scenarios; and evidence cannot be omitted, otherwise business teams cannot verify the conclusions.
4.2 Reverse Tracing and Batch Computation
Reverse queries only require reversing the edge directions and reusing the same traversal logic. In batch scenarios with a large number of starting points, cache results by “shared upstream”: persist the penetration results of intermediate nodes already computed, and reuse them directly when the same node appears again, which can compress repeated computation by an order of magnitude.
4.3 Result Pruning and Thresholds
In practice, extremely small ratios need to be filtered out to avoid outputting thousands of noisy paths. A common approach is two-level filtering with a per-path threshold and a terminal aggregation threshold, but the count of filtered items must be retained so the audit can state that “N tiny paths were ignored.”
5. Data Quality and Consistency Checks
Correct algorithms do not guarantee correct conclusions; the data layer often contributes most of the error. At least four types of checks are recommended:
- Total check: total outward holdings of the same entity should be close to 100%; a deviation beyond the threshold triggers a hold and generates a task for verification.
- Type check: natural-person nodes should not have outward holding edges, and partnerships should be checked for completeness of their funding structure.
- Temporal check: every edge carries effective and expiry times, and penetration should slice by the baseline date to avoid answering a current question with a historical structure.
- Basis consistency: subscribed and paid-in capital must not be mixed within one calculation, because mixing amplifies error after multi-layer multiplication.
For missing data, “explicit annotation plus interval estimation” is recommended: mark the branch as incomplete in the result and give a possible range, rather than silently treating it as zero.
6. Performance and Engineering Considerations
The complexity of recursive traversal grows exponentially with the number of paths in the worst case, so the engineering focus is pruning rather than stacking hardware. Combinable measures include: goal-directed search over the set of terminals the business cares about; precomputation and caching for high-frequency starting points; splitting the graph by connected components for parallel processing; and accumulating cycle detection results into a “known anomalies list” that can be skipped directly next time. If compute tasks are deployed on a container platform, it is recommended to separate stateless queries from batch jobs, and to use logging and monitoring with alerts to observe depth distribution, timeout rate, and cycle hit rate — these metrics reflect data health better than response time alone.
7. Common Pitfalls
- Expanding only one layer: most wrong business conclusions come from this; recursion must be enforced and the number of layers shown in the product.
- Deleting cycles as bad data: a cycle is itself an important risk signal and should be output rather than discarded.
- Ignoring contractual-control relationships: looking only at registered ratios underestimates actual control, so a relationship-type field must be kept in the model.
- Unexplainable results: giving only percentages without paths means business teams cannot trust the results and audit requirements cannot be met.
8. Suggested Rollout Path
In the first phase, use adjacency lists plus a recursive script to establish the calculation basis, and align a small set of samples with manual conclusions. In the second phase, add validation rules and evidence retention to form a reviewable query service. In the third phase, introduce caching, parallelism, and threshold strategies to handle scale, and hand entity recognition in unstructured material to an intelligent model to assist in generating candidate relationships, which then flow back to the deterministic engine for validation. This division of labor — models for understanding and extraction, code for calculation and reconciliation — both improves data entry efficiency and ensures the final numbers can be recomputed and traced.
