How the Portfolio-Review Skill Calculates Position Sizing and Rebalancing

The portfolio-review skill calculates position sizing by comparing each holding's certainty-adjusted expected return against a cash benchmark, then enforces strict concentration limits and validates allocations through macro stress-tests before generating specific rebalancing actions.

The portfolio-review skill in the xbtlin/ai-berkshire repository implements a quantitative, value-investing approach to portfolio construction inspired by Buffett and Li Lu. According to the source code in skills/portfolio-review.md, it processes holdings through a systematic four-layer framework that combines opportunity-cost analysis with defensive risk management. This article examines the exact formulas, guardrails, and stress-testing methodologies defined in the codebase.

Layer 1: Opportunity-Cost-Based Position Sizing

The skill begins by calculating whether each dollar is better deployed in a specific stock or held as cash. It invokes the tools/financial_rigor.py three-scenario routine to derive a simplified expected return formula:

Expected Annual Return ≈ FCF Yield + Projected Growth

This raw return estimate is then adjusted by a certainty factor derived from valuation checks (PE/PB ratios, analyst consensus, and financial-rigor verification). The final metric becomes Expected Return × Certainty, which is compared against a cash benchmark representing the risk-free rate (approximately 4%). If a position’s adjusted return falls below this cash threshold, the skill flags it for reduction or exit, embodying the principle that "每一块钱都应该放在回报最高的地方" (every dollar should be placed where returns are highest).

Layer 2: Concentration and Cash Guardrails

After calculating individual opportunity costs, the skill enforces portfolio-level concentration rules to prevent excessive risk. According to skills/portfolio-review.md, it validates the following metrics:

  • Single position limit: Largest holding must remain below 40%
  • Top three concentration: Combined allocation of the three largest positions should fall between 50-80%
  • Diversification range: Total number of holdings must stay between 5 and 15 positions
  • Liquidity buffer: Cash allocation must remain within 10-30% of total capital

If any metric drifts outside these bands, the skill generates recommendations to add or remove positions, ensuring the portfolio maintains "核心持仓不超过10只" (core positions not exceeding 10) as per Buffett-style standards.

Layer 3: Rebalancing Logic and Stress-Testing

The rebalancing engine constructs a "调仓建议" (rebalancing suggestions) table that maps specific actions to each holding. Valid actions include 加仓 (increase), 减仓 (decrease), 清仓 (liquidate), 新建仓 (new position), or 不动 (hold), with corresponding target percentages derived from the opportunity-cost rankings.

Before finalizing recommendations, the skill runs a 压力测试 (stress test) against four predefined macro scenarios: global recession, US-China conflict, interest-rate surge, and tech-bubble burst. Using each holding’s sector exposure and historical volatility, it estimates the maximum drawdown under each adverse condition. If the analysis indicates a holding would cause excessive portfolio decline, the system overrides the pure opportunity-cost logic and flags the position for 减仓 or 清仓 to preserve capital.

Layer 4: Active Cash Management

Unlike passive cash calculations, the skill treats liquidity as a deliberate position with its own opportunity cost. After processing equity holdings, it calculates a recommended cash proportion between 10-30% based on current market conditions and the aggregate opportunity set. If cash reserves fall below the target range, the skill recommends 部分减仓 (partial reduction) of existing positions to raise liquidity. Conversely, if cash exceeds the upper limit while high-conviction opportunities exist, it suggests deploying capital via 加仓 commands into positions offering superior risk-adjusted returns.

Executing the Skill: Code Examples

The skill follows a fixed execution pipeline: parsing → data retrieval → single-position health check → portfolio-level analysis → optimization → report generation. Below are practical invocations demonstrating how to retrieve sizing calculations and rebalancing tables.


# Example 1: Invoke with current weights to get rebalancing suggestions

result = run_skill(
    skill="portfolio-review",
    args="腾讯30%, 美团20%, 茅台20%, 英伟达15%, 现金15%"
)
print(result["调仓建议"])

# → [{'动作': '加仓', '标的': '腾讯', '当前占比': '30%', '建议占比': '35%', '理由': '预期回报高于现金'}]

# Example 2: Retrieve the detailed opportunity-cost analysis table

result = run_skill(
    skill="portfolio-review",
    args="我的持仓"
)
print(result["机会成本分析"])

# → Table showing ticker, 当前占比, 预期年化回报, 确定性, and 预期回报×确定性

# Example 3: Examine stress-test impact before rebalancing

result = run_skill(
    skill="portfolio-review",
    args="腾讯30%, 美团20%, 英伟达15%, 现金35%"
)
print(result["压力测试"])

# → Lists scenario, 假设, 组合预计影响, and 最大回撤 for each macro shock

These outputs leverage the codex-prompts/portfolio-review.md definitions to return structured markdown tables that can be parsed programmatically or reviewed manually.

Summary

  • Opportunity-cost sizing: Positions are sized based on Expected Return × Certainty compared to a ~4% cash benchmark, using the three-scenario function from tools/financial_rigor.py
  • Hard guardrails: Enforces strict limits (max 40% single holding, 5-15 total positions, 10-30% cash) to prevent concentration risk
  • Stress-validated rebalancing: Generates specific 调仓建议 actions only after validating allocations against four macro shock scenarios and estimating maximum drawdowns
  • Active cash optimization: Treats cash as a position with target ranges, recommending 部分减仓 to raise liquidity or 加仓 to deploy excess cash

Frequently Asked Questions

How does the portfolio-review skill calculate expected returns for position sizing?

The skill uses the three-scenario function in tools/financial_rigor.py to compute a base formula of FCF Yield + Projected Growth. It then multiplies this figure by a certainty factor derived from PE/PB valuations, analyst consensus data, and financial-rigor verification checks to produce a risk-adjusted expected return.

What are the specific concentration limits enforced by the skill?

According to skills/portfolio-review.md, the skill mandates that the largest single holding remain below 40% of the portfolio, the top three holdings comprise 50-80% of total capital, the total number of positions stay between 5 and 15, and cash reserves remain within 10-30% of assets under management.

How does the skill incorporate stress-testing into rebalancing decisions?

Before finalizing any 调仓建议, the skill runs a 压力测试 against four macro scenarios (global recession, US-China conflict, interest-rate surge, and tech-bubble burst). It calculates estimated drawdowns using sector exposure and historical volatility data; if a holding would cause excessive portfolio decline under adverse conditions, the skill recommends 减仓 (reduction) or 清仓 (liquidation) regardless of the standalone opportunity-cost calculation.

Can the skill recommend increasing cash rather than investing in equities?

Yes. The skill treats cash as an active position with its own target range (10-30%). If the opportunity-cost analysis shows limited high-certainty investments, or if the portfolio is overweight equities, it explicitly recommends 部分减仓 (partial selling) of existing positions to raise cash reserves to the optimal defensive level.

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:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →