# Stock Analysis v6.3 - Quick Reference

## New: LongPort-Powered 8-Dimension Analysis

### Basic Usage
```bash
# Single stock
uv run ~/.hermes/skills/openclaw-imports/stock-analysis/scripts/analyze_stock_unified.py O

# Multiple stocks
uv run ~/.hermes/skills/openclaw-imports/stock-analysis/scripts/analyze_stock_unified.py O 823.HK MAIN JEPI NLY

# Fast mode (skip Yahoo fallback for speed)
uv run ~/.hermes/skills/openclaw-imports/stock-analysis/scripts/analyze_stock_unified.py O --fast

# JSON output
uv run ~/.hermes/skills/openclaw-imports/stock-analysis/scripts/analyze_stock_unified.py O --output json
```

### Symbol Format
| Market | Format | Example |
|--------|--------|---------|
| US | `TICKER` or `TICKER.US` | `O`, `AAPL.US` |
| HK | `CODE.HK` | `823.HK`, `9988.HK` |
| CN | `CODE.SZ` or `CODE.SH` | `000001.SZ` |

### 8-Dimension Scoring System

| Dimension | Weight | Data Source | Metrics |
|-----------|--------|-------------|---------|
| **Fundamentals** | 40% | LongPort + Yahoo | PE, PB, dividend, margins, ROE, debt |
| **Valuation** | 30% | LongPort | PE/PB/dividend relative scoring |
| **Momentum** | 20% | LongPort | RSI, volume ratio, price change |
| **Market Cap** | 10% | LongPort | Large-cap stability bonus |

### Scoring Logic

**Fundamentals Score:**
- PE < 15: +0.5, PE > 30: -0.3
- PB < 1.0: +0.6, PB > 5.0: -0.4
- Dividend > 5%: +0.5
- Operating margin > 15%: +0.5
- ROE > 15%: +0.4
- Debt/Equity < 50: +0.3

**Valuation Score:**
- PE: <15 → +0.5, <25 → +0.2, >35 → -0.3
- PB: <1.0 → +0.6, <2.0 → +0.3, >5.0 → -0.4
- Dividend: >5% → +0.5, >3% → +0.3

**Momentum Score:**
- RSI < 30 (oversold): +0.5
- RSI > 70 (overbought): -0.5
- Volume ratio > 1.5: +0.3

### Recommendations
| Score | Recommendation | Confidence |
|-------|----------------|------------|
| > 0.3 | BUY | 80-90% |
| > 0.0 | BUY | 50-80% |
| > -0.3 | HOLD | 50-80% |
| < -0.3 | SELL | 80-90% |

### Data Sources

**LongPort (Primary):**
- PE TTM, PB, EPS TTM, BPS
- Dividend yield, Market cap
- Real-time quotes, Volume ratio
- Full HK/CN/US coverage

**Yahoo Finance (Fallback - US only):**
- Operating margins, ROE, ROA
- Debt ratios, Revenue growth
- Analyst ratings, Earnings history

## Legacy Commands (Yahoo Finance)

### Stock Analysis
```bash
uv run {baseDir}/scripts/analyze_stock.py AAPL --fast
```

### Dividend Analysis
```bash
uv run {baseDir}/scripts/dividends.py O JEPI QYLD
```

## Environment Setup

### LongPort SDK
Add to `~/.bashrc`:
```bash
export LONGBRIDGE_APP_KEY=your_key
export LONGBRIDGE_APP_SECRET=your_s...port LONGBRIDGE_ACCESS_TOKEN=your_t...The script auto-maps `LONGBRIDGE_*` → `LONGPORT_*` for the SDK.

## Troubleshooting

### "token invalid" error
Token expired. Get new token from LongPort App → Settings → API Keys.

### Yahoo Finance rate limiting
Normal during heavy usage. LongPort data is still available. Use `--fast` to skip Yahoo.

### Missing PE/PB for ETFs
ETFs don't have traditional PE/PB. Only dividend yield is available.

### Negative PE
Negative PE means the company is losing money. Fundamentals score will be lower.
