calculateMoneyRatio

This commit is contained in:
mantikoros 2022-01-15 00:11:27 -06:00
parent e12e399679
commit a0be5b6394
2 changed files with 12 additions and 5 deletions

View File

@ -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)

View File

@ -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==