Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions .claude/skills/haoinvest/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ All-in-one investment management via CLI + Claude Code agent. CLI does data + co

### Workflow 1: "帮我分析 XXX" — Analyze a stock

1. Run comprehensive report:
1. Run composable analysis (single call, all modules including peer):
```bash
uv run haoinvest analyze report <symbol>
uv run haoinvest analyze run <symbol>
```
2. For A-shares, also run peer comparison:
Or select specific modules:
```bash
uv run haoinvest analyze peer <symbol>
uv run haoinvest analyze run <symbol> --modules fundamental,risk,peer
```
3. Interpret ALL sections in Chinese:
2. Interpret ALL sections in Chinese:
- 估值: Is it cheap or expensive? Compare PE/PB to peers.
- 财务健康: Is the company profitable and growing?
- 风险: How volatile is it? What's the worst drawdown?
Expand Down Expand Up @@ -51,9 +51,9 @@ All-in-one investment management via CLI + Claude Code agent. CLI does data + co

**触发条件**: 用户表达买入/卖出意图时。

1. Run comprehensive report + guardrails pre-trade data (2 calls):
1. Run composable analysis + guardrails pre-trade data (2 calls):
```bash
uv run haoinvest analyze report <symbol> --json
uv run haoinvest analyze run <symbol> --json
uv run haoinvest guardrails pre-trade-data <symbol> <buy/sell> <qty> -m <type> --json
```
If user hasn't specified quantity, ask first. If price not known, the command auto-fetches.
Expand Down Expand Up @@ -129,15 +129,11 @@ All-in-one investment management via CLI + Claude Code agent. CLI does data + co

### Workflow 4: "对比 A 和 B" — Compare stocks

1. Batch fundamental comparison:
1. Batch composable analysis (single call):
```bash
uv run haoinvest analyze fundamental <A>,<B> --verbose
uv run haoinvest analyze run <A>,<B> --modules fundamental,risk,signals
```
2. Batch technical comparison:
```bash
uv run haoinvest analyze technical <A>,<B>
```
3. Summarize: who's better on what dimension, and overall recommendation
2. Summarize: who's better on what dimension, and overall recommendation

### Workflow 5: "定期体检" — Portfolio checkup

Expand Down Expand Up @@ -179,6 +175,13 @@ uv run haoinvest market sector <name> # Sector constitu

### Analysis
```bash
# Composable analysis (preferred — single call, choose modules)
uv run haoinvest analyze run <symbol(s)> # All modules (fundamental,technical,risk,volume,signals,peer,checklist)
uv run haoinvest analyze run <symbol> --modules fundamental,risk,peer # Selective modules
uv run haoinvest analyze run <symbol> --json # JSON output for structured parsing
uv run haoinvest analyze run <A>,<B> --modules fundamental # Batch comparison

# Individual commands (still available)
uv run haoinvest analyze report <symbol> # Full report + buy-readiness checklist
uv run haoinvest analyze fundamental <symbol(s)> [--verbose] # Valuation + financial health (batch OK)
uv run haoinvest analyze technical <symbol(s)> # MA/MACD/RSI/BB (batch OK)
Expand Down
8 changes: 6 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ haoinvest/
├── journal.py # Investment journal with emotion/decision tagging
├── cli/ # Typer CLI — entry point: `uv run haoinvest`
│ ├── __init__.py # App + subcommand registration
│ ├── formatters.py # Output formatting (text/JSON)
│ ├── analyze.py # analyze subcommand
│ ├── _shared.py # Shared CLI utilities (init_db, fetch_current_prices)
│ ├── formatters.py # Output formatting (text/JSON/section headers)
│ ├── analyze.py # analyze subcommand (includes composable `run` command)
│ ├── guardrails.py # guardrails subcommand
│ ├── journal.py # journal subcommand
│ ├── market.py # market subcommand
│ ├── portfolio.py # portfolio subcommand
Expand All @@ -48,6 +50,8 @@ haoinvest/
│ └── optimization_engine.py # Portfolio optimization (HRP, min vol, max Sharpe)
├── portfolio/ # Trade recording, position tracking, returns (TWR)
├── analysis/ # Thin adapters over engine
│ ├── cache.py # Price data caching (ensure_prices_cached)
│ ├── registry.py # Module registry for composable `analyze run`
│ ├── fundamental.py # Valuation assessment (PE/PB/ROE), financial health
│ ├── technical.py # Technical indicator adapter
│ ├── risk.py # Risk metrics adapter
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Built for a beginner investor in China covering A-shares, US stocks, HK stocks,
- **Fundamental Analysis** — PE/PB/ROE valuation assessment with financial health scoring; batch support for multi-symbol comparison
- **Peer Comparison** — Find and compare same-sector stocks by valuation and performance
- **Sector Browsing** — Browse A-share industry sectors and their constituent stocks
- **Composable Analysis** — `analyze run` command with `--modules` flag to compose any combination of fundamental, technical, risk, volume, signals, peer, and checklist in a single call
- **Comprehensive Report** — Full stock report with buy-readiness checklist combining fundamental, technical, and risk analysis
- **Risk Metrics** — Annualized volatility, max drawdown, Sharpe ratio, Sortino ratio (powered by QuantStats)
- **Technical Analysis** — MA, MACD, RSI, Bollinger Bands with Chinese explanations (powered by pandas-ta)
Expand Down Expand Up @@ -47,7 +48,12 @@ uv run haoinvest portfolio list # View holdings
uv run haoinvest portfolio add-trade 600519 buy 100 1800.50
uv run haoinvest portfolio returns # P&L summary

# Analysis
# Composable analysis (preferred — single call, choose modules)
uv run haoinvest analyze run 600519 # All modules
uv run haoinvest analyze run 600519 --modules fundamental,risk,peer # Selective
uv run haoinvest analyze run 600519,000858 --modules fundamental # Batch

# Individual analysis commands
uv run haoinvest analyze fundamental 600519 # PE/PB valuation
uv run haoinvest analyze fundamental 600519,000858 # Batch comparison
uv run haoinvest analyze risk --symbol NVDA # Volatility, Sharpe, drawdown
Expand Down
31 changes: 31 additions & 0 deletions haoinvest/analysis/cache.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Price data caching — ensure price history is available before analysis."""

from datetime import date, timedelta

from ..db import Database
from ..market import get_provider
from ..models import MarketType


def ensure_prices_cached(
db: Database, symbol: str, market_type: MarketType, start: date, end: date
) -> None:
"""Fetch and cache price history if not already present.

Includes gap-fill: if cached data doesn't cover the requested start date,
fetches the missing earlier portion.
"""
existing = db.get_prices(symbol, market_type, start, end)
if len(existing) > 10:
earliest_cached = min(b.trade_date for b in existing)
if earliest_cached <= start + timedelta(days=7):
return
provider = get_provider(market_type)
bars = provider.get_price_history(symbol, start, earliest_cached)
if bars:
db.save_prices(bars)
return
provider = get_provider(market_type)
bars = provider.get_price_history(symbol, start, end)
if bars:
db.save_prices(bars)
Loading
Loading