Portfolio Management Skill
Parse $ARGUMENTS to determine the command, then execute the corresponding command below.
Execution Command
bash
python3 /Users/kikuchihiroyuki/stock-skills/.claude/skills/stock-portfolio/scripts/run_portfolio.py <command> [args]
Command List
snapshot -- Portfolio Snapshot
Generate a portfolio snapshot including current price, profit/loss, and currency conversion.
bash
python3 .../run_portfolio.py snapshot
buy -- Add Purchase Record
bash
python3 .../run_portfolio.py buy --symbol <sym> --shares <n> --price <p> [--currency JPY] [--date YYYY-MM-DD] [--memo text] [--yes]
Omitting
(
) will display a confirmation preview of the purchase details and exit. Specifying
skips confirmation and directly records the purchase (KIK-444).
sell -- Add Sale Record
bash
python3 .../run_portfolio.py sell --symbol <sym> --shares <n> [--price <sale-price>] [--date YYYY-MM-DD] [--yes]
Omitting
(
) will display a confirmation preview of the sale details (acquisition price, estimated realized profit/loss) and exit. Specifying
skips confirmation and directly records the sale (KIK-444).
When
is specified, it calculates and displays realized profit/loss, profit/loss ratio, and after-tax estimate, then saves to
data/history/trade/*.json
(KIK-441).
review -- Trade Performance Review (KIK-441)
Aggregate and display profit/loss statistics from past sale records (those recorded with
).
bash
python3 .../run_portfolio.py review [--year 2026] [--symbol NVDA]
Output Content:
- Transaction History Table (Symbol, Sale Date, Shares Held, Acquisition Price, Sale Price, Holding Period, Realized Profit/Loss, Profit/Loss Ratio)
- Statistics (Number of Transactions, Win Rate, Average Return, Average Holding Period, Total Realized Profit/Loss)
analyze -- Structural Analysis
Calculate HHI (Herfindahl-Hirschman Index) for region/sector/currency/size to analyze portfolio bias. 4-axis analysis including size-based composition table (Large/Mid/Small/ETF/Unknown) (KIK-438, KIK-469 P2: ETF Classification). ETFs are independently categorized as sector "ETF" and size "ETF".
bash
python3 .../run_portfolio.py analyze
health -- Health Check
Check if the investment hypothesis for held securities is still valid. Output 3-level alerts based on multiple axes of technical analysis (SMA50/200, RSI, Golden Cross/Dead Cross detection) and fundamental analysis (Change Score, Shareholder Return Stability). Sensitivity is automatically increased for small-cap stocks (KIK-438).
bash
python3 .../run_portfolio.py health
Technical Analysis (KIK-356/374/438):
- Trend determination for SMA50/200 (Uptrend/Sideways/Downtrend)
- Golden Cross/Dead Cross Detection: Detect cross events with a 60-day lookback, display occurrence date and elapsed days
- Small-Cap Cross Lookback Shortening (KIK-438): For small-cap stocks, use lookback=30 days to detect recent fluctuations early
Shareholder Return Stability (KIK-403):
- Evaluate stability based on total return ratio of dividends + share buybacks (✅Stable High Return/📈Increasing Trend/⚠️Temporary High Return/📉Decreasing Trend)
- Temporary High Return → Promoted to early warning
- Decreasing Trend → Add reason to alert details
- Use total return ratio (dividends + share buybacks) for long-term suitability assessment
Small-Cap Allocation (KIK-438):
- Classify each security by market capitalization (Large/Mid/Small/Unknown) and display badge
- Small-cap stocks automatically escalate from EARLY_WARNING to CAUTION
- Calculate the small-cap ratio of the entire portfolio, display warning if >25%, danger if >35%
ETF Health Check (KIK-469 Phase 2):
- Display separate tables for individual stocks and ETFs
- ETF Table: Symbol, Profit/Loss, Trend, Expense Ratio, AUM, ETF Score, Alert
- Individual Stock Table: As before (Quality of Change, Long-Term Suitability, Return Stability)
Alert Levels:
- Early Warning: Break below SMA50 / Sharp RSI decline / Deterioration of 1 change score indicator / Temporary High Return
- Caution: SMA50 approaching SMA200 + indicator deterioration / Deterioration of multiple change score indicators / Escalation of small-cap EARLY_WARNING
- Exit: Dead Cross detected / Trend collapse + change score deterioration
adjust -- Portfolio Adjustment Advisor (KIK-496)
Generate specific adjustment actions (SELL/SWAP/ADD/TRIM_CLASS/FLAG) using 17 rules (P1-P10: Position-specific, F1-F7: Portfolio-wide) based on health check results + market regime determination.
bash
python3 .../run_portfolio.py adjust [--full]
CLI Options:
- : Full analysis mode (includes concentration and correlation analysis. High API load)
Output:
- Market Regime (bull/bear/crash/neutral) — Determined from SMA50/200, RSI, drawdown
- Action Table by HIGH/MEDIUM/LOW Priority (Action Type/Target/Reason/Rule ID)
- Summary (Number of Actions)
Regime Correction: In crash regime, increase urgency by 1 level. In bear regime, prioritize rules for small-cap stocks and downtrend sectors.
rebalance -- Rebalancing Proposal
Analyze current portfolio structure and present proposals to reduce concentration risk and adjust to target allocation.
bash
python3 .../run_portfolio.py rebalance [options]
CLI Options:
--strategy defensive|balanced|aggressive
(Default: balanced)
- (Example: Technology)
--reduce-currency CURRENCY
(Example: USD)
- (Example: 0.15)
- (Example: 0.25)
- (Example: 0.30)
- (JPY, Example: 1000000)
--min-dividend-yield YIELD
(Example: 0.03)
forecast -- Estimated Return
Estimate 12-month expected returns for each held security in 3 scenarios (Optimistic/Base/Pessimistic) based on analyst target prices or historical return distribution. Includes value trap warnings and TOP/BOTTOM rankings.
bash
python3 .../run_portfolio.py forecast
Estimation Methods:
- Analyst Method: Analyst target price + dividend yield + share buyback yield (including shareholder returns)
- Historical Return Method: For securities without analyst coverage such as ETFs, estimate using historical CAGR + standard deviation (KIK-469 P2: ETFs display annual volatility + badge)
- Industry Catalyst Adjustment (KIK-433, when connected to Neo4j): Add number of recent catalysts in the same sector × 1.7% to optimistic scenario, subtract number of catalysts × 1.7% from pessimistic scenario (capped at 10% each)
Output Structure (KIK-390):
- Portfolio-wide 3-scenario return and profit/loss table
- Watchlist Section (Aggregate securities with value trap warnings)
- Expected Return TOP 3 / BOTTOM 3 Rankings
- Security-specific details (Analyst Target/Forward PER/Number of News/X Sentiment/3 Scenarios)
what-if -- What-If Simulation (KIK-376 / KIK-451)
Simulate adding/selling/swapping securities and display the impact on the portfolio with Before/After comparison.
bash
# Add only (Traditional)
python3 .../run_portfolio.py what-if --add "SYMBOL:SHARES:PRICE[,...]"
# Swap (Sell then Buy) (KIK-451)
python3 .../run_portfolio.py what-if --remove "SYMBOL:SHARES[,...]" --add "SYMBOL:SHARES:PRICE[,...]"
# Sell only simulation (KIK-451)
python3 .../run_portfolio.py what-if --remove "SYMBOL:SHARES[,...]"
CLI Options:
- : List of securities to add (optional). Format: Comma-separated
- : List of securities to sell (optional). Format: Comma-separated (price not required, calculated at market price)
- Either or is required
Output:
- [When Selling] Context of Sale Candidates (KIK-470): When is specified, automatically display screening appearance count, investment notes, and research history before simulation (when connected to Neo4j)
- Before/After comparison of sector HHI, region HHI, currency HHI
- Basic information of added securities (PER/PBR/Dividend Yield/ROE)
- [When Swapping] Sale Security Table (Symbol, Shares, Estimated Sale Proceeds)
- [When Swapping] Cash Flow (Required Purchase Funds / Estimated Sale Proceeds / Difference)
- [When Swapping] Sale Security Health Check (Alert status of sale targets)
- Judgment label: Recommended / Consider with Caution / Not Recommended (e.g., "This swap is recommended" for swaps)
- ETF Quality Evaluation (KIK-469 P2): When adding ETFs, reflect ETF score in judgment (Warning if quality is low <40, Good if ≥75)
backtest -- Backtesting
Verify returns from accumulated screening results and compare with benchmarks (Nikkei 225/S&P500).
bash
python3 .../run_portfolio.py backtest [options]
CLI Options:
- : Screening preset to verify (Example: alpha, value)
- : Region to verify (Example: jp, us)
- : Verify returns for N days after acquisition (Default: 90)
Output:
- Daily returns by screening date
- Benchmark comparison (Excess Return)
- Win Rate, Average Return, Maximum Return/Maximum Loss
simulate -- Compound Interest Simulation
Simulate future asset growth using compound interest based on the current portfolio. Calculate compound interest using forecast expected returns + dividend reinvestment + monthly contributions, display in 3 scenarios (Optimistic/Base/Pessimistic).
bash
python3 .../run_portfolio.py simulate [options]
CLI Options:
- (Simulation period in years, Default: 10)
- (Monthly contribution amount, JPY, Default: 0)
- (Target amount, JPY, Example: 15000000)
- (Reinvest dividends, Default: ON)
- (Do not reinvest dividends)
list -- List of Held Securities
Display the contents of portfolio.csv as-is.
bash
python3 .../run_portfolio.py list
Natural Language Routing
Refer to .claude/rules/intent-routing.md for natural language → skill determination.
Constraints
- Japanese Stocks: 100-share units (board lot)
- ASEAN Stocks: 100-share units (minimum commission 3,300 JPY)
- Rakuten Securities compatible (commission structure)
- portfolio.csv path:
.claude/skills/stock-portfolio/data/portfolio.csv
Output
Display results in Markdown format.
snapshot Output Items
- Symbol / Name / Quantity Held / Acquisition Price / Current Price / Valuation Amount / Profit/Loss / Profit/Loss Ratio / Currency
analyze Output Items
- Sector HHI / Region HHI / Currency HHI / Size HHI (KIK-438)
- Composition ratio for each axis (Size-based composition table: Large/Mid/Small/ETF/Unknown)
- ETF Notes (Note on unimplemented look-through)
- Risk level determination
health Output Items
- Individual Stock Table: Symbol (Small-cap stocks have badge) / Profit/Loss Ratio / Trend / Cross Event / Quality of Change / Alert / Long-Term Suitability / Shareholder Return Stability
- ETF Table (KIK-469 P2): Symbol / Profit/Loss / Trend / Expense Ratio / AUM / ETF Score / Alert
- Details of securities with alerts (Reason, SMA/RSI values, Cross occurrence date/elapsed days, Change Score, Shareholder Return Stability, Recommended Action)
- Small-Cap Allocation: Summary of small-cap ratio for entire portfolio (✅Normal/⚠️Warning/🔴Danger)
forecast Output Items
- Portfolio-wide: 3-scenario returns (Optimistic/Base/Pessimistic) + Profit/Loss Amount + Total Valuation
- Watchlist Section: List of securities with value trap warnings
- TOP 3 / BOTTOM 3: Expected Return Rankings (with number of analysts)
- Security-specific: Analyst Target Price / Forward PER / Number of News / X Sentiment / 3 Scenarios / ETFs display annual volatility + badge
what-if Output Items
- [When Selling] Context of Sale Candidates (KIK-470): Screening appearance count, investment notes, research history
- Before/After HHI comparison (Sector/Region/Currency)
- Fundamentals of added securities
- Concentration change determination
- [When Swapping] Sale Security Table (Estimated Sale Proceeds)
- [When Swapping] Cash Flow (Required Purchase Funds / Sale Proceeds / Difference)
- [When Swapping] Sale Security Health Check
- [When Swapping] "This swap is recommended / Consider with Caution / Not Recommended"
backtest Output Items
- Daily returns by screening date
- Benchmark comparison (Excess Return)
- Win Rate, Statistical Values
adjust Output Items
- Market Regime (Regime Name/SMA50 vs SMA200/RSI/Drawdown)
- HIGH Priority Table: SELL/SWAP/TRIM_CLASS Actions
- MEDIUM Priority Table: FLAG/SELL Actions
- LOW Priority Table: FLAG Actions
- Summary (Number of HIGH/MEDIUM/LOW Actions, Regime)
rebalance Output Items
- Current HHI (Sector/Region/Currency) and Target HHI
- Sale Candidates (Symbol, Shares, Reason)
- Purchase Candidates (Symbol, Shares, Reason, Dividend Yield)
- Predicted HHI after rebalancing
simulate Output Items
- Annual transition table (Year/Valuation Amount/Total Contributions/Investment Gains/Total Dividends)
- 3-scenario comparison (Final year of Optimistic/Base/Pessimistic)
- Target Achievement Analysis (Year of Achievement / Required Monthly Contribution)
- Compound interest effect of dividend reinvestment
Execution Examples
bash
# Snapshot
python3 .../run_portfolio.py snapshot
# Purchase Record
python3 .../run_portfolio.py buy --symbol 7203.T --shares 100 --price 2850 --currency JPY --date 2025-06-15 --memo Toyota
# Sale Record
python3 .../run_portfolio.py sell --symbol AAPL --shares 5
# Structural Analysis
python3 .../run_portfolio.py analyze
# List Display
python3 .../run_portfolio.py list
# Health Check
python3 .../run_portfolio.py health
# Estimated Return
python3 .../run_portfolio.py forecast
# Rebalancing Proposal
python3 .../run_portfolio.py rebalance
python3 .../run_portfolio.py rebalance --strategy defensive
python3 .../run_portfolio.py rebalance --reduce-sector Technology --additional-cash 1000000
# What-If Simulation (Add only)
python3 .../run_portfolio.py what-if --add "7203.T:100:2850,AAPL:10:250"
# What-If Simulation (Swap: Sell 7203.T → Buy 9984.T) (KIK-451)
python3 .../run_portfolio.py what-if --remove "7203.T:100" --add "9984.T:50:7500"
# What-If Simulation (Sell only) (KIK-451)
python3 .../run_portfolio.py what-if --remove "7203.T:50"
# Adjustment Advisor (KIK-496)
python3 .../run_portfolio.py adjust
python3 .../run_portfolio.py adjust --full
# Backtesting
python3 .../run_portfolio.py backtest --preset alpha --region jp --days 90
Prior Knowledge Integration Rules (KIK-466)
health Command
If the output of get_context.py includes the following, integrate with health check results in the response:
- Trade History (BOUGHT/SOLD): Reference purchase price and date to add context of unrealized profit/loss. If a sold security appears in warnings, clearly state "No problem as it has been sold"
- Investment Notes (Note): If there are thesis/concern notes, cross-reference with health check results. e.g., "Value trap concern note exists → BT score is also high this time → Requires close attention"
- Previous Health Check (HealthCheck): Show differences from previous check. e.g., "Previous HOLD → Current EXIT: Situation deteriorated" "Previous EXIT → Current HOLD: Improved"
- Screening History (SURFACED): If a warning security was in the top rankings in past screenings, e.g., "High attention (3 times in top rankings) but requires caution now"
- Thesis Progress: If thesis note is over 90 days old, prompt "Time to review thesis"
snapshot / forecast
- If there is a previous snapshot/forecast, add difference comments
- e.g., "Compared to previous: Valuation amount +5.2%, return improved"
Prompt to Record Analysis Conclusions
When providing a response that includes a specific judgment for EXIT/warnings (e.g., "Recommended to sell" "Continue holding"):
💡 Would you like to record this judgment as an investment note?