even ▸ README.md
updated 2026-02-28
Even - Unicorn.Land MVP
A production-ready MVP for Unicorn.Land’s “Even” product: a low-touch, inequality-driven macro trading decision-support dashboard.
Overview
Even operationalizes an inequality/incentive framework to pick simple, liquid, retail-accessible trades and monitor persistence. It runs a weekly loop: Diagnose → Map → Select instrument → Position sizing helper → Monitor → Reassess only if incentives truly shift.
Tech Stack
- Frontend: Next.js 14 (App Router), TypeScript, Tailwind CSS, shadcn/ui, Recharts
- Backend: Next.js API routes (Edge runtime where possible) + Prisma (SQLite for MVP)
- Database: SQLite with Prisma ORM
- Jobs: Simple cron routes (
/api/cron/*) that can be triggered manually - No external schedulers or secrets committed
Features
Core Pages
/even- Overview dashboard with status banner, exposure bars, tile grid, mechanisms, trades, and alerts/even/mechanisms/[id]- Detailed mechanism view with associated trades and signals/even/trades- Trade management with filtering and performance tracking/even/alerts- Alert monitoring and resolution
Data Model
- Mechanisms: Core inequality/incentive frameworks with persistence scoring
- Trades: Position tracking with risk management
- Signals: Market data with traffic-light color coding
- Metrics: Inequality-aware market tiles (breadth, value growth, etc.)
- Alerts: System notifications for regime shifts and invalidators
Market Tiles
- Breadth: RSP/SPY ratio
- Value Growth: IWD/IWF ratio
- Small/Large: IWM/QQQ ratio
- Real Rate: Policy rate - Core CPI
- HY OAS: High yield option-adjusted spread
- DXY Proxy: UUP (Dollar strength)
- Gold vs TIPS: GLD/TIPS ratio
- VIX Term: VIX/VXV ratio
Quick Start
Prerequisites
- Node.js 18+
- pnpm (recommended) or npm
Installation
- Clone and install dependencies:
cd even
pnpm install
- Set up environment:
cp env.example .env.local
# Edit .env.local with your configuration
- Set up database:
pnpm prisma migrate dev
pnpm prisma db seed
- Start development server:
pnpm dev
- Open in browser:
http://localhost:3000/even
API Endpoints
Core APIs
GET /api/health- Health checkGET /api/mechanisms- List mechanisms with paginationPOST /api/mechanisms- Create mechanismGET /api/mechanisms/[id]- Get mechanism detailsPUT /api/mechanisms/[id]- Update mechanismDELETE /api/mechanisms/[id]- Delete mechanismGET /api/trades- List trades with filteringPOST /api/trades- Create tradeGET /api/signals- Get latest signalsGET /api/metrics/latest- Get latest metrics with tilesGET /api/alerts- List alerts with filtering
Cron Jobs (Manual Triggers)
POST /api/cron/pull-metrics- Fetch market data and compute tilesPOST /api/cron/scan-news- Analyze news for incentive shiftsPOST /api/cron/weekly-summary- Generate weekly market summary
Sample API Calls
Pull Market Metrics
curl -X POST http://localhost:3000/api/cron/pull-metrics
Generate Weekly Summary
curl -X POST http://localhost:3000/api/cron/weekly-summary
Scan News
curl -X POST http://localhost:3000/api/cron/scan-news
Create a Mechanism
curl -X POST http://localhost:3000/api/mechanisms \
-H "Content-Type: application/json" \
-d '{
"title": "Fed Policy Uncertainty",
"whoGains": "Risk-averse investors",
"whoPays": "Growth stocks and leveraged positions",
"persistence": "Central bank policy uncertainty creates sustained demand for safe assets",
"channels": ["duration", "credit"],
"invalidators": ["Clear Fed guidance", "Economic data normalization"],
"persistenceScore": 75
}'
Create a Trade
curl -X POST http://localhost:3000/api/trades \
-H "Content-Type: application/json" \
-d '{
"instrument": "TLT",
"venue": "ETF",
"side": "long",
"entry": 95.50,
"stop": 92.00,
"target": 100.00,
"sizeEUR": 1000,
"riskEUR": 35.00,
"notes": "Duration play on Fed uncertainty"
}'
Data Adapters
The system includes pluggable data providers with graceful fallbacks:
Market Data (lib/adapters/marketData.ts)
- Stooq Provider: Free, no API key required
- Mock Provider: Fallback with realistic data
- Symbols: SPY, RSP, IWD, IWF, IWM, QQQ, HYG, LQD, TLT, IEF, GLD, IAU, UUP, BTC-USD, ETH-USD, VIX, VXV
Derived Metrics (lib/adapters/derived.ts)
- Computes inequality-aware tiles from market data
- Historical data for sparklines
- Safe division handling for missing data
Macro Data (lib/adapters/macro.ts)
- Policy rates, inflation, real rates
- High yield spreads, TIPS yields
- Mock data for MVP (easily replaceable with real APIs)
Rules Engine
Color Thresholds
- Breadth: < 0.95 (red), 0.95-0.98 (amber), > 0.98 (green)
- Small/Large: < 0.70 (red), 0.70-0.80 (amber), > 0.80 (green)
- Real Rate: ≤ 0% (green), 0-1% (amber), > 1% (red)
- HY OAS: > 500bp (red), 350-500bp (amber), < 350bp (green)
Alert Rules
- 2+ tiles flip to red in 5 days → “NarrativeRegime” alert
- Trade stop breached → “Invalidator” alert
- News analysis score ≥ 70 → “IncentiveShift” alert
Production Deployment
Environment Variables
DATABASE_URL="file:./prod.db"
NEXT_PUBLIC_APP_URL="https://your-domain.com"
# Optional API keys for real data providers
# ALPHA_VANTAGE_API_KEY=""
# TIINGO_API_KEY=""
# POLYGON_API_KEY=""
# NEWS_API_KEY=""
Database Migration
pnpm prisma migrate deploy
pnpm prisma db seed
Build and Start
pnpm build
pnpm start
Extending the System
Adding Real Data Providers
- Implement the
MarketDataProviderinterface - Add provider to
MarketDataServiceconstructor - Update environment variables
Adding New Tiles
- Add to
DerivedMetricsService.computeMetrics() - Add color rules to
RulesEngine - Update
TileGridcomponent - Add to database migration
Adding New Alert Types
- Add to
AlertRuletype inrules.ts - Implement condition logic
- Update alert creation in cron jobs
Architecture
even/
├── app/ # Next.js App Router
│ ├── api/ # API routes
│ │ ├── cron/ # Manual cron endpoints
│ │ └── ... # Core APIs
│ ├── even/ # Main app pages
│ └── globals.css # Global styles
├── components/ # React components
│ ├── ui/ # shadcn/ui components
│ └── ... # Custom components
├── lib/ # Core logic
│ ├── adapters/ # Data providers
│ ├── repositories/ # Database layer
│ ├── rules.ts # Rules engine
│ └── validations.ts # Zod schemas
├── prisma/ # Database schema & migrations
└── public/ # Static assets
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
License
Private - Unicorn.Land Internal Use Only