Advertisement
Guest User

Geometric mean market

a guest
Apr 23rd, 2023
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. # Geometric, no rounding
  2. # Mostly stolen from https://pastebin.com/1Ti9FT7k
  3.  
  4. import requests
  5. import json
  6. import time
  7. import numpy as np
  8.  
  9. MAX_COUNT = 20 # number of pages of bets, counting by 1000
  10. # times retrieved from https://manifold.markets/api/v0/slug/will-the-geometric-mean-of-this-mar
  11. START_TIME = 1681270853000 # 4/11/23 11:40:53 PM ET
  12. END_TIME = 1682999940000 # 5/1/2023 11:59:00 PM ET
  13. NOW = time.time()*1e3
  14. timepassed = NOW - START_TIME
  15. timeleft = END_TIME - NOW
  16. totaltime = END_TIME - START_TIME
  17. END_TIME = NOW
  18. NEEDED = np.exp(-1)
  19.  
  20. def loadMarket():
  21. response = requests.get('https://manifold.markets/api/v0/market/will-the-geometric-mean-of-this-mar')
  22.  
  23. def loadBets():
  24. ret = []
  25.  
  26. i = 0
  27. lastId = None
  28.  
  29. while True:
  30. response = requests.get(
  31. 'https://manifold.markets/api/v0/bets',
  32. params={'limit': 1000, 'before': lastId, 'contractSlug': 'will-the-geometric-mean-of-this-mar'}
  33. )
  34. bets = json.loads(response.content)
  35. print('loaded a set of bets')
  36.  
  37. if len(bets) == 0 or i > MAX_COUNT:
  38. print('finished at', i)
  39. print('lastId', lastId)
  40. return ret
  41.  
  42. for bet in bets:
  43. if bet.get('isRedemption'):
  44. # this is a payout, not a bet
  45. continue
  46. ret.append(bet)
  47.  
  48. lastId = bets[-1]['id']
  49. i += 1
  50.  
  51. def calculateLogAverage(bets):
  52. currentSum = 0
  53. currentProb = 0.5
  54. currentTime = START_TIME
  55. for bet in bets:
  56. for fill in bet['fills']:
  57. if 'limitProb' in bet and fill.get('matchedBetId') != None:
  58. # we can ignore this fill, as it's a limit order fill that will be matched by another bet
  59. continue
  60. timeDiff = fill['timestamp'] - currentTime
  61. currentSum += np.log(currentProb) * timeDiff
  62. currentProb = bet['probAfter']
  63. currentTime = fill['timestamp']
  64.  
  65. # account for the time after the last bet
  66. timeDiff = END_TIME - currentTime
  67. currentSum += np.log(currentProb) * timeDiff
  68.  
  69. average = currentSum / (END_TIME - START_TIME)
  70. return average
  71.  
  72. def main():
  73. global bets
  74. bets = loadBets()
  75. # we could extract fills and sort by timestamp but in practice this will be the same
  76. bets.sort(key=lambda bet: bet["createdTime"])
  77. global average
  78. average = np.exp(calculateLogAverage(bets))
  79. print('current average', average)
  80. print('needed', NEEDED)
  81. print('difference', average-NEEDED)
  82.  
  83. main()
  84.  
  85. fracpassed = timepassed/totaltime
  86. fracleft = timeleft/totaltime
  87. timeratio = timepassed/timeleft
  88. required = np.exp(-1/fracleft)/average**timeratio
  89. print('Future mean required for 1/e:',required)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement