Skip to content

zh3nl/Posterity

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Posterity - Polymarket Analytics Dashboard

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.

Overview

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.

Features

🎯 Landing Page & Navigation

  • Interactive terminal-style background with pixel animations
  • Smooth navigation between landing page and dashboard
  • Modern glassmorphism design with responsive layout

πŸ“Š Market Analysis

  • 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

πŸ€– AI-Powered Discovery

  • 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

πŸ“ˆ Statistical Features

  • 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

Tech Stack

Frontend

  • 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

Backend & APIs

  • 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)

Statistical Computing

  • 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

Getting Started

Prerequisites

  • Node.js 18+ and npm
  • OpenAI API key (Get one here)
  • Modern web browser with JavaScript enabled

Quick Start

  1. Clone the repository:
git clone <repository-url>
cd posterity
  1. Install dependencies:
npm install
  1. Set up environment variables: Create a .env.local file in the root directory:
OPENAI_API_KEY=your-openai-api-key-here
  1. Start the development server:
npm run dev
  1. Open the application: Navigate to http://localhost:3000 in your browser

Alternative Commands

# 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

Usage

Viewing Markets

  1. Markets are automatically loaded from the Polymarket API
  2. Use the search box to filter by keywords
  3. Use the category dropdown to filter by market category

Statistical Analysis

  1. Select Markets: Choose exactly 2 markets from the list by clicking on them
  2. Navigate to Charts: Go to the "Price Charts" tab
  3. View Basic Stats: See Pearson correlation coefficient automatically calculated
  4. 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
  5. Chart Options:
    • Toggle "Normalize Scale" to view markets on a 0-100 scale
    • Select different time intervals (1h, 1d, 1w)
    • Enable/disable correlation display

AI Discovery

  1. Select multiple markets (at least 2)
  2. Navigate to the "AI Discovery" tab
  3. Click "Discover Correlations"
  4. View AI-generated insights about semantic and statistical correlations

API Routes

  • GET /api/markets - Fetch all markets with optional filters (from Polymarket Gamma API)
  • GET /api/markets/[id] - Fetch a specific market by ID
  • GET /api/markets/[id]/candlesticks - Fetch price history for a market (from Polymarket CLOB API)
  • POST /api/discover - AI correlation discovery endpoint with semantic analysis

Project Structure

β”œβ”€β”€ 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

How It Works

Statistical Analysis Engine

  • 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

AI Discovery

  1. Semantic Analysis: Generates embeddings for market questions and descriptions using OpenAI's text-embedding-3-large model
  2. Similarity Calculation: Computes cosine similarity between embedding vectors
  3. Price Correlation: Calculates statistical correlation between historical price movements
  4. AI Reasoning: Uses GPT-4 to explain why markets might be correlated
  5. Filtering: Returns top correlations based on combined semantic and statistical scores

Cost Considerations

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.

Development

# 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

Future Enhancements

  • 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

License

MIT

Acknowledgments

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors