Now that we have a posterior distribution, we can use it to compute the optimal bid, which I define as the bid that maximizes expected return (see http://en.wikipedia.org/wiki/Expected_return).
I’m going to present the methods in this section top-down, which means I will show you how they are used before I show you how they work. If you see an unfamiliar method, don’t worry; the definition will be along shortly.
To compute optimal bids, I wrote a class called
class GainCalculator(object): def __init__(self, player, opponent): self.player = player self.opponent = opponent
ExpectedGains, which computes a sequence of bids
and the expected gain for each bid:
def ExpectedGains(self, low=0, high=75000, n=101): bids = numpy.linspace(low, high, n) gains = [self.ExpectedGain(bid) for bid in bids] return bids, gains
high specify the range of possible bids;
n is the number of bids to try.
ExpectedGain, which computes expected gain for a
def ExpectedGain(self, bid): suite = self.player.posterior total = 0 for price, prob in sorted(suite.Items()): gain = self.Gain(bid, price) total += prob * gain return total
ExpectedGain loops through the
values in the posterior and computes the gain for each bid, given the
actual prices of the showcase. It weights each gain with the corresponding
probability and returns the total.
Gain, which takes a ...