Simplified helper to compute hedge stakes to green up existing positions — adjust for fees and increments before production use.
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
