How to Use the Industry-Funnel Skill to Filter Stocks in ai-berkshire
The industry-funnel skill implements a four-layer quantitative and qualitative filtering process that narrows a broad market universe of 30-60 stocks down to three high-conviction investment ideas through hard metrics, structured analysis templates, and multi-perspective guru reviews.
The xbtlin/ai-berkshire repository provides an AI-powered investment research framework that replicates Berkshire Hathaway-style security selection through composable, markdown-defined skills. The industry-funnel skill serves as the primary stock filtering engine, systematically eliminating candidates through explicit inclusion criteria documented in skills/industry-funnel.md.
Understanding the Four-Layer Filtering Architecture
The industry-funnel skill processes securities through a sequential elimination workflow, with each layer producing reproducible output formats and documented "淘汰理由" (elimination rationale).
Layer 1: Full-Market Scan (30-60 Companies)
The funnel initializes with a full-market scan that unions three activity-based subsets across A-shares, Hong Kong, U.S., and international markets: high-turnover stocks, recent strong risers, and top-market-cap members. This layer also includes a dedicated "unlisted IPO candidates" section. The combination yields an initial pool of roughly 30-60 companies, ensuring broad coverage without geographic bias.
Layer 2: Hard-Metric Funnel (≤10 Companies)
Layer 2 applies five quantitative filters to every company from the initial pool:
- PE – Reasonable valuation vs. historical/peer levels, with PEG relaxation allowed
- ROE – Greater than 15% or demonstrating a clear improving trend
- Operating cash-flow – Exceeds 70% of net profit
- Debt-to-asset ratio – Below 60% (with higher caps permitted for utilities)
- Moat rating – Qualitative assessment of ★★★ or higher
Companies must satisfy all five criteria to advance automatically. Those meeting four criteria plus a "near-miss" on the fifth are flagged for manual review rather than immediate elimination. This quantitative screen reduces the universe to ≤10 firms.
Layer 3: Structured Deep-Dive
For each surviving company, the skill generates a 300-500 word structured analysis template covering business model mechanics, financial quality assessment, moat depth evaluation, top-3 risk factors, valuation snapshot, and a binary "enter final-3?" decision field. This enforces analytical consistency and surfaces residual doubts before final selection.
Layer 4: Four-Guru Deep Analysis
The final three selections undergo 800-1200 word narrative analysis from the perspectives of five investment philosophies: 段永平 (Duan Yongping), Warren Buffett, Charlie Munger, 李录 (Li Lu), and an "期权型" (optionality) lens. Each perspective produces a detailed narrative culminating in a composite star rating (★-style) and explicit position sizing recommendation (core/satellite/option/observation).
Executing the Industry-Funnel Skill Programmatically
The skill can be invoked via the provided CLI wrapper or parsed for downstream automation workflows.
Direct CLI Invocation
Use the ai_berkshire.run module to execute the funnel against a specific industry sector:
import subprocess, json
def run_industry_funnel(industry: str) -> str:
"""Runs the industry‑funnel skill and returns the raw markdown output."""
result = subprocess.run(
["python3", "-m", "ai_berkshire.run", "industry-funnel", industry],
capture_output=True,
text=True,
check=True,
)
return result.stdout
output_md = run_industry_funnel("AI 算力")
print(output_md) # Full funnel report (layers 1‑4)
Parsing Layer 1 Tabular Output
Extract the initial screening table for DataFrame-based analysis or Excel export:
import pandas as pd
import re
def parse_layer1_table(md: str) -> pd.DataFrame:
"""Extracts the “全市场扫描” table from the markdown report."""
# Locate the markdown table between the header and the next blank line
table_md = re.search(r"\| 公司名 \| 代码 \| 市场 .*?\n(?P<table>(\|.*\n)+)", md, re.S).group("table")
# Convert markdown pipes to CSV, then read with pandas
csv_data = "\n".join([row.strip().strip("|") for row in table_md.splitlines() if row.strip()])
return pd.read_csv(pd.compat.StringIO(csv_data), sep="|", engine="python")
Core Source Files and Architecture
The industry-funnel skill implementation spans three critical paths in the repository:
skills/industry-funnel.md– Contains the core markdown skill definition, including layer specifications, the five hard metric thresholds, and structured analysis templates.codex-prompts/industry-funnel.md– Generated Codex prompt wrapper enabling execution through the OpenAI Codex CLI.scripts/sync-codex-skills.py– Synchronization utility that maintains parity between the canonical markdown skill definitions and the Codex-compatible prompt wrappers.
These files collectively implement the input → skill → structured output workflow, enabling integration with portfolio management systems and automated reporting pipelines.
Summary
- The industry-funnel skill applies a rigorous four-layer elimination process (30-60 → ≤10 → 3 stocks) with explicit documentation at each filtering stage.
- Five hard metrics (PE, ROE > 15%, operating cash flow > 70% of net profit, debt-to-asset < 60%, moat rating ≥ ★★★) drive the quantitative Layer 2 screening.
- Structured 300-500 word templates enforce consistent qualitative analysis for each Layer 2 survivor.
- Final selections undergo 800-1200 word multi-perspective guru review with explicit position sizing classifications (core/satellite/option/observation).
- Programmatic access available via
python3 -m ai_berkshire.run industry-funnelwith pandas-compatible output parsing for downstream automation.
Frequently Asked Questions
What markets does the industry-funnel skill cover?
The skill simultaneously scans A-shares, Hong Kong, U.S., and international equity markets as defined in skills/industry-funnel.md. It also includes a dedicated section for unlisted IPO candidates, ensuring comprehensive coverage without geographic bias.
What happens if a company meets four out of five hard metrics?
Companies satisfying four of the five quantitative filters but missing one are flagged for manual review rather than automatic elimination. This "near-miss" tolerance allows analysts to exercise judgment on qualitative factors while maintaining the discipline of the quantitative framework.
Can I customize the guru perspectives or analysis templates?
Yes, the analysis templates and guru perspectives are defined in skills/industry-funnel.md and can be customized by editing the markdown file directly. The scripts/sync-codex-skills.py utility ensures any modifications propagate to the codex-prompts/industry-funnel.md wrapper for CLI compatibility.
How do I extract the final three recommendations from the output?
The Layer 4 output generates structured markdown sections containing composite star ratings (★-style) and position sizing classifications (core/satellite/option/observation). You can extract these using regex patterns targeting the "四大师深度分析" section headers, similar to the Layer 1 table parsing approach.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →