A sophisticated Next.js web application for analyzing Polymarket prediction markets with advanced statistical analysis, interactive visualizations, and AI-powered correlation discovery. Find signal from noise in prediction market data.
Posterity is a comprehensive analytics platform designed for traders, researchers, and analysts interested in prediction market dynamics. The application combines real-time market data with cutting-edge statistical analysis and AI-powered insights to help users identify relationships between different prediction markets.
- Interactive terminal-style background with pixel animations
- Smooth navigation between landing page and dashboard
- Modern glassmorphism design with responsive layout
- Market Browser: Browse and search live Polymarket prediction markets with filtering
- Price Charts: Overlay and compare multiple market price movements using TradingView Lightweight Charts
- Advanced Statistics: Calculate Pearson correlation coefficients and conditional probabilities
- Joint Probability Analysis: Estimate P(X and Y) using multiple approaches with confidence intervals
- Semantic Analysis: OpenAI embeddings to find conceptually related markets
- Statistical Correlation: Automated discovery of price movement relationships
- GPT-4 Insights: AI-generated explanations for market correlations
- Combined Scoring: Hybrid semantic + statistical correlation ranking
- Pearson correlation coefficient calculation
- Conditional probability estimates: P(X|Y), P(X|not Y), P(Y|X), P(Y|not X)
- Joint probability estimation with multiple methods
- Standard deviation and regression parameter display
- Probability clipping and validation
- Framework: Next.js 14 with App Router
- Language: TypeScript for type safety
- Styling: TailwindCSS with custom components
- UI Components: Custom pixel animations, terminal effects, glassmorphism design
- Charts: TradingView Lightweight Charts for professional market visualization
- API Routes: Next.js API routes for server-side processing
- Data Sources:
- Polymarket Gamma API (live market data)
- Polymarket CLOB API (historical price data)
- AI Integration: OpenAI API (text-embedding-3-large, GPT-4)
- Correlation Analysis: Custom Pearson correlation implementation
- Time Series: Advanced alignment and normalization algorithms
- Probability Calculations: Conditional and joint probability estimation
- Linear Regression: Custom implementation for market relationship modeling
- Node.js 18+ and npm
- OpenAI API key (Get one here)
- Modern web browser with JavaScript enabled
- Clone the repository:
git clone <repository-url>
cd posterity- Install dependencies:
npm install- Set up environment variables:
Create a
.env.localfile in the root directory:
OPENAI_API_KEY=your-openai-api-key-here- Start the development server:
npm run dev- Open the application: Navigate to http://localhost:3000 in your browser
# Install dependencies
npm install
# Run development server (with hot reload)
npm run dev
# Build for production
npm run build
# Start production server
npm start
# Run linter
npm run lint- Markets are automatically loaded from the Polymarket API
- Use the search box to filter by keywords
- Use the category dropdown to filter by market category
- Select Markets: Choose exactly 2 markets from the list by clicking on them
- Navigate to Charts: Go to the "Price Charts" tab
- View Basic Stats: See Pearson correlation coefficient automatically calculated
- Advanced Analysis: View conditional probabilities:
- P(X|Y) and P(X|not Y) for the first market
- P(Y|X) and P(Y|not X) for the second market
- Joint probability estimates P(X and Y) with multiple methods
- Chart Options:
- Toggle "Normalize Scale" to view markets on a 0-100 scale
- Select different time intervals (1h, 1d, 1w)
- Enable/disable correlation display
- Select multiple markets (at least 2)
- Navigate to the "AI Discovery" tab
- Click "Discover Correlations"
- View AI-generated insights about semantic and statistical correlations
GET /api/markets- Fetch all markets with optional filters (from Polymarket Gamma API)GET /api/markets/[id]- Fetch a specific market by IDGET /api/markets/[id]/candlesticks- Fetch price history for a market (from Polymarket CLOB API)POST /api/discover- AI correlation discovery endpoint with semantic analysis
βββ app/
β βββ api/ # API routes
β β βββ markets/ # Market data endpoints
β β β βββ [id]/
β β β βββ candlesticks/ # Price history endpoint
β β βββ discover/ # AI discovery endpoint
β βββ dashboard/ # Dashboard page
β β βββ page.tsx # Main analytics dashboard
β βββ globals.css # Global styles
β βββ layout.tsx # Root layout
β βββ page.tsx # Landing page
βββ components/
β βββ LandingPage.tsx # Landing page with terminal effects
β βββ MarketList.tsx # Market browser component
β βββ ChartComparison.tsx # Advanced chart visualization with statistics
β βββ DiscoveryTab.tsx # AI discovery interface
β βββ FaultyTerminal.tsx # Interactive terminal background
β βββ PixelCard.tsx # Animated pixel card components
β βββ DecryptedText.tsx # Text animation component
βββ lib/
β βββ types.ts # TypeScript interfaces
β βββ correlation.ts # Statistical analysis utilities
βββ package.json
- Time Series Processing: Advanced alignment algorithms for different market time stamps
- Correlation Analysis: Pearson correlation coefficient calculation with proper data alignment
- Conditional Probabilities: Estimates P(X|Y), P(X|not Y), P(Y|X), P(Y|not X) using linear regression
- Joint Probability: Multiple estimation methods for P(X and Y) with confidence measures
- Data Validation: Automatic probability clipping to [0,1] range and outlier detection
- Visualization: TradingView Lightweight Charts with professional market styling
- Semantic Analysis: Generates embeddings for market questions and descriptions using OpenAI's text-embedding-3-large model
- Similarity Calculation: Computes cosine similarity between embedding vectors
- Price Correlation: Calculates statistical correlation between historical price movements
- AI Reasoning: Uses GPT-4 to explain why markets might be correlated
- Filtering: Returns top correlations based on combined semantic and statistical scores
The AI Discovery feature uses OpenAI's API which incurs costs:
- Embeddings: ~$0.00013 per 1K tokens (text-embedding-3-large)
- Chat: ~$0.03 per 1K tokens (GPT-4)
For typical usage (10-20 markets), expect costs under $0.10 per discovery request.
# Install dependencies
npm install
# Run development server
npm run dev
# Build for production
npm run build
# Start production server
npm start
# Run linter
npm run lint- Add database caching for faster loads
- Implement WebSocket for real-time price updates
- Add more chart types (candlesticks, volume)
- Create shareable dashboard views
- Add user authentication and saved watchlists
MIT
- Data provided by Polymarket
- Charts powered by TradingView Lightweight Charts
- AI powered by OpenAI