Graphing a Prediction Market Cost Function

The goal of a prediction market is to predict an outcome such as the winner of a political election. In a prediction market, a group of experts buys and sells shares in the options in a way similar to the stock market.


A prediction market needs an underlying cost function. A common cost function is the logarithmic market scoring rule (LMSR). If x and y represent the number of shares of options X and Y, then the LMSR cost function is:

C = b * ln(exp(x/b) + exp(y/b))

where b is a scaling constant called the liquidity. I wondered what the cost function looked like so I decided to graph it using the R language. The R commands I used start with:

x = seq(0, 50)
y = seq(0, 50)
f = function(x, y) { 10 * log(exp(x/10) +
 exp(y/10)) }
z = outer(x, y, f)

I set up vectors x and y with 51 values from 0 to 50 inclusive. The next command defines the LMSR cost function for two inputs and a scaling factor of b = 10.


jet.colors = colorRampPalette(c("midnightblue",
  "blue", "cyan", "green", "yellow", "orange",
  "red", "darkred"))
nbcol = 64
color = jet.colors(nbcol)
nrz = nrow(z)
ncz = ncol(z)

zfacet = z[-1,-1] + z[-1,-ncz] +
  z[-nrz,-1] + z[-nrz,-ncz]
facetcol = cut(zfacet, nbcol)

I set up a custom color gradient from dark blue to dark red. You can think of the zfacet and facetcol as magic R incantations for doing a 3D color gradient graph.

The graph is created with:

persp(x, y, z, col=color[facetcol], phi=15,
  theta=-35, ticktype="detailed", d=10, r=1,
  shade=0.1, expand=1.0, zlim=range(0:60))

The phi argument is the tilt-the-base angle. The theta is the rotate-the-base angle. The d is the perspective effect; larger d lessens effect. The r is distance-to-eye. The expand shrinks the plotting box if d < 1. The zlim argument sets the output range otherwise the graph wouldn't start at z=0.

Anyway, because all the equations in prediction market are derived from the underlying cost function, plotting the cost function helped me understand what's going on in the math for a prediction market.

This entry was posted in Machine Learning, Prediction Markets. Bookmark the permalink.