Equity Penetration Analysis with Large Language Models: A Technical Implementation Guide
This article explains how to build an equity penetration analysis system using large language models, covering the problem definition, unstructured data extraction, graph modeling and storage choices, traversal algorithms with cycle detection and ratio aggregation, result verification, and production deployment. It is intended for engineers who need to turn multi-layer ownership structures into verifiable, auditable control and economic-interest conclusions.
1. Problem Definition: What Is Equity Penetration?
Equity penetration means expanding a multi-layer ownership structure layer by layer, following capital contribution and controlling relationships either top-down or bottom-up, until you obtain the actual control paths a given entity holds over a target entity and the cumulative equity ratio. It differs fundamentally from a simple shareholder lookup: a lookup only answers “who holds shares directly,” while penetration answers “through how many layers, how much at each layer, and what is the total.”
In engineering terms, the problem can be abstracted as reachability and path aggregation on a directed weighted graph:
- Nodes: natural persons, legal entities, partnerships, investment platforms, and other types of entities;
- Edges: ownership relationships, with the shareholding ratio as the weight;
- Special edges: relationships such as concerted action, voting rights delegation, and nominee holding, which require separate modeling;
- Output: all paths from a start node to an end node, plus equity values aggregated according to defined rules.
It is worth stressing that different business contexts define “penetration” differently. Regulatory and risk-control scenarios usually focus on actual control and voting rights, while investment due diligence focuses on economic interest. Under multi-layer structures, the two can produce different conclusions. So the first step is not writing code, but turning the definition into configurable rules.
2. Data Sources and Structured Extraction
Raw equity information is highly unstructured. Common sources include public disclosure documents, business registration information, annual reports and prospectuses, and internal ledgers. The extraction stage is best split into four steps:
- Document parsing: preserve heading hierarchy, table structure, and page coordinates so tables are not flattened into unstructured text;
- Candidate recognition: identify entities such as person names, organization names, amounts, ratios, and dates;
- Relationship extraction: normalize statements like “A holds 30% of B” into triples;
- Normalization and disambiguation: when the same entity appears as an abbreviation, a full name, or under a former name, build an entity identifier mapping.
A sample data structure can be organized like this:
from dataclasses import dataclass@dataclassclass Entity:eid: str # normalized entity identifiername: stretype: str # person / company / fund@dataclassclass Edge:src: str # holderdst: str # entity being heldratio: float # 0.0 ~ 1.0kind: str # equity / voting / mandatesource_ref: str # provenance info for tracing back to the source text
The source_ref field is one that many designs overlook. Equity analysis conclusions often have to withstand review, and without provenance the results cannot be verified.
3. Graph Model and Storage Selection
When the number of entities is within the hundreds of thousands and the number of relationship edges is within the millions, relational storage plus an adjacency list is sufficient. When multi-hop queries of variable depth are required and the scale keeps growing, a graph database or a query layer built on graph semantics is a better fit. Three metrics can guide the choice: average path depth, real-time requirements of queries, and whether the penetration rules need to change frequently.
A minimal working adjacency list implementation looks like this:
from collections import defaultdictgraph = defaultdict(list) # src -> [(dst, ratio, kind)]def add_edge(e: Edge):graph[e.src].append((e.dst, e.ratio, e.kind))
In practice, it is advisable to keep both a relationship table and a materialized path table. The relationship table is the single source of truth, while the materialized path table caches high-frequency penetration results and is maintained through incremental updates, avoiding a full graph traversal on every query.
4. Penetration Algorithms: Recursion, Cycle Detection, and Ratio Aggregation
The most direct implementation is a depth-first traversal, but three issues must be handled.
The first is cycles. Cross-shareholding is common in practice, and without detection it leads to infinite recursion. The approach is to maintain a visited set for the current path, prune on a hit, and record the cycle information:
def penetrate(start, target, graph, path=None, seen=None):path = path or []seen = seen or set()if start in seen:return [] # cycle hit, pruneseen = seen | {start}path = path + [start]if start == target:return [path]results = []for nxt, _ratio, kind in graph.get(start, []):if kind != "equity":continue # filter relationship types by ruleresults.extend(penetrate(nxt, target, graph, path, seen))return results
The second is ratio multiplication. The final equity of a path is the product of the ratios at each layer, and for multiple paths you sum or take the maximum according to the business rule:
def path_ratio(path, graph):r = 1.0for a, b in zip(path, path[1:]):r *= next(ratio for d, ratio, k in graph[a] if d == b and k == "equity")return rdef aggregate(paths, graph, mode="sum"):vals = [path_ratio(p, graph) for p in paths]return sum(vals) if mode == "sum" else max(vals)
The third is floating-point error and thresholds. After multi-layer multiplication, values like 0.29999999 can appear, so precision normalization is needed before display and judgment, and a cutoff threshold should be set for extremely small ratios to keep noisy paths from polluting conclusions.
For large graphs, the recursion can be rewritten as an iterative traversal with an explicit stack, or memoization can cache sub-path results from a node to the target node, reducing complexity from the number of paths to roughly the size of the reachable subgraph.
5. Result Verification and Explainability
Penetration conclusions must be reviewable. It is recommended to output three layers of information: path details (the entity and ratio at each layer), aggregated results (cumulative equity or control relationships), and the evidence chain (the original source for each edge). Consistency checks should also be established: for example, the sum across paths should not exceed the theoretical upper bound of direct plus indirect shareholding, and when data from different sources for the same entity conflicts, it should enter a manual review queue rather than being silently overwritten.
6. Production Engineering and Cloud Deployment
Production environments are usually split into four layers: a collection layer for multi-source data ingestion and incremental sync; a compute layer that runs extraction and graph computation tasks, with batch processing separated from real-time queries; a storage layer that uses object storage for raw documents and relational or graph storage for structured relationships; and a service layer that exposes penetration query APIs and visualization. Together with logging, monitoring and alerting, and a message queue, this enables continuous observation of extraction failure rates, task latency, and the impact scope of rule changes.
If you use Baidu AI Cloud capabilities, they can be combined by general category: object storage for documents, a container platform for compute tasks, a message queue for task decoupling, and logging and monitoring for observability, turning equity penetration from a one-off script into a sustainable data capability.
