Equity Penetration Algorithm Implementation and Graph Construction: Engineering Practices
This article explains how to implement equity penetration for ownership analysis, covering graph-based data modeling, entity disambiguation, multi-path ownership calculation, cycle handling, precision control, graph database usage, incremental updates, visualization, and API output. It also highlights common pitfalls and engineering considerations for building a maintainable equity penetration system in due diligence, risk control, related-party identification, and compliance scenarios.
1. Business Value and Two Basic Types of Equity Penetration
In corporate due diligence, risk control, related-party transaction identification, and tender or procurement compliance, relying only on direct shareholder information from company registry filings is often not enough to understand the real control relationships. Common structures such as multi-layer shareholding, cross-shareholding, and nested limited partnerships can make the ultimate beneficiary and actual control unclear.
Equity penetration analysis works by tracing shareholding relationships layer by layer. It can calculate the effective interest ratio of one entity in another entity, or identify the ultimate beneficiaries of a company.
Equity penetration is usually divided into two directions:
- Upward penetration: Starting from the target company, trace shareholder relationships upward until reaching terminal entities such as natural persons, state-owned entities, or listed companies. It answers: “Who ultimately owns this company?”
- Downward penetration: Starting from a shareholder or group, expand along investment relationships downward and calculate its direct or indirect shareholding ratio in member companies at each level. It answers: “How much interest does this entity hold in companies across different levels?”
1.1 Four Key Challenges in Penetration Calculation
- Multi-path aggregation: A shareholder may indirectly hold shares in the same company through multiple paths. The result must be calculated path by path and then summed. Simply taking one path can produce an incorrect conclusion.
- Circular shareholding: Situations such as A and B holding shares in each other, or cyclical shareholding within a corporate group, do exist in practice. A naive recursive implementation may fall into an infinite loop, so cycles must be handled at the algorithm level.
- Differences in disclosure scope: Differences in how public disclosure information is reported, differences between subscribed capital and paid-in capital, and timing gaps in shareholding changes can all affect the calculation results.
- Scale and timeliness: A large group’s outbound investments may involve hundreds or thousands of entities. The number of relationships grows quickly, so query performance and data freshness need to be considered.
2. Data Foundation: Graph Modeling of Entities and Relationships
2.1 Node and Edge Definitions
Equity relationships can be modeled as a weighted directed graph. Nodes represent entities such as companies or individuals, and edges represent shareholding relationships. The weight on an edge represents the shareholding ratio. To facilitate calculation and verification, each edge should include at least the following fields:
{"from": "Company A","to": "Company B","ratio": 0.60,"type": "equity","effective_date": "2024-03-01","source": "public disclosure","confidence": 0.98}
ratio: Shareholding ratio, represented as a decimal between 0 and 1.type: Relationship type, such as equity, voting rights delegation, or acting-in-concert arrangements.effective_date: Effective date, used to reconstruct the historical ownership structure at a specific point in time.source: Data source, used for traceability and verification.confidence: Confidence level of the data source, used to handle low-confidence records differently.
It is recommended to store nodes and edges in a graph database, while retaining a versioned detail table in a relational database for auditing and historical tracing.
2.2 Data Acquisition and Entity Disambiguation
Equity data mainly comes from public channels such as company registry filings, corporate annual reports, and disclosures from listed companies. This information is mostly unstructured text or semi-structured tables and needs to be extracted and cleaned first.
With improved document understanding in large language models, the cost of extracting shareholder names and ownership ratios from long texts such as announcements and articles of association has decreased significantly. However, this type of extraction is assistive. Critical fields should still be confirmed through structured sources and cross-validation.
Entity disambiguation is a prerequisite for data quality. The same company may appear under different names across sources, including full names, abbreviations, historical names, or even names that are similar but belong to completely different entities. The following matching order is recommended:
- Prefer unique identifiers such as unified social credit codes or other official registration numbers where available.
- Next, compare attributes such as registered address, legal representative, and incorporation date.
- Finally, use name-text similarity algorithms as supplementary support.
After matching, assign a globally unique ID to each real-world entity. All subsequent calculations should be based on this ID to avoid confusion between entities with similar names.
2.3 Data Quality Checks
Before data is ingested into the system, at least the following checks should be completed:
- Ratio validity: The shareholding ratio must be between 0 and 1. For the same invested company, the sum of shareholder ratios should be close to 1. Records with obvious deviations should be marked as anomalies.
- Consistency between capital contribution and ratio: Compare “capital contribution ÷ registered capital” with the disclosed shareholding ratio. Records with differences beyond a threshold should be manually reviewed.
- Time consistency: Shareholding changes should have corresponding effective times. Logical errors such as “a shareholder exists before the invested company is established” should be avoided.
- Completeness: Measure the proportion of isolated nodes and companies with missing shareholder information as an indicator of data coverage.
3. Core Algorithm: Calculating Penetration Ratios
3.1 Calculation Principle
Suppose a path is P = (v₀, v₁, …, vₙ), where v₀ is the starting shareholder and vₙ is the target company whose ownership is being penetrated. Let rᵢ be the shareholding ratio on edge eᵢ. The penetration ratio of this path is defined as the product of all edge ratios:
share(P) = r₁ × r₂ × … × rₙ
The total penetration ratio from the starting shareholder v₀ to the target company vₙ is the sum of the penetration ratios of all simple paths:
total(v₀ → vₙ) = Σ share(P)
Note that the summation only applies to simple paths, meaning paths that do not visit the same node more than once. If repeated nodes are not restricted, circular shareholding may cause the same path to extend indefinitely, making the result meaningless.
3.2 Example: Multi-Path Aggregation
The following example illustrates how multiple paths are calculated:
Company A ──60%──> Company B ──100%──> Company DCompany A ──40%──> Company C ──50%───> Company D
- Company A indirectly holds Company D through Company B: 60% × 100% = 60%;
- Company A indirectly holds Company D through Company C: 40% × 50% = 20%;
- Therefore, the indirect shareholding ratio of Company A in Company D is 60% + 20% = 80%.
If one mechanically follows only one path to the end, the other ownership chain will be missed, leading to an incorrect conclusion.
3.3 Recursive Implementation Example
The following example implements the core logic for calculating penetration results along shareholding chains:
# Parameter notes:# adjacency: Adjacency list {shareholder ID: [(invested company ID, shareholding ratio), ...]}# start: Traversal start# target: Traversal end; if empty, traverse until terminal entities# threshold: Pruning threshold; branches below this penetration ratio are not expanded furtherfunction penetrate(start, target, threshold):result = empty map # Result: terminal node -> accumulated penetration ratiostack = [(start, 1.0, [start])] # (current node, current weight, path)while stack is not empty:(node, weight, path) = stack.pop()children = adjacency.get(node, [])isTerminal = (children is empty)or (target is not null and node == target)or (path.length > MAX_DEPTH)if isTerminal:result[node] += weightcontinuefor each (child, ratio) in children:if child in path: # Cycle detectedresult[node] += weight # Attribute the cycle weight to the current nodecontinuenewWeight = weight * ratioif newWeight < threshold: # Pruningcontinuestack.push((child, newWeight, path + [child]))return normalize(result)
After traversal, if the sum of ratios in the result is less than 1 due to cycles or pruning, it can be normalized to 1 to represent the distribution of the “attributable portion.” The original total should also be retained in the result for transparency.
3.4 Implementation Considerations
- Termination conditions: It is best to use an explicit set of terminal entities, such as natural persons, state-owned entities, and listed companies. This gives the traversal clear endpoints and makes the computation controllable. If traversal must continue until nodes with no upper-level shareholders are reached, a maximum depth limit should be set to avoid infinite recursion caused by abnormal data.
- Cycle handling: Use the current path set to determine whether a cycle exists. Once a cycle is detected, add the weight of that branch to the current node, indicating that this portion of interest is ultimately held among entities within the cycle.
- Precision control: Shareholding ratios are calculated through multiplication. Using floating-point numbers can accumulate errors on deep paths. It is recommended to use a high-precision decimal type, or represent ratios as integers scaled to ten-thousandths, and output results with a fixed precision, such as four decimal places.
- Pruning optimization: When the current weight is below a threshold, such as 0.01%, its impact on the result can be considered acceptable, and that branch can be terminated directly. The threshold should be determined based on business precision requirements, and the total pruned weight should be recorded in the result.
- Recursion versus iteration: The example uses an explicit stack to implement depth-first traversal. This avoids the risk of stack overflow caused by too many recursive function calls.
3.5 Computational Complexity and Optimization
Suppose the graph has V nodes, E edges, and depth D. In the worst case, penetration calculation requires enumerating a large number of simple paths, and complexity grows rapidly with graph density and depth. The following optimizations can be applied:
- Result caching: The same node may be repeatedly visited in calculations with different starting points. Results can be cached by “start node + time snapshot.”
- Pre-built adjacency list: Maintain a sparse adjacency list in memory to avoid repeated database access during traversal.
- Layered and batched processing: For offline computation, split tasks by corporate group or connected component, then merge the results.
- Incremental calculation: Recompute only the subgraphs affected by changes. Specifically, use a reverse adjacency list to find all potentially affected starting nodes, and run penetration only for those nodes.
4. Engineering Implementation: From Algorithm to Service
4.1 Four Core Engineering Issues
1) Circular Shareholding and Cross-Shareholding
At the algorithm level, path deduplication solves the infinite-loop problem. However, further business interpretation is needed.
For structures where A and B hold shares in each other, it is necessary to distinguish between:
- Interest attribution: The ratio of A’s holding in B and B’s holding in A may differ and should be calculated separately.
- Control attribution: Circular shareholding may amplify or dilute one party’s actual control. This should be assessed together with factors such as board composition and voting arrangements.
2) Aggregation of Indirect Shareholding
In addition to the multi-path summation described earlier, attention must be paid to minority interest calculations. Suppose a parent company directly holds 80% of a subsidiary, while the remaining 20% is held by external shareholders. In the subsidiary’s net profit, 80% belongs to the parent company, and the remaining portion is recorded as minority interest. When preparing consolidated financial statements, this portion should be presented separately and cannot simply be consolidated at 100%.
3) Precision of Shareholding Ratios
In deeply nested structures, multiplying ratios level by level causes the number of decimal places to increase quickly. The following strategies are recommended:
- Use high-precision numeric types internally.
- Retain 2 to 4 decimal places when displaying results, depending on business needs.
- Validate the sum of ratios and raise alerts if deviations exceed the allowed error tolerance.
4) Detection of Circular Dependencies
If traversal is implemented recursively, circular dependencies may cause recursion never to return. For engineering implementation, the following approach is recommended:
- Maintain a set of nodes in the current traversal path.
- When an already visited node is encountered, record the cycle and add the weight of that branch to the current node.
- Perform strongly connected component analysis on the whole graph in advance to identify all cycles and output a cycle list for business review.
# Tarjan's algorithm for strongly connected components (illustrative)index = 0stack = []on_stack = set()indices = {}lowlink = {}sccs = []def strongconnect(v):global indexindices[v] = lowlink[v] = indexindex += 1stack.append(v)on_stack.add(v)for w in adjacency[v]:if w not in indices:strongconnect(w)lowlink[v] = min(lowlink[v], lowlink[w])elif w in on_stack:lowlink[v] = min(lowlink[v], indices[w])if lowlink[v] == indices[v]:scc = []while True:w = stack.pop()on_stack.remove(w)scc.append(w)if w == v:breaksccs.append(scc)for v in adjacency:if v not in indices:strongconnect(v)# Strongly connected components with more than one node, or self-loops, are cyclescycles = [scc for scc in sccs if len(scc) > 1 or (len(scc) == 1 and scc[0] in adjacency[scc[0]])]
Identifying cycles is not only about preventing infinite loops; cycles can also serve as risk signals. Frequently changing cross-shareholding or complex circular structures are often associated with benefit transfer or hidden control, and deserve special attention in risk control.
4.2 Event-Driven Updates and Incremental Calculation
Equity data is not static. Events such as capital increases, share transfers, mergers, and divisions can change the structure of the graph. Therefore, an event-driven update mechanism should be established:
- Change capture: Use data synchronization tasks to periodically compare equity snapshots and identify added, deleted, or modified relationships.
- Impact analysis: Based on the changed edges, use a reverse adjacency list to find all potentially affected starting nodes.
- Incremental recalculation: Re-run penetration only for affected starting nodes and write the results into a versioned table.
- Version traceability: Generate a new calculation version for each recalculation, recording the input data snapshot ID and algorithm version to ensure that results are traceable and reproducible.
4.3 Integration with Graph Databases
Equity penetration queries are typical multi-hop traversal scenarios. Relational databases often experience rapid performance degradation when performing multiple-layer joins. It is recommended to store nodes and edges in a graph database and use graph traversal capabilities for multi-hop queries. The following points should also be considered:
- Index design: Create indexes on node IDs, relationship types, and effective dates to improve traversal efficiency.
- Traversal depth limits: Set a maximum hop count at the query layer to prevent abnormal data from causing excessively long traversals.
- Caching of hot results: Cache penetration results for high-frequency queries to reduce computational pressure.
- Read/write separation: Deploy offline computation and online queries separately to avoid interference.
4.4 Incremental Updates and Visualization
Visualization is the most intuitive way to present equity penetration results. A hierarchical directed graph layout is recommended:
- Node coloring: Distinguish entities by type, such as natural persons, companies, funds, and state-owned entities.
- Edge labels: Display both direct shareholding ratios and cumulative penetration ratios.
- Interactive capabilities: Support clicking a node to view its penetration details, as well as expanding or collapsing subgraphs.
For penetration results, it is recommended to provide two views:
- Path view: Show the ratio multiplication process for each chain, making manual verification easier.
- Summary view: Aggregate results by ultimate entities and present the combined interest ratio for each terminal entity.
4.5 Service Output
Penetration results usually need to be delivered to downstream systems through APIs or files. Clear data structures should be defined, for example:
{"start": "Company A","target": "Company D","direct_ratio": 0.0,"indirect_ratio": 0.80,"version": "2025-01-01","paths": [{"chain": ["Company A", "Company B", "Company D"], "ratio": 0.60},{"chain": ["Company A", "Company C", "Company D"], "ratio": 0.20}]}
The output should include the calculation version number and data snapshot time so that downstream systems can assess the freshness and applicability of the results.
5. Common Pitfalls and Precautions
- Treating direct shareholding as final ownership: In multi-layer structures, the direct shareholding ratio can differ significantly from the final penetration ratio. Conclusions should only be drawn after completing the penetration calculation.
- Ignoring minority interest: In consolidated financial statements, the subsidiary’s net profit should be allocated based on the parent company’s shareholding ratio, with minority interests presented separately.
- Infinite loops caused by unhandled cycles: Recursive implementations must include path deduplication or a maximum depth limit.
- Precision loss: After multiplying ratios along long chains, the result may become very small. Using low-precision numeric types can distort the result.
- Ignoring data timeliness: Equity changes are dynamic. Conclusions should indicate the data cutoff time.
- Confusing control rights with income rights: A high shareholding ratio does not necessarily mean strong control. Voting rights, board seats, and other factors must also be considered.
6. Conclusion
The core challenges of equity penetration lie in both calculation accuracy and engineering maintainability under complex shareholding structures. Starting from data modeling, this article introduces the calculation principles of penetration ratios, example code, and engineering recommendations. It focuses on key issues such as circular shareholding, precision control, incremental updates, and visualization.
In practical implementation, the following points should be emphasized:
- Establish a unique entity identifier system and perform entity disambiguation.
- Use high-precision numeric types and validate results.
- Correctly handle cycles through path deduplication.
- Use event-driven mechanisms to support incremental updates.
- Retain calculation version and data snapshot information in outputs.
When building such systems in the cloud, Baidu AI Cloud can be considered where available, especially for capabilities such as graph databases, big data computing, object storage, logging services, and monitoring/alerting. These capabilities can help reduce infrastructure operations costs and allow teams to focus on equity data governance and business logic.
Equity penetration is not only a technical implementation but also a reflection of data governance capability. Only by combining data quality, algorithm accuracy, and engineering efficiency can such systems truly create value in risk control, compliance, and business analysis scenarios.
