Polymarket Quant Trader
A professional quant trading system for Polymarket prediction markets, built and battle-tested in production. Three alpha streams. One integrated system.
Overview
This skill gives you a complete quantitative trading system for Polymarket with three independent alpha streams:
- 1. EV-Based Signal Trading — Kelly Criterion position sizing + Bayesian probability updating. Find edges, size them correctly, update beliefs as evidence arrives.
- Self-Improving Strategy (Autoresearch Loop) — An autonomous hill-climbing optimizer that tunes your strategy parameters overnight using Brier score as the objective function. Wake up to a better strategy.
- Cross-Platform Arbitrage (PM x 1WIN) — Detect spread discrepancies between Polymarket and 1WIN bookmaker. Fuzzy title matching, confidence tiering, Kelly-sized positions.
Each stream works independently or together. The system ships with TypeScript source, npm scripts for every workflow, and a backtester to validate before going live.
Current production performance: Brier score 0.18 (meaningful edge territory — baseline random is 0.25, professional is sub-0.12).
Stream 1: EV-Based Signal Trading
How It Works
The core loop: estimate a probability, compare it to the market price, calculate expected value, size the position with Kelly Criterion, and update beliefs as new evidence arrives.
Kelly Criterion Position Sizing
Kelly answers: "Given my edge, what fraction of my bankroll should I bet?"
The formula:
CODEBLOCK0
In prediction markets, odds derive from the market price:
CODEBLOCK1
If YES trades at $0.40, then b = 0.60/0.40 = 1.5 (you risk $0.40 to win $0.60).
Implementation:
CODEBLOCK2
Why quarter Kelly? Full Kelly maximizes long-run growth rate but produces brutal drawdowns (50%+ swings). Quarter Kelly captures ~75% of the growth rate with dramatically lower variance. Every serious quant fund uses fractional Kelly.
EV Calculator
Expected value quantifies your edge per dollar risked:
CODEBLOCK3
Reading the output: An edgePct of 5% means your model thinks the market is mispriced by 5%. The recommend flag fires when EV is positive AND edge exceeds 2% (below that, transaction costs eat your edge).
Bayesian Probability Updater
Update your probability estimates as new evidence arrives:
CODEBLOCK4
Likelihood ratios: A ratio of 2.0 means "this evidence is twice as likely if YES is true." A ratio of 0.5 means "this evidence is twice as likely if NO is true." The Bayesian updater chains multiple evidence items — each update feeds the next as a new prior.
Market Scorer (Composite Ranking)
Combines all signals into a single score for market selection:
CODEBLOCK5
Markets scoring highest get traded first. The expiry window filter avoids two failure modes: too-short expiry (can't exit if wrong) and too-long expiry (capital locked up, edge decays).
Stream 2: Self-Improving Strategy (Autoresearch Loop)
The Brier Score Metric
Brier score measures prediction calibration — how close your probability estimates are to actual outcomes:
CODEBLOCK6
Interpretation scale:
| Score | Level | Meaning |
|---|
| 0.25 | Random | Coin-flip predictions |
| 0.22 |
Weak edge | Slightly better than random |
| 0.18 | Meaningful edge | Consistent alpha |
| 0.12 | Professional | Elite forecaster territory |
| < 0.10 | Superforecaster | Top 1% calibration |
Lower is better. The system tracks Brier score as the primary optimization objective.
Strategy Configuration
The strategy is defined by tunable parameters:
CODEBLOCK7
Prediction logic:
CODEBLOCK8
Running the Autoresearch Loop
CODEBLOCK9
How research:auto works:
- 1. Loads current strategy config
- Tries a parameter mutation (e.g., minEdgePct 3.0 → 2.5)
- Evaluates against all resolved markets → gets Brier score
- If Brier improved → keep change, bump version, save checkpoint
- If Brier worsened → revert to backup
- Move to next untried mutation
- Stop when all mutations exhausted without improvement
Parameter search space:
CODEBLOCK10
Reading the Iteration Log
Results are logged to research/program.md:
CODEBLOCK11
Breaking a Plateau
When auto-improve exhausts its search space without improvement:
- 1. Inject a hypothesis manually — Edit
research/strategy.ts with a theory (e.g., "crypto markets are less efficient after 10pm UTC") and run INLINECODE5 - Add new data — More resolved markets = more signal for the optimizer
- Change the objective — Weight Brier + Sharpe ratio instead of pure Brier
- Try category-specific strategies — Separate configs for sports vs politics vs crypto
Stream 3: Cross-Platform Arbitrage (PM x 1WIN)
How Spread Arbitrage Works
When two platforms price the same event differently, you can profit from the spread:
CODEBLOCK12
If Polymarket says 40% and 1WIN says 35.7%, Polymarket is pricing YES higher. The direction depends on which platform you think is wrong — or you can bet both sides if the spread exceeds the combined vig.
Spread Calculator
CODEBLOCK13
Running the Arb Scanner
CODEBLOCK14
What it does:
- 1. Fetches active Polymarket markets (sports/crypto, expires within 48h, volume > 0)
- Fetches 1WIN events via API (with fallback to CLOB proxy if geo-blocked)
- Fuzzy-matches event titles across platforms (Dice coefficient, 0.4 threshold)
- Calculates spreads for all matches
- Tiers by confidence (HIGH/MEDIUM/LOW)
- Returns top 20 opportunities sorted by spread percentage
Reading the output:
CODEBLOCK15
Title Matching
The fuzzy matcher handles cross-platform naming differences:
CODEBLOCK16
Continuous Monitoring
CODEBLOCK17
Setup Guide
1. Clone and Install
CODEBLOCK18
2. Configure Environment
Copy .env.example to .env and fill in:
CODEBLOCK19
3. Run Each Stream
CODEBLOCK20
Recipes
Recipe 1: Morning Scan for Arb Opportunities
CODEBLOCK21
Recipe 2: Run Overnight Strategy Improvement
CODEBLOCK22
Recipe 3: Check Portfolio EV
CODEBLOCK23
Recipe 4: Add a New Market to the Bayesian Tracker
CODEBLOCK24
Recipe 5: Backtest a Strategy Change
CODEBLOCK25
Architecture Notes
The system is modular by design. Each quant module (kelly-criterion.ts, ev-calculator.ts, bayesian-updater.ts) is pure functions with no side effects — they can be imported independently into any project. The research loop operates on strategy.ts as a single source of truth, with versioned checkpoints for rollback. The arbitrage detector cascades through data sources (1WIN API → CLOB proxy → mock) for reliability.
All trading respects risk constraints: MAX_POSITION_SIZE, STOP_LOSS_PERCENT, and DRY_RUN mode. Start with paper trading. Always.
Polymarket 量化交易员
一个面向Polymarket预测市场的专业量化交易系统,已在生产环境中构建并经过实战检验。三个阿尔法流。一个集成系统。
概述
本技能为您提供一套完整的Polymarket量化交易系统,包含三个独立的阿尔法流:
- 1. 基于期望值的信号交易 — 凯利准则仓位管理 + 贝叶斯概率更新。发现优势,正确配置仓位,随着证据出现更新信念。
- 自我改进策略(自动研究循环) — 一个自主爬山优化器,使用布里尔分数作为目标函数,在夜间调整您的策略参数。醒来时获得更好的策略。
- 跨平台套利(Polymarket × 1WIN) — 检测Polymarket与1WIN博彩公司之间的价差。模糊标题匹配、置信度分级、凯利仓位管理。
每个流可独立运行或协同工作。系统附带TypeScript源代码、适用于每个工作流的npm脚本,以及上线前验证的回测工具。
当前生产环境表现: 布里尔分数0.18(有意义的优势区间 — 随机基线为0.25,专业水平低于0.12)。
流1:基于期望值的信号交易
工作原理
核心循环:估算概率,与市场价格比较,计算期望值,使用凯利准则配置仓位,并在新证据出现时更新信念。
凯利准则仓位管理
凯利回答的问题是:鉴于我的优势,我应该用多少比例的资金下注?
公式:
f = (p b - q) / b
其中:
f* = 最佳下注资金比例
p = 获胜概率(您的估算,0-1)
b = 净赔率乘数(每1美元风险对应的回报)
q = 1 - p(失败概率)
在预测市场中,赔率来源于市场价格:
b = (1 - 市场YES价格) / 市场YES价格
如果YES交易价格为0.40美元,则b = 0.60/0.40 = 1.5(您承担0.40美元风险以赢得0.60美元)。
实现:
typescript
// kelly-criterion.ts
export function kelly(p: number, b: number, q?: number): number {
const qVal = q ?? 1 - p;
return (p * b - qVal) / b;
}
export function quarterKelly(p: number, b: number): number {
return 0.25 * kelly(p, b);
}
export function kellySizing(
bankroll: number,
p: number,
b: number,
mode: full | half | quarter = quarter
): number {
const fraction = mode === full ? kelly(p, b)
: mode === half ? 0.5 * kelly(p, b)
: quarterKelly(p, b);
return Math.max(0, bankroll * Math.min(fraction, 0.15));
}
为什么用四分之一凯利? 完整凯利能最大化长期增长率,但会产生残酷的回撤(50%以上的波动)。四分之一凯利能捕获约75%的增长率,同时显著降低波动性。每个严肃的量化基金都使用分数凯利。
期望值计算器
期望值量化您每承担一美元风险所获得的优势:
typescript
// ev-calculator.ts
export interface MarketEV {
marketId: string;
ourP: number; // 您估算的概率
marketP: number; // 市场隐含概率(= YES价格)
b: number; // 净赔率:(1 - marketP) / marketP
ev: number; // 每美元风险的期望值
edgePct: number; // 优势占市场价格的百分比
kellyFraction: number; // 四分之一凯利最佳比例
recommend: boolean; // 是否值得交易?(ev > 0 && edgePct >= 2%)
}
export function calcEV(ourProbability: number, marketYesPrice: number) {
const b = (1 - marketYesPrice) / marketYesPrice;
const ev = ourProbability * b - (1 - ourProbability);
const edgePct = (ev / marketYesPrice) * 100;
return { ev, edgePct, b };
}
export function scoreMarket(market: any, ourP: number): MarketEV {
const { ev, edgePct, b } = calcEV(ourP, market.yesPrice);
const kellyFraction = quarterKelly(ourP, b);
return {
marketId: market.id,
ourP,
marketP: market.yesPrice,
b,
ev,
edgePct,
kellyFraction,
recommend: ev > 0 && edgePct >= 2,
};
}
export function rankByEV(markets: MarketEV[]): MarketEV[] {
return [...markets].sort((a, b) => b.ev - a.ev);
}
解读输出: 5%的edgePct意味着您的模型认为市场定价偏差为5%。当期望值为正且优势超过2%时,recommend标志触发(低于此阈值,交易成本会吞噬您的优势)。
贝叶斯概率更新器
随着新证据的出现更新您的概率估算:
typescript
// bayesian-updater.ts
export interface BayesianState {
marketId: string;
priorP: number;
currentP: number;
evidence: Evidence[];
lastUpdated: Date;
}
export interface Evidence {
description: string;
likelihoodRatio: number; // > 1 支持YES,< 1 支持NO
timestamp: Date;
}
export function bayesUpdate(prior: number, likelihoodRatio: number): number {
const posterior = (prior * likelihoodRatio) /
(prior * likelihoodRatio + (1 - prior));
return Math.max(0.001, Math.min(0.999, posterior));
}
export function addEvidence(
state: BayesianState,
evidence: Evidence
): BayesianState {
const newP = bayesUpdate(state.currentP, evidence.likelihoodRatio);
return {
...state,
currentP: newP,
evidence: [...state.evidence, evidence],
lastUpdated: evidence.timestamp,
};
}
export function getRecommendation(
state: BayesianState,
marketPrice: number
): { action: buy | sell | hold; confidence: number; reason: string } {
const diff = state.currentP - marketPrice;
if (Math.abs(diff) < 0.02) return { action: hold, confidence: 0, reason: 在噪音范围内 };
if (diff > 0) return { action: buy, confidence: diff, reason: 模型高于市场${(diff*100).toFixed(1)}% };
return { action: sell, confidence: -diff, reason: 模型低于市场${(-diff*100).toFixed(1)}% };
}
似然比: 比值为2.0意味着如果YES为真,此证据出现的可能性是两倍。比值为0.5意味着如果NO为真,此证据出现的可能性是两倍。贝叶斯更新器可以串联多个证据项——每次更新都作为新的先验输入下一次更新。
市场评分器(综合排名)
将所有信号合并为单一分数,用于市场选择:
typescript
// market-scorer.ts — 加权评分模型
// EV分数: 40%权重 — 优势百分比
// 凯利分数: 30%权重 — 最佳仓位(越高越有信心)
// 到期窗口: 20%权重 — 最佳区间6-72小时
// 成交量分数: 10%权重 — 对数归一化流动性
评分最高的市场优先交易。到期窗口过滤器避免两种失败模式:到期时间过短(如果判断错误无法退出)和到期时间过长(资金被锁定,优势衰减)。
流2:自我改进策略(自动研究循环)
布里尔分数指标
布里尔分数衡量预测校准度——您的概率估算与实际结果的接近程度:
brierScore = mean((预测概率 - 实际结果)^2)
其中 实际结果 = 1(如果解决为YES),0(如果解决为NO)
解读量表:
微弱优势 | 略优于随机 |
| 0.18 | 有意义优势 | 持续阿尔法 |
| 0.12 | 专业水平 | 精英预测者区间 |
| < 0.10 | 超级预测者 | 前1%校准度 |
分数越低越好。系统将布里尔分数作为主要优化目标进行追踪。
策略配置
策略由可调参数定义:
typescript
// research/strategy.ts
export interface StrategyConfig {
minVolume: number; // 最低市场