Green‑up helper — JavaScript

Simplified helper to compute hedge stakes to green up existing positions — adjust for fees and increments before production use.

Green‑up helper — JavaScript

JavaScript

Category: Code Library  •  Tags: javascript, hedging, greenup  •  Published: PUBLISH_DATE

Code — copyable

      Copy// positions: [{ price, stake, side: 'BACK'|'LAY' }]
function computeGreenup(positions, hedgePrice) {
  const backProfit = positions.filter(p => p.side === 'BACK').reduce((s, p) => s + p.stake * (p.price - 1), 0);
  const layLiability = positions.filter(p => p.side === 'LAY').reduce((s, p) => s + p.stake, 0);
  // simplified: hedgeStake * (hedgePrice - 1) + layLiability = backProfit
  const hedgeStake = (backProfit - layLiability) / (hedgePrice - 1);
  return { hedgeStake: Math.max(0, parseFloat(hedgeStake.toFixed(2))) };
}
module.exports = { computeGreenup };

Notes

  • Round stakes to market increments and include fees when computing hedge amounts.
  • Test across multiple outcomes and small stakes before automating.

License: MIT

Back to Code Library

Don’t miss our blog post!

We don’t spam! Read our privacy policy for more info.

Leave a Reply

Your email address will not be published. Required fields are marked *