diff --git a/common/calculate.ts b/common/calculate.ts index 8560dfab..b5c6818b 100644 --- a/common/calculate.ts +++ b/common/calculate.ts @@ -68,15 +68,22 @@ export function calculateRawShareValue( return currentValue - postSaleValue } -export function calculateMoneyRatio(contract: Contract, amount: number) { +export function calculateMoneyRatio( + contract: Contract, + bet: Bet, + shareValue: number +) { const { totalShares, pool } = contract const p = getProbability(totalShares) - const actual = pool.YES + pool.NO - amount + const actual = pool.YES + pool.NO - shareValue + + const betAmount = + bet.outcome === 'YES' ? p * bet.amount : (1 - p) * bet.amount const expected = - p * contract.totalBets.YES + (1 - p) * contract.totalBets.NO - amount + p * contract.totalBets.YES + (1 - p) * contract.totalBets.NO - betAmount if (actual <= 0 || expected <= 0) return 0 @@ -89,7 +96,7 @@ export function calculateShareValue(contract: Contract, bet: Bet) { bet.shares, bet.outcome ) - const f = calculateMoneyRatio(contract, shareValue) + const f = calculateMoneyRatio(contract, bet, shareValue) const myPool = contract.pool[bet.outcome] const adjShareValue = Math.min(Math.min(1, f) * shareValue, myPool) diff --git a/web/yarn.lock b/web/yarn.lock index 9af034e8..abff3d3e 100644 --- a/web/yarn.lock +++ b/web/yarn.lock @@ -1604,7 +1604,7 @@ create-hmac@^1.1.0, create-hmac@^1.1.4, create-hmac@^1.1.7: safe-buffer "^5.0.1" sha.js "^2.4.8" -critters@^0.0.16: +critters@0.0.16: version "0.0.16" resolved "https://registry.yarnpkg.com/critters/-/critters-0.0.16.tgz#ffa2c5561a65b43c53b940036237ce72dcebfe93" integrity sha512-JwjgmO6i3y6RWtLYmXwO5jMd+maZt8Tnfu7VVISmEWyQqfLpB8soBswf8/2bu6SBXxtKA68Al3c+qIG1ApT68A==