Skip to content
TheChatArchiveThe Chat Archive
Metallama-4-maverick-17b-128e-instruct· MetaHugging Face LMArena Human Preference 140K

@dataclass class Market: id: str y: float n: float p: float min: int = 0 max: int = 100…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Metallama-4-maverick-03-26-experimental’s answer.
  1. User

    @dataclass class Market: id: str y: float n: float p: float min: int = 0 max: int = 100 k: float = field(init=False)

    def __post_init__(self):
        self.k = constant(self.y, self.n, self.p)
    
    @property
    def probability(self) -> float:
        return probability(self.y, self.n, self.p)
    
    @property
    def value(self) -> float:
        return ((self.max - self.min) * self.probability) + self.min
    
    def bet_yes(self, mana: int) -> Market:
        new_n = self.n + mana
        new_y = yes(new_n, self.p, self.k)
        return Market(self.id, new_y, new_n, self.p, self.min, self.max)
    
    def return_for_yes(self, mana: int) -> Tuple[float, float]:
        new_market = self.bet_yes(mana)
        return self.y + mana - new_market.y, new_market.probability
    
    def bet_no(self, mana: int) -> Market:
        new_y = self.y + mana
        new_n = no(new_y, self.p, self.k)
        return Market(self.id, new_y, new_n, self.p, self.min, self.max)
    
    def return_for_no(self, mana: int) -> Tuple[float, float]:
        new_market = self.bet_no(mana)
        return self.n + mana - new_market.n, new_market.probability
    
    # how much mana to spend to get to prob
    def mana_for_prob(self, prob: float, max_mana: int = 1000) -> int:
        assert 0 < prob < 1
        mult = 1
        if prob < self.probability:
            # buy NO
            mult = -1
            outcomes = [abs(self.return_for_no(mana)[1] - prob)
                        for mana in range(0, max_mana + 1)]
        else:
            # buy YES
            outcomes = [abs(self.return_for_yes(mana)[1] - prob)
                        for mana in range(0, max_mana + 1)]
        smallest_index = outcomes.index(min(outcomes))
        if smallest_index > max_mana:
            return 0
        return smallest_index * mult
    

    def market_from_manifold_market(market: dict) -> Market: p = market["p"] n = market["pool"]['NO'] y = market["pool"]['YES'] min = market.get("min", 0) max = market.get("max", 100) return Market(market['id'], y, n, p, min, max)

    def constant(y: float, n: float, p: float) -> float: # k = y^p * n^(1-p) return pow(y, p) * pow(n, 1 - p)

    def probability(y: float, n: float, p: float) -> float: return p * n/(p*n + (1-p) * y)

    def yes(n: float, p: float, k: float) -> float: return pow((k/pow(n, 1-p)), 1/p)

    def no(y: float, p: float, k: float) -> float: return pow((k/pow(y, p)), 1/(1-p))

  2. Meta Assistant

    The code you've provided is implementing a prediction market model based on a specific type of automated market maker (AMM). The AMM is using a formula that involves the "YES" and "NO" pool sizes (y and n), a probability p, and a constant k derived from these parameters.

    To maximize arbitrage profit between two markets with the same resolution criteria but different probabilities, you can use the Market class and its methods to simulate trades and find the optimal amount of "mana" to spend.

    Here's a step-by-step guide to achieve this:

    1. Create Market objects for both markets:

      • Use the market_from_manifold_market function to create Market objects from the market data.
    2. Determine the target probability:

      • The target probability is the probability at which you want to converge the two markets. You can calculate this by finding a probability that is between the current probabilities of the two markets.
    3. Calculate the amount of "mana" to spend in each market:

      • Use the mana_for_prob method to calculate the amount of "mana" needed to reach the target probability in each market.
    4. Simulate trades and check for convergence:

      • Use the bet_yes and bet_no methods to simulate trades in each market.
      • Check if the probabilities of the two markets have converged after the trades.
    5. Optimize the amount of "mana" to spend:

      • You can use a binary search approach to find the optimal amount of "mana" to spend.
      • Start with a range of possible "mana" values and iteratively narrow down the range until you find the optimal amount.

    Here's some sample code to demonstrate this:

    def find_optimal_mana(market1: Market, market2: Market, max_mana: int = 1000) -> Tuple[int, int]:
        # Determine the target probability
        target_prob = (market1.probability + market2.probability) / 2
    
        # Calculate the amount of "mana" to spend in each market
        mana1 = market1.mana_for_prob(target_prob, max_mana)
        mana2 = market2.mana_for_prob(target_prob, max_mana)
    
        # If mana1 is negative, it means we need to buy "NO" in market1
        if mana1 < 0:
            new_market1 = market1.bet_no(-mana1)
        else:
            new_market1 = market1.bet_yes(mana1)
    
        # If mana2 is negative, it means we need to buy "NO" in market2
        if mana2 < 0:
            new_market2 = market2.bet_no(-mana2)
        else:
            new_market2 = market2.bet_yes(mana2)
    
        # Check if the probabilities have converged
        if abs(new_market1.probability - new_market2.probability) < 0.01:
            return abs(mana1), abs(mana2)
        else:
            # Adjust the target probability and repeat the process
            if new_market1.probability > new_market2.probability:
                target_prob -= 0.01
            else:
                target_prob += 0.01
            return find_optimal_mana(market1, market2, max_mana)
    
    # Create Market objects
    market1_data = {...}  # data for market 1
    market2_data = {...}  # data for market 2
    market1 = market_from_manifold_market(market1_data)
    market2 = market_from_manifold_market(market2_data)
    
    # Find the optimal amount of "mana" to spend
    mana1, mana2 = find_optimal_mana(market1, market2)
    

    This code will help you find the optimal amount of "mana" to spend in each market to converge their probabilities. You can then use this information to execute trades and maximize your arbitrage profit.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.