getNumericBets
This commit is contained in:
parent
dc032c502a
commit
47f18cb307
|
@ -8,6 +8,7 @@ import {
|
||||||
NumericContract,
|
NumericContract,
|
||||||
} from './contract'
|
} from './contract'
|
||||||
import { DPM_FEES } from './fees'
|
import { DPM_FEES } from './fees'
|
||||||
|
import { normpdf } from './normal'
|
||||||
|
|
||||||
export function getDpmProbability(totalShares: { [outcome: string]: number }) {
|
export function getDpmProbability(totalShares: { [outcome: string]: number }) {
|
||||||
// For binary contracts only.
|
// For binary contracts only.
|
||||||
|
@ -35,12 +36,30 @@ export function getDpmOutcomeProbabilities(totalShares: {
|
||||||
export function getNumericBets(
|
export function getNumericBets(
|
||||||
contract: NumericContract,
|
contract: NumericContract,
|
||||||
bucket: string,
|
bucket: string,
|
||||||
betAmount: number
|
betAmount: number,
|
||||||
|
std = 0.05
|
||||||
) {
|
) {
|
||||||
const { totalShares, bucketCount } = contract
|
const { bucketCount } = contract
|
||||||
|
const bucketNumber = parseInt(bucket)
|
||||||
|
const buckets = _.range(0, bucketNumber)
|
||||||
|
|
||||||
const bucketNum = +bucket
|
const mean = bucketNumber / bucketCount
|
||||||
// const bucketRange =
|
|
||||||
|
const allDensities = buckets.map((i) => normpdf(i / bucketCount, mean, std))
|
||||||
|
const densitySum = _.sum(allDensities)
|
||||||
|
|
||||||
|
const rawBetAmounts = allDensities
|
||||||
|
.map((d) => (d / densitySum) * betAmount)
|
||||||
|
.map((x) => (x >= 1 / bucketCount ? x : 0))
|
||||||
|
|
||||||
|
const rawSum = _.sum(rawBetAmounts)
|
||||||
|
const scaledBetAmounts = rawBetAmounts.map((x) => (x / rawSum) * betAmount)
|
||||||
|
|
||||||
|
const bets = scaledBetAmounts
|
||||||
|
.map((x, i) => (x > 0 ? [i.toString(), x] : undefined))
|
||||||
|
.filter((x) => x != undefined) as [string, number][]
|
||||||
|
|
||||||
|
return bets
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getDpmOutcomeProbabilityAfterBet(
|
export function getDpmOutcomeProbabilityAfterBet(
|
||||||
|
|
9
common/normal.ts
Normal file
9
common/normal.ts
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
export function normpdf(x: number, mean = 0, std = 1) {
|
||||||
|
if (std === 0) {
|
||||||
|
return x === mean ? Infinity : 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return Math.exp((-0.5 * Math.pow(x - mean, 2)) / std) / Math.sqrt(TAU * std)
|
||||||
|
}
|
||||||
|
|
||||||
|
const TAU = Math.PI * 2
|
Loading…
Reference in New Issue
Block a user