Local-first Stock Intelligence System for Taiwan + US Markets
A persistent, self-improving AI agent that hunts for explosive growth stocks
Kestrel is named for the falcon that hovers still before a precise dive β a personal market intelligence system that combines:
- Multi-factor scoring across Technical Β· Chip Β· Fundamental Β· Theme Β· Macro dimensions
- 16 chart pattern detectors + 17 candlestick combo patterns + golden combo detection
- Multi-timeframe analysis (intraday β 6-month) for swing trades and position holds
- Dynamic theme system with 148 themes, 3-layer AI classification, real-time heat tracking
- Kestrel agent with memory, skills, investor personas, multi-platform gateway
- Social intelligence β RSS, PTT, policy monitors analyzed by Claude Haiku in real-time
- Backtest engine β event-driven, zero look-ahead bias, auto-fetches historical data on demand
- Multi-source data layer β 5 providers with cache-first routing
- Broker integration β ζ°Έθ± (Shioaji) + ε ε€§ (Yuanta) + Interactive Brokers with paper trading
Local-first design. No Docker, no servers, no cloud required. Everything runs on your machine using DuckDB + SQLite + diskcache.
Most stock screeners tell you what is moving, but not why it should keep moving β and they treat Taiwan and US markets identically when the alpha sources are completely different.
Kestrel separates them:
| Market | Unique Signals |
|---|---|
| Taiwan | Monthly revenue (MOPS) Β· TDCC holder count Β· Institutional flows Β· Margin/short Β· Day-trading ratio Β· Broker concentration Β· Stock futures OI |
| US | Options unusual flow Β· Institutional holders Β· Insider transactions Β· Earnings surprises Β· Short interest |
| Common | RS Line Β· Pattern detection (16 detectors) Β· EPS acceleration Β· Sector rotation (RRG) Β· Macro (VIX, yield curve, DXY, Fear & Greed) |
- Day (intraday-3day): Episodic Pivot, candlestick combos, RVOL spikes
- Swing (1-3 weeks): Pocket Pivot, Double Bottom, Bull Flag, Triangles, Wedges
- Position (1-3 months): VCP, Cup & Handle, Stage 2, Darvas Box, Flat Base
- Trend (3-12 months): CANSLIM, Three Weeks Tight, growth screening
Revenue growth β₯20%, gross margin expanding, D/E < 1.0, above MA200. Fundamental weight 50%.
- 4-layer persistent memory: Working + Episodic (FTS5 search) + Semantic + Procedural
- 5 modes: Single, Orchestrated, Personas, Skill, Team
- 16 file-based skills with LLM fallback routing
- 12 agent tools (scoring, chip data, patterns, data queries)
- Multi-platform: Telegram bot + LINE bot + CLI + Web Dashboard
- Investor personas: Buffett, Lynch, Graham, Burry, Druckenmiller
- Multi-provider LLM via OpenRouter (Claude, GPT, Grok, DeepSeek)
Position patterns: VCP, Cup & Handle, Stage 2 Breakout, Darvas Box, Flat Base, Three Weeks Tight
Swing patterns: Pocket Pivot, Double Bottom, Bull Flag, High Tight Flag, Falling/Rising Wedge, Ascending/Descending/Symmetrical Triangle
Day patterns: Episodic Pivot, Candlestick Combos (8 bullish + 9 bearish)
- 148 themes
- 3-layer classification: GICS auto-assign + LLM batch + social reinforcement
- Real-time heat from RSS/PTT/policy monitors
- 5 providers: FinMind, yfinance, Finnhub, Alpha Vantage, FMP
- Cache-first: DuckDB check before any API call
- Fallback chains: If primary fails, auto-try secondary source
- Premium tier: Sponsor-only datasets gated by subscription
- ζ°Έθ±ι (SinoPac): Shioaji SDK, cross-platform, paper + live trading
- ε ε€§ (Yuanta): OneAPI via Windows bridge service
- Interactive Brokers: ib_insync, US + TW + global markets
- Multi-broker sessions: Connect all 3 simultaneously, switch active broker
- Safety guards: Position size limits, daily loss circuit breaker, trade count cap
- Audit log: Immutable record of every broker action
- Telegram bot: Send messages to agent, receive alerts + analysis
- LINE bot: Same as Telegram, via LINE Official Account
- Push alerts: Score threshold triggers β instant notification
- CLI: Full agent access via command line
- Data quality layer with cross-source validation
- Per-user async locks prevent race conditions
- Tool retry + circuit breaker for resilience
- Edge case handlers (ex-dividend, limit-up, disposition, IPO, wash trading)
- Stealth accumulation detector (7 micro-signals for small caps)
- Cost ceiling + rate limiting for OpenRouter
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Multi-Source Data Layer β
β FinMind Β· yfinance Β· Finnhub Β· Alpha Vantage Β· FMP β
β Cache-first Β· Key rotation Β· Fallback chains Β· Premium gating β
βββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Local Storage (No Servers Required) β
β DuckDB 1.5 Β· SQLite + FTS5 Β· diskcache Β· Parquet archive β
ββββββββββββββββββββ¬βββββββββββββββββββββββββββ¬βββββββββββββββββββββ
βΌ βΌ
ββββββββββββββββββββββββββββββ βββββββββββββββββββββββββββββββββββ
β Analysis Pipeline β β Kestrel Agent β
β 21 patterns + 17 combos β β ReAct + Memory + 16 Skills β
β 5-dim scoring + themes β β 12 tools + LLM routing β
β Sector rotation (RRG) β β Telegram/LINE/CLI/Web gateway β
β Social intelligence β β Investor personas panel β
β Stealth accumulation β β Slash commands + watchlist β
ββββββββββββββ¬ββββββββββββββββ βββββββββββββββββββββββββββββββββββ
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Dashboard (Next.js 16) Β· 3 Themes Β· i18n (EN + zh-TW) β
β Alerts (Telegram/LINE bots) Β· Broker Trading (ζ°Έθ±/ε
ε€§/IB) β
β Backtest Engine (auto-fetch data Β· TW+US cost models) β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Full details in docs/ARCHITECTURE.md
- Language: Python 3.12+ (backend) + TypeScript 5 (frontend)
- Backend: FastAPI + uvicorn + APScheduler (75 routes)
- Frontend: Next.js 16 + Tailwind CSS 4 + Recharts + Lightweight Charts
- Storage: DuckDB 1.5 (analytical) + SQLite (operational) + diskcache
- AI/LLM: OpenRouter (multi-model β Claude, GPT, Grok, DeepSeek)
- Broker SDKs: Shioaji (ζ°Έθ±) + ib_insync (IB) + Yuanta bridge (ε ε€§)
- Data Sources: FinMind + yfinance + Finnhub + Alpha Vantage + FMP
- Auth: Telegram OIDC + LINE OAuth β JWT sessions
- i18n: next-intl (EN + zh-TW)
- Package Manager:
uv(Python) +pnpm(frontend)
# 1. Clone
git clone https://github.com/iadr-dev/kestrel.git
cd kestrel
# 2. Install dependencies (Python 3.12+ required)
uv sync
# 3. Configure API keys
cp .env.example .env
# Edit .env: OPENROUTER_API_KEY (required), FINMIND_API_TOKEN (for TW data)
# yfinance works without any key for US data
# 4. Start the API server
uv run uvicorn kestrel.api.main:app --reload --port 8000
# 5. Start the agent (CLI mode)
uv run python -m kestrel.agent.gateway --mode cli
# 6. (Optional) Start the dashboard
cd web && pnpm install && pnpm dev
# Open http://localhost:3000Three themes: Neo-Terminal (dark/cyan) · Tactical HUD (dark/green) · Hermès (light/orange)
Features:
- Ticker tape + 5-tab navigation (Market Β· Signals Β· Agent Β· Trading Β· Settings)
- RRG scatter chart + theme heatmap + sector rankings
- Signal cards with score arc + K-line chart (TradingView Lightweight Charts)
- Agent chat with tool call cards + mode selector (single/team/debate/personas)
- Portfolio positions + backtest runner + broker connections
- Global search (βK) + keyboard shortcuts + i18n toggle
| Platform | How to set up | Capabilities |
|---|---|---|
| CLI | python -m kestrel.agent.gateway --mode cli |
Full agent + slash commands |
| Telegram | Create bot via @BotFather β set TELEGRAM_BOT_TOKEN |
Chat + push alerts |
| LINE | Create LINE Official Account β set LINE_CHANNEL_ACCESS_TOKEN |
Chat + push alerts |
| Web | Dashboard at http://localhost:3000/dashboard/agent |
Chat + rich rendering |
Users message our bot β agent processes β replies in the same chat. Push alerts sent to users based on their notification preferences.
For personal daily use: ~$3-5/month total:
| Component | Monthly Cost |
|---|---|
| OpenRouter (Claude Sonnet + Haiku) | $3-5 |
| Market data (yfinance, FinMind free, Finnhub free) | $0 |
| Broker paper trading | $0 |
| Optional: Finnhub paid (real-time insider + options) | $49 |
| Optional: FMP paid (30yr financials + screener) | $15 |
Zero paid dependencies required for core functionality. All market data uses free sources.
| Doc | Content |
|---|---|
| docs/ARCHITECTURE.md | System architecture index |
| docs/AGENT-DESIGN.md | Agent system design |
| docs/API-DOC.md | HTTP API reference (75 endpoints) |
| docs/API-DESIGN.md | API design decisions + streaming protocol |
| docs/STRATEGY_GUIDE.md | Strategy & factor guide (EN) |
| docs/STRATEGY_GUIDE-TW.md | Strategy & factor guide (zh-TW) |
| docs/references/ | Architecture + implementation detail docs |
The kestrel is the falcon that hovers perfectly still before its precise dive β observing patiently, then striking with overwhelming accuracy.
That's the philosophy: don't chase, don't react. Watch the patterns develop, accumulate evidence across multiple dimensions, then strike with conviction when everything aligns.
AGPL-3.0 β see LICENSE
Not financial advice. Kestrel is a research and monitoring tool. All trading decisions and consequences are entirely the user's responsibility. Past backtest performance does not guarantee future results.