Screen stocks against their industry peers
An industry-relative stock screen calculates a comparison threshold inside each declared peer group, then applies the same relative rule to each stock. It does not apply one market-wide PE cutoff and call the result industry adjusted. The output needs the group definition, valid observation count, threshold and each stock’s disposition, so a researcher can reconstruct why a company entered.
This guide uses fictional positive PE observations and synthetic industry labels. It actually computes group medians and applies a less-than-or-equal screening rule. It does not establish that low relative PE predicts returns or that CoTrading already offers industry screening. A-shares, Hong Kong and US stocks need separately confirmed classification versions and comparable data before this method can be transferred.
Freeze classification and measurement together
Begin with a dated stock universe, one classification system and a chosen level in its hierarchy. Mixing a broad sector for one company with a narrow subindustry for another produces inconsistent comparison groups. Store the classification identifier, version and assignment date beside each stock. Keep unclassified records visible instead of assigning them to a convenient large group.
The SEC’s SIC list is an official example of business classifications used in EDGAR filings. It is not a universal mapping for every market or a guarantee that each code represents an economically homogeneous peer set. Our labels Tech, Utility and Rare are invented groups, not actual SIC codes or recommendations to use that taxonomy.
Choose a comparable metric and its eligibility rules before grouping. Here PE must be observed, positive and measured under one agreed earnings convention. A negative PE is not treated as an exceptionally cheap observation. Missing PE does not enter the median denominator, but the stock remains in the original-universe count and receives a missing-metric state.
Define the relative rule and minimum size
The operational rule is “select stocks with positive PE at or below their industry’s valid-observation median.” The example requires at least three valid observations before calculating a usable threshold. Three is a declared demonstration gate, not a statistically validated reliability standard. Real group-size requirements should reflect the research purpose, coverage quality and concentration of the peer set.
The median includes the screened company’s own eligible observation. A leave-one-out comparison would be a different method and needs separate thresholds for each company. Specify that choice rather than letting implementation details decide it. Also declare how an exact tie at the median behaves; this example includes equality.
| Group | Observed positive PE values | Valid count | Threshold | Treatment |
|---|---|---|---|---|
| Tech | 10, 20, 30 | 3 | 20 | calculate |
| Utility | 4, 6, 8 | 3 | 6 | calculate |
| Rare | 2, 4 | 2 | unavailable | withhold |
Tech additionally contains T4 with missing PE, so its total membership is four while the valid denominator is three. M1 has PE 12 but no industry. Neither record disappears merely because it cannot contribute to a group calculation.
Calculate thresholds before selecting stocks
First collect eligible numeric observations by group. Only groups meeting the minimum receive a threshold. Then evaluate every original row against the threshold map. This two-pass operation prevents row order from changing the median or letting early rows be screened against an incomplete group.
groups = defaultdict(list)
for symbol, industry, pe in records:
if industry is not None and pe is not None and D(pe) > 0:
groups[industry].append(D(pe))
thresholds = {group: median(values)
for group, values in groups.items()
if len(values) >= minimum}
Python’s statistics reference documents median calculation, including the average of two middle observations for an even-sized group. Keep the median convention in the method record. A different quantile algorithm, interpolation rule or missing-value policy can change threshold membership even with the same raw values.
Download the complete example. Use Python 3.12+ with the standard library and synthetic data; run python R520.py. The authoring source is docs/growth/research/round-5/examples/R520.py.
Actual output selects T1 and T2 from Tech and U1 and U2 from Utility. T3 and U3 fail their relative thresholds. R1 and R2 receive small_group, M1 receives missing_industry and T4 receives missing_metric. Assertions verify medians 20 and 6, valid counts 3, 3 and 2, and identical results after reversing the input rows.
Interpret a relative pass without a cross-industry claim
T2 passes at PE 20 because it is at its group’s median. U3 fails at PE 8 because it is above its group’s median of 6. This does not imply that T2 is cheaper than U3 in an absolute economic sense. The screen asks about position within a declared peer set, not which business deserves the highest valuation across industries.
Keep the actual PE, group threshold and group denominator on each result row. A label such as “industry value pass” without those details hides the comparison being made. If the researcher later changes the industry level, recalculate thresholds and reopen the result instead of retaining the old pass flag under a new label.
Relative selection also does not remove accounting differences within an industry. Verify fiscal periods, extraordinary items, earnings normalization and relevant business-model differences. Classification provides a grouping rule; it does not certify that every member is a perfect comparable.
Test the small-group counterexample
Rare’s two observed PEs could produce a numerical median of 3. The fixture deliberately withholds that threshold because the group fails the predeclared minimum. Automatically selecting R1 at PE 2 would violate the operational policy, even though the arithmetic is easy. Keep both Rare stocks pending group review rather than calling one a statistically reliable low-valuation stock.
Missing classification is a different failure mechanism. M1’s PE can be valid while no comparison group is established. Adding it to Tech merely to reach a larger sample would change the research universe and the threshold without support. Resolve its classification from an appropriate source, save the assignment revision and rerun all affected groups.
T4 instead needs the agreed PE observation. When that value arrives, Tech’s denominator and median can change, so rerun the entire Tech group rather than only T4. A local data repair can have a group-wide numerical dependency. Other industries can retain their unchanged results if their inputs and classification are fixed.
Deliver the group calculation as an inspectable package
Save the original universe, classification snapshot, eligible-observation table, thresholds, per-stock states and excluded-observation reasons. Reconcile ten original rows to four passes, two relative failures, two small-group records, one unclassified record and one missing metric. The valid-observation counts are a different reconciliation and should not be confused with final pass counts.
Have a reviewer reconstruct one Tech and one Utility median directly from the retained observations. Then inspect a withheld group and confirm that no threshold was silently published for it. This checks both successful calculation and the intended stop branch.
Reopen the screen after new comparable data, classification reassignment, source corrections or a deliberate minimum-size change. Compare the old and new group inputs before explaining membership changes. The useful result is a reproducible within-industry research shortlist with visible denominator limits, not a universal ranking, a factor-performance claim or a substitute for company research.
Inspect coverage before interpreting a group threshold
Publish both total assigned stocks and valid metric observations for each industry. A group meeting the minimum with many unavailable members can be selective in a way that the median does not reveal. The threshold describes the observed eligible subset, and the coverage table should prevent it being mistaken for a complete industry valuation benchmark.
When classification is revised, identify both the old group and the new group. Moving a stock can change two thresholds and every dependent decision, even when that company’s PE stays fixed. Keep a classification-change record so this effect is not misreported as a broad earnings or market-price movement.
Have the reviewer recompute the threshold from raw eligible values rather than trusting a printed summary. Check equal-to-threshold members and an excluded observation at the same time. This connects the denominator policy, median calculation and final predicate in one review. A clean arithmetic check cannot validate an inappropriate peer set, so retain a separate question for whether the chosen classification level serves the actual company comparison.
FAQ
Does the minimum of three prove the group is reliable?
No. It is an operational fixture rule. Statistical or economic reliability needs a separate justification.
Should a newly completed metric rerun only that stock?
Not when it changes a group threshold. Recalculate all stocks depending on the affected group.