My C language skills get very rusty very quickly if I don’t use the language. For mental exercise I decided I’d port a C# program I wrote that simulates a prediction market, to the C language.
In a prediction market, a group of people buy and sell shares of some future event. People with correct predictions get paid by the market sponsor. There is some very interesting math behind prediction markets — the numbers of outstanding shares of the possible outcomes map to the probabilities of the outcomes. And the price of shares changes with each transaction.
My demo output begins with:
C:\Data gcc -o prediction_demo.exe prediction_demo.c C:\Data prediction_demo.exe Begin prediction market demo Goal is to predict election winner among Adams, Baker, Cogan ======================== Initial number of shares owned are: 0 0 0 Initial inferred probabilities of winning are: 0.3333 0.3333 0.3333 Initial costs for one share of each option are: $0.3344 $0.3344 $0.3344 ======================== Transaction: Player001 buys 10 shares of Baker Cost of transaction to Player001 was: $3.45 Updated number of shares owned are: 0 10 0 Updated inferred probabilities of winning are: 0.3220 0.3559 0.3220 Updated costs for one share of each option are: $0.3231 $0.3571 $0.3231 ========================
Initially there are no shares held of any of the 3 candidates so it makes sense that the probabilities of each winning are 0.333. After Player001 buys shares of Baker, it makes sense that a.) the price of Baker shares goes up, and b.) the inferred probability that Baker will win increases.
I was surprised at how many details about C I’d forgotten, but everything came back pretty quickly. Programming languages are like a lot of things: you have to practice.