Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Geometric, no rounding
- # Mostly stolen from https://pastebin.com/1Ti9FT7k
- import requests
- import json
- import time
- import numpy as np
- MAX_COUNT = 20 # number of pages of bets, counting by 1000
- # times retrieved from https://manifold.markets/api/v0/slug/will-the-geometric-mean-of-this-mar
- START_TIME = 1681270853000 # 4/11/23 11:40:53 PM ET
- END_TIME = 1682999940000 # 5/1/2023 11:59:00 PM ET
- NOW = time.time()*1e3
- timepassed = NOW - START_TIME
- timeleft = END_TIME - NOW
- totaltime = END_TIME - START_TIME
- END_TIME = NOW
- NEEDED = np.exp(-1)
- def loadMarket():
- response = requests.get('https://manifold.markets/api/v0/market/will-the-geometric-mean-of-this-mar')
- def loadBets():
- ret = []
- i = 0
- lastId = None
- while True:
- response = requests.get(
- 'https://manifold.markets/api/v0/bets',
- params={'limit': 1000, 'before': lastId, 'contractSlug': 'will-the-geometric-mean-of-this-mar'}
- )
- bets = json.loads(response.content)
- print('loaded a set of bets')
- if len(bets) == 0 or i > MAX_COUNT:
- print('finished at', i)
- print('lastId', lastId)
- return ret
- for bet in bets:
- if bet.get('isRedemption'):
- # this is a payout, not a bet
- continue
- ret.append(bet)
- lastId = bets[-1]['id']
- i += 1
- def calculateLogAverage(bets):
- currentSum = 0
- currentProb = 0.5
- currentTime = START_TIME
- for bet in bets:
- for fill in bet['fills']:
- if 'limitProb' in bet and fill.get('matchedBetId') != None:
- # we can ignore this fill, as it's a limit order fill that will be matched by another bet
- continue
- timeDiff = fill['timestamp'] - currentTime
- currentSum += np.log(currentProb) * timeDiff
- currentProb = bet['probAfter']
- currentTime = fill['timestamp']
- # account for the time after the last bet
- timeDiff = END_TIME - currentTime
- currentSum += np.log(currentProb) * timeDiff
- average = currentSum / (END_TIME - START_TIME)
- return average
- def main():
- global bets
- bets = loadBets()
- # we could extract fills and sort by timestamp but in practice this will be the same
- bets.sort(key=lambda bet: bet["createdTime"])
- global average
- average = np.exp(calculateLogAverage(bets))
- print('current average', average)
- print('needed', NEEDED)
- print('difference', average-NEEDED)
- main()
- fracpassed = timepassed/totaltime
- fracleft = timeleft/totaltime
- timeratio = timepassed/timeleft
- required = np.exp(-1/fracleft)/average**timeratio
- print('Future mean required for 1/e:',required)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement