Skip to content

feat(synth-overlay): balance-aware Kelly position sizing (Closes #31)#36

Closed
MkDev11 wants to merge 1 commit intoentrius:mainfrom
MkDev11:feature/issue-31-kelly-position-sizing
Closed

feat(synth-overlay): balance-aware Kelly position sizing (Closes #31)#36
MkDev11 wants to merge 1 commit intoentrius:mainfrom
MkDev11:feature/issue-31-kelly-position-sizing

Conversation

@MkDev11
Copy link
Contributor

@MkDev11 MkDev11 commented Mar 11, 2026

feat(synth-overlay): balance-aware Kelly position sizing

Add Position Sizing card to the Synth Overlay side panel that calculates the Kelly-optimal bet size for Polymarket binary markets.

Closes #31

Summary

Turns the existing edge + confidence signals into a concrete recommended bet size, so users know how much to wager, not just which side. The side panel now includes a Position Sizing card that reads the user's balance (auto-detected from the Polymarket DOM or entered manually), computes the Kelly-optimal fraction for both YES and NO sides, scales by forecast confidence, caps at 20% of bankroll, and displays the recommended position size in USD.

What's new

  • Balance detection: scrapeBalance() in content.js best-effort detects USDC/USD balance from the Polymarket DOM using 3 context-gated strategies (dollar amounts near "balance/portfolio" keywords, USDC amounts with ancestor context, inline "Balance $X" patterns). Falls back to manual input, persisted via chrome.storage.local.
  • Kelly computation: computeKellySizing() in sidepanel.js implements the full Kelly Criterion formula for binary markets — computes f* = (b·p_true − (1−p_true)) / b for both YES and NO sides, picks the +EV side, scales by confidence score, and caps at 20%.
  • Live recalculation: Sizing updates instantly when live Polymarket prices change (via updateWithLivePrice()) or when the user edits their balance — no refresh needed.
  • Position Sizing UI card: Shows Kelly side (YES/NO/No +EV), fraction of bankroll, recommended size in USD, and EV per $1. Side is color-coded green (YES) / red (NO) / gray (No +EV). A contextual note appears when the 20% cap is active.
  • Python reference + tests: kelly.py mirrors the JS logic for testability. 20 pytest tests cover basic behavior, edge cases, cap enforcement, formula correctness, and symmetry.

Related Issues

Closes #31

Type of Change

  • Bug fix
  • Improvement to existing tool
  • Documentation
  • Other (describe below)

Files Changed

File Purpose
tools/synth-overlay/extension/content.js Add scrapeBalance() with 3 context-gated DOM strategies; extend getContext() to include balance
tools/synth-overlay/extension/sidepanel.html Add Position Sizing card with balance input, Kelly side/fraction/size/EV fields, dynamic note
tools/synth-overlay/extension/sidepanel.css Styles for sizing card, balance input, YES/NO/No+EV color classes, cap note
tools/synth-overlay/extension/sidepanel.js computeKellySizing(), updateSizingUI(), initSizing(), loadStoredBalance(), saveStoredBalance(); wire into refresh() and updateWithLivePrice()
tools/synth-overlay/kelly.py Python reference implementation of Kelly logic (mirrors JS)
tools/synth-overlay/tests/test_kelly.py 20 tests: basic behavior, edge cases, cap, formula, symmetry
tools/synth-overlay/README.md Add Position Sizing section documenting the feature

Testing

  • Tested against Synth API
  • Manually tested
  • Tests added/updated

Demo Video

recording-2026-03-11-17-55-37.webm

…ius#31)

Add Position Sizing card to the Synth Overlay side panel that calculates
the Kelly-optimal bet size for Polymarket binary markets.

- content.js: add scrapeBalance() to detect USDC/USD balance from DOM,
  extend getContext() to include balance field
- sidepanel.html: add Position Sizing card with balance input, Kelly side,
  fraction, recommended size, and EV per dollar fields
- sidepanel.css: styles for the new sizing card and balance input
- sidepanel.js: implement computeKellySizing() with full Kelly formula for
  both YES/NO sides, confidence scaling, 20% bankroll cap; add balance
  persistence via chrome.storage.local; wire sizing into refresh() and
  updateWithLivePrice() for instant recalculation
- kelly.py: Python reference implementation of the Kelly logic for testing
- tests/test_kelly.py: 20 tests covering basic behavior, edge cases,
  cap enforcement, formula correctness, and symmetry
@MkDev11 MkDev11 force-pushed the feature/issue-31-kelly-position-sizing branch from cf42525 to e7ed495 Compare March 11, 2026 18:05
@e35ventura e35ventura closed this Mar 11, 2026
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.

Synth Overlay: Balance-Aware Position Sizing with Kelly Criterion (updated)

2 participants