Skip to content

feat: hedgeBet() — lock in guaranteed profit on line-movement scenarios#26

Merged
ianalloway merged 1 commit into
mainfrom
feat/hedge-bet
Jul 16, 2026
Merged

feat: hedgeBet() — lock in guaranteed profit on line-movement scenarios#26
ianalloway merged 1 commit into
mainfrom
feat/hedge-bet

Conversation

@ianalloway

Copy link
Copy Markdown
Owner

Summary

  • Adds hedgeBet(originalStake, originalAmericanOdds, hedgeAmericanOdds) to the kelly-js API
  • Computes the hedge stake that equalises gross returns across both outcomes (equal-return hedge)
  • Returns hedgeStake, guaranteedProfit, isProfit, roi, totalRisked, and grossReturn

Classic use case: you placed an early-season bet at +300 and the underdog has made the final. The opposite side is now available at +100. hedgeBet(100, 300, 100) tells you to stake $200 on the other side, locking in $100 profit regardless of who wins.

The formula is hedgeStake = originalStake × decimal(originalOdds) / decimal(hedgeOdds), which equalises the gross payout for both outcomes. isProfit is true when that gross return exceeds the combined stakes.

Test plan

  • Profitable-hedge case with exact numbers verified
  • Break-even (identical odds on both sides)
  • Loss scenario (hedge odds shorter than original)
  • Gross-parity property (hedgeStake × dHedge === originalStake × dOrig)
  • Input validation (non-positive stake throws RangeError)
  • npm run lint clean (TypeScript 7 + type check)
  • 148 tests passing

🤖 Generated with Claude Code

Adds hedgeBet(originalStake, originalAmericanOdds, hedgeAmericanOdds)
which computes the stake on the opposite side that equalises gross returns
in both outcomes. Classic use: early underdog bet that has moved in your
favour — calculate exactly how much to hedge for a risk-free profit.

Returns hedgeStake, guaranteedProfit, isProfit, roi, totalRisked, grossReturn.
Five new tests cover the profitable-hedge, break-even, loss, gross-parity,
and input-validation cases.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 14, 2026 18:03
@cursor

cursor Bot commented Jul 14, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@ianalloway
ianalloway merged commit f866282 into main Jul 16, 2026
4 checks passed
@ianalloway
ianalloway deleted the feat/hedge-bet branch July 16, 2026 17:10
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.

2 participants