Skip to content

Add v2 features: shorts scanner, portfolio hedge, agentic API#138

Open
UrbanLegendsAV wants to merge 3 commits intomsitarzewski:mainfrom
UrbanLegendsAV:claude/add-shorts-hedge-Ccm20
Open

Add v2 features: shorts scanner, portfolio hedge, agentic API#138
UrbanLegendsAV wants to merge 3 commits intomsitarzewski:mainfrom
UrbanLegendsAV:claude/add-shorts-hedge-Ccm20

Conversation

@UrbanLegendsAV
Copy link

What does this PR do?

This PR introduces three major feature sets to TarsierAlpha v2:

1. Shorts Scanner (scanner_shorts.py, scoring_additions.py)

  • Detects short setups: gap fill shorts, overbought reversals, and negative catalyst plays
  • Scores shorts on 0–100 scale with 80+ threshold (beta gating)
  • Admin-controlled opt-in via shorts_enabled user flag
  • Integrates as Phase 6 of the main scan pipeline
  • Includes short-specific badges (theta burn, margin alerts)

2. Portfolio Hedge Mode (hedge.py, templates/hedge.html)

  • Maps real-world business exposure (e.g., diesel costs) to correlated public tickers
  • Generates PUT baskets across 10 industries (trucking, retail, oil, tech, airlines, housing, banking, healthcare, manufacturing, consumer)
  • Configurable hedge ratios: low (10%), medium (20%), high (35%)
  • Paper-only trades with estimated P&L on 5% market drops
  • Web UI for interactive basket generation and entry

3. Agentic API Layer (agent_routes.py, openapi.yaml)

  • Read-only endpoints for AI agents: /api/agent/scans, /api/agent/pnl
  • Paper trade simulation: POST /api/agent/paper-trade
  • X-Agent-Key header authentication (comma-separated keys from env)
  • OpenAPI 3.0 spec for agent integration
  • Optimized JSON responses for LLM consumption

Supporting Changes

  • Database migrations: New columns for side (long/short), badges, leverage, hedge_group_id, shorts_found
  • Options selector: Modified save_option_candidate() to accept option_type parameter (was hardcoded 'call')
  • Market regime: Added allow_shorts and allow_hedge flags based on VIX levels
  • Frontend components (React/Next.js): Scanner tabs, hedge mode UI, P&L dashboard with longs/shorts split, paper trade modal
  • Backend services (Node/Express): Scanner for longs/shorts, paper trade execution, hedge basket generation, WebSocket alerts, Telegram notifications
  • Integration guide: INTEGRATION.md with step-by-step setup instructions

Test Plan

  • Verify shorts scan runs as Phase 6 after main scan completes
  • Test hedge basket generation for each industry with varying risk tolerances
  • Confirm agent API endpoints return valid JSON with correct authentication
  • Validate paper trade entry/exit via both UI and agent API
  • Check database migrations apply without errors
  • Verify WebSocket alerts dispatch new scans to connected clients
  • Test Telegram notifications for high-score setups

https://claude.ai/code/session_01TVcb1QbqkBpUkJ58aMPMo2

claude and others added 3 commits March 11, 2026 01:54
Full implementation of TarsierAlpha v2 per Grok spec:

Backend (Node/Express + MongoDB):
- Shorts scanner: gap_fill_short, overbought_short, catalyst_short (score 0-100, beta 80+ cap)
- Longs scanner: gap_fill, oversold_bounce (existing logic extended)
- Technical indicators: RSI, Bollinger Bands, gap detection, volume ratio
- Paper trade service: Polygon mid + 0.5% slippage, no real broker
- Portfolio Hedge Mode: industry → correlated put basket (trucking/retail/oil/tech/airlines/banking/healthcare/housing)
- P&L routes: longs vs shorts split, win rate, drawdown, avg hold time
- Public anonymized weekly P&L endpoint
- Agentic API: GET /api/agent/scans, GET /api/agent/pnl, POST /api/agent/paper-trade
- WebSocket /ws/alerts: real-time scan push, side subscription, heartbeat
- Telegram alerts: high ping (longs), low horn (shorts), weekly P&L broadcast
- OpenAPI spec + Swagger UI at /api/docs
- Firebase auth middleware + AgentKey middleware

Frontend (Next.js 14 + Tailwind + Recharts):
- Scanner tabs: Longs | Shorts (BETA) | Hedge
- Shorts beta opt-in banner with risk disclosure
- ScanCard: score, Greeks, entry zone, leverage, theta_burn/margin_alert badges
- Paper Trade Modal: qty selector, slippage note, confirm/success states
- Hedge Mode: industry/exposure/risk-tolerance form → basket table → Paper Hedge button
- P&L Dashboard: longs vs shorts stats, public weekly leaderboard, open trades table
- WebSocket hook: auto-reconnect, audio cues (880Hz longs, 220Hz shorts)
- Firebase auth hook: Google sign-in, token sync
- PWA manifest, dark theme, Tailwind brand colors

https://claude.ai/code/session_01TVcb1QbqkBpUkJ58aMPMo2
- scoring_additions.py: score_short(), score_short_for_hedge(), build_risk_note()
- options_selector_additions.py: find_best_put(), select_put_options_for_candidate()
- scanner_shorts.py: Phase 6 shorts pipeline, admin-gated beta
- hedge.py: Industry→PUT basket generator (10 industries, 3 risk levels)
- agent_routes.py: /api/agent/scans, /api/agent/pnl, /api/agent/paper-trade
- app_additions.py: Routes for hedge, shorts toggle, agent blueprint
- market_regime_additions.py: allow_shorts/allow_hedge flags
- migrations.sql: New columns (side, badges, leverage, risk_note, hedge_group_id)
- templates: hedge.html, shorts_beta_banner.html, shorts_tab.html
- INTEGRATION.md: Step-by-step apply guide

https://claude.ai/code/session_01TVcb1QbqkBpUkJ58aMPMo2
@UrbanLegendsAV
Copy link
Author

added more to my own project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants