The textbook solution to the (textbook) pricing problem

The textbook case assumes that there is a finite set of prices that can be set for a homogenous good. This set of possible prices is also the set of possible customer maximum willingnesses to pay (WTP). For the purposes of this illustration, take this set to be the integers from 1 to 10 inclusive. That is, the seller can offer his product for $1, $2, …, $10.

If the seller offers a price equal to or below the current customer’s WTP, his loss for that customer is the WTP minus the offered price, divided by \(N\), , where \(N\) is the highest possible price/WTP in the finite set. For example, if a seller offers his product to a customer for $5, but the customer would have been willing to pay up to $7, his loss for that period will be \(\frac{2}{10}=0.2\). If, on the other hand, the seller offers a price greater than the customer’s WTP, he incurs a fixed loss of \(\frac{c}{N}\), and \(c\) is a parameter between \(0\) and \(N\).

What makes this a partial monitoring problem is that the seller does not have direct access to his actual losses, or the customer’s WTP. The only feedback is whether or not the customer bought the product at the offered price.

We can represent both the actual losses and the feedback as NxN matrices. The textbook contains formulae for each, but I’ll provide a brief conceptual overview here. Each entry in the loss matrix \(L\), \(l(i,j)\), is the loss that would have accrued if the seller offered price \(i\) and the customer had WTP \(j\).


n = 10

L = matrix(numeric(n*n), nrow = n, ncol = n)

c = 7

for (i in 1:n) {
  for (j in 1:n) {
    
    L[j,i] <- (1/n)*(ifelse(i>j, c, j-i))
  }
}

L
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]  0.0  0.7  0.7  0.7  0.7  0.7  0.7  0.7  0.7   0.7
 [2,]  0.1  0.0  0.7  0.7  0.7  0.7  0.7  0.7  0.7   0.7
 [3,]  0.2  0.1  0.0  0.7  0.7  0.7  0.7  0.7  0.7   0.7
 [4,]  0.3  0.2  0.1  0.0  0.7  0.7  0.7  0.7  0.7   0.7
 [5,]  0.4  0.3  0.2  0.1  0.0  0.7  0.7  0.7  0.7   0.7
 [6,]  0.5  0.4  0.3  0.2  0.1  0.0  0.7  0.7  0.7   0.7
 [7,]  0.6  0.5  0.4  0.3  0.2  0.1  0.0  0.7  0.7   0.7
 [8,]  0.7  0.6  0.5  0.4  0.3  0.2  0.1  0.0  0.7   0.7
 [9,]  0.8  0.7  0.6  0.5  0.4  0.3  0.2  0.1  0.0   0.7
[10,]  0.9  0.8  0.7  0.6  0.5  0.4  0.3  0.2  0.1   0.0

Each entry in the feedback matrix \(H\), \(h(i,j)\), is the feedback the seller would have received if he offered price \(i\) and the customer’s WTP was \(j\). For reasons that will become clear later, we will counterintuitively encode cases where the customer buys the product with ‘0’, and cases where the customer does not buy the product with ‘1’.


H = matrix(numeric(n*n), nrow = n, ncol = n)

for (i in 1:n) {
  for (j in 1:n) {
    
    H[j,i] <- (ifelse(i>j, 0, 1))
  }
}

H
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]    1    0    0    0    0    0    0    0    0     0
 [2,]    1    1    0    0    0    0    0    0    0     0
 [3,]    1    1    1    0    0    0    0    0    0     0
 [4,]    1    1    1    1    0    0    0    0    0     0
 [5,]    1    1    1    1    1    0    0    0    0     0
 [6,]    1    1    1    1    1    1    0    0    0     0
 [7,]    1    1    1    1    1    1    1    0    0     0
 [8,]    1    1    1    1    1    1    1    1    0     0
 [9,]    1    1    1    1    1    1    1    1    1     0
[10,]    1    1    1    1    1    1    1    1    1     1

A crucial assumption, which is fulfilled in this pricing case, is that there exists a matrix \(K\) such that \(L=KH\). The way the textbook describes this requirement conceptually is that the feedback matrix \(H\) needs to give us enough information about the loss matrix \(L\).


library(matlib)

K <- L %*% inv(H)

K
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,] -0.7  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.7
 [2,]  0.1 -0.7  0.0  0.0  0.0  0.0  0.0  0.0  0.0   0.7
 [3,]  0.1  0.1 -0.7  0.0  0.0  0.0  0.0  0.0  0.0   0.7
 [4,]  0.1  0.1  0.1 -0.7  0.0  0.0  0.0  0.0  0.0   0.7
 [5,]  0.1  0.1  0.1  0.1 -0.7  0.0  0.0  0.0  0.0   0.7
 [6,]  0.1  0.1  0.1  0.1  0.1 -0.7  0.0  0.0  0.0   0.7
 [7,]  0.1  0.1  0.1  0.1  0.1  0.1 -0.7  0.0  0.0   0.7
 [8,]  0.1  0.1  0.1  0.1  0.1  0.1  0.1 -0.7  0.0   0.7
 [9,]  0.1  0.1  0.1  0.1  0.1  0.1  0.1  0.1 -0.7   0.7
[10,]  0.1  0.1  0.1  0.1  0.1  0.1  0.1  0.1  0.1   0.0

Given these building blocks, we can now implement the general textbook partial monitoring strategy, applied to our specific toy pricing case, in code.

The first step is to choose values for parameters \(\eta > 0\) and \(\gamma < 1\). I’ve chosen values arbitrarily. We also need to initialize the vector \(w_0 = (1, ..., 1)\) of length \(n=10\). And, while we’re at it, we might as well set our sequence of customer WTPs. I’m starting with a sequence whereby every customer is willing to pay exactly $5 for the product.

eta <- 2
gamma <- 0.5

w <- numeric(n) + 1

wtp_sequence <- numeric(100) + 5

I’ll do the rest in one function:


run_textbook_strategy <- function(eta = 0.2, gamma = 0.5, w = numeric(n) + 1,
                                  n = 10,
                                  number_of_customers = 100,
                                  wtp_sequence = numeric(100) + 5) {
  
  p <- numeric(n)
  estimated_losses <- numeric(n)
  
  # Some vectors to track how the strategy performs over time
  
  actual_losses <- numeric(number_of_customers)
  offered_prices <- numeric(number_of_customers)
  estimated_losses_for_chosen_action <- numeric(number_of_customers)
    
  
  
  for (customer in 1:number_of_customers) {
    
    
    # Update the distribution vector p according to the textbook formula
    p <- (1-gamma)*w/sum(w) + (gamma/n)
    
    # Choose an action based on that probability distribution p
    normalized_p <- p / sum(p)
    offered_price <- sample(1:n, size=1, prob=normalized_p)
    
    # Record this action in the offered_prices vector
    offered_prices[customer] <- offered_price
    
    # Get feedback
    feedback <- ifelse(offered_price > wtp_sequence[customer],1,0)
    
    # Record the actual loss (unknown to the seller) in actual_losses
    actual_losses[customer] <- L[wtp_sequence[customer],offered_price]
  
    # Update estimated losses according to the textbook formula
    estimated_losses <- K[,offered_price] * feedback * (1/p[offered_price])
    
    # Record the estimated loss for the chosen action
    estimated_losses_for_chosen_action[customer] <- estimated_losses[offered_price]
    
    # Update the weighting vector w according to the textbook formula
    w <- w * exp(-1 * eta * estimated_losses)
    
    
    }
  
  return(data.frame(wtp_sequence,offered_prices, actual_losses, estimated_losses_for_chosen_action))
  
  }


textbook_strategy_results <- run_textbook_strategy(number_of_customers = 100,
                                                   wtp_sequence = numeric(100) + 5)

textbook_strategy_results
NA
NA

…I don’t think this actually works and I’m not sure why. The strategy seems to semi-randomly choose prices to offer, and doesn’t converge on the optimal strategy of offering a price of 5 each time, as that is the WTP of all customers. Some troubleshooting / re-reading of the textbook is required.

The actual problem at hand

Unlike the textbook case, buyers can buy multiple products (or fractions of a product). And the seller can set a price curve, rather than a single price. Buyer WTP is also unlikely to be independent of the quantity purchased, i.e., buyers are probably willing to pay less and less for the next marginal unit, as the quantity already purchased rises.

Take the buyer’s WTP as a function \(f\) mapping units demanded to WTP. Take the seller’s price curve as a function \(g\) mapping units supplied to offered prices.

Assume that the seller has a fixed cost \(c\) to supplying each unit of the product (e.g., if he sells 0.5, his cost is \(\frac{c}{2}\)). The seller will never offer the good at a price below \(c\).

In the very simplest case of this new problem, there is a sequence of customers with identical WTP, and the seller has an infinite number of items to sell. The seller tries to maximise profits (revenues from selling the product to the customer, minus costs of ‘producing’ the product). Let \(x\) be the quantity demanded/supplied. If the seller knew \(f\), he could set \(g(x) = f(x)\) for \(\forall x f(x) > c\).

Assume:

  1. \(f(x)\) is a decreasing, continuous, monotonic function.
  2. \(f(x) < c\) for a sufficiently high \(x\).
  3. \(f(x) > c\) for a sufficiently low (positive) \(x\).

Then let \(s\) represent the quantity at which \(f(s) = c\).

In the case where the seller has perfect knowledge of the customer’s WTP, he makes \(\int^s_0 f(x)dx\) in revenue, and \(\int^s_0 (f(x)-c) dx\) in profit.

For each customer, the seller receives feedback \(\phi\), the number of items the customer bought from the seller. (Contrast this with the textbook case, where the feedback was either that the customer bought the product, or didn’t buy the product.) The seller then has to use a strategy that minimizes the distance between his actual profit, and \(\int^s_0 (f(x)-c) dx\). This seems a fair bit harder than the textbook case.

Concluding thoughts

  1. The textbook is focused on predictions where the predictor has no information about the distribution from which the outcome sequence is drawn. Presumably, in your setting, you have some existing beliefs about the price of the products, beyond the bounds of minimum and maximum customer WTP. The textbook algorithm might be suboptimal for this reason, or maybe a bit overkill for what is in reality an easier problem.
  2. I’m open to any feedback on next steps, if we’d like to move forward. Some next steps could be for me to try and fix my implementation of the general algorithm, look more deeply into the bounds on regret proved in the textbook, and further developing a formal statement of the actual problem at hand.
LS0tCnRpdGxlOiAiUHJpY2luZyB3aXRoIFBhcnRpYWwgTW9uaXRvcmluZyIKb3V0cHV0OiBodG1sX25vdGVib29rCi0tLQoKIyMgVGhlIHRleHRib29rIHNvbHV0aW9uIHRvIHRoZSAodGV4dGJvb2spIHByaWNpbmcgcHJvYmxlbQoKClRoZSB0ZXh0Ym9vayBjYXNlIGFzc3VtZXMgdGhhdCB0aGVyZSBpcyBhIGZpbml0ZSBzZXQgb2YgcHJpY2VzIHRoYXQgY2FuIGJlIHNldCBmb3IgYSBob21vZ2Vub3VzIGdvb2QuIFRoaXMgc2V0IG9mIHBvc3NpYmxlIHByaWNlcyBpcyBhbHNvIHRoZSBzZXQgb2YgcG9zc2libGUgY3VzdG9tZXIgbWF4aW11bSB3aWxsaW5nbmVzc2VzIHRvIHBheSAoV1RQKS4gRm9yIHRoZSBwdXJwb3NlcyBvZiB0aGlzIGlsbHVzdHJhdGlvbiwgdGFrZSB0aGlzIHNldCB0byBiZSB0aGUgaW50ZWdlcnMgZnJvbSAxIHRvIDEwIGluY2x1c2l2ZS4gVGhhdCBpcywgdGhlIHNlbGxlciBjYW4gb2ZmZXIgaGlzIHByb2R1Y3QgZm9yIFwkMSwgXCQyLCAuLi4sIFwkMTAuCgpJZiB0aGUgc2VsbGVyIG9mZmVycyBhIHByaWNlIGVxdWFsIHRvIG9yIGJlbG93IHRoZSBjdXJyZW50IGN1c3RvbWVyJ3MgV1RQLCBoaXMgbG9zcy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