## A Prediction Market Simulation using C

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

========================

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.

This entry was posted in Machine Learning. Bookmark the permalink.

### 4 Responses to A Prediction Market Simulation using C

1. I find I get rusty if I don’t use a programming language for a while, I do also find that you pick things up pretty quickly so it’s not that disastrous! I also think it helps when learning a new language as it’s easier to compare the new language to a language you’ve learnt previously!

2. Tom Nantais says:

Sorry to get in touch with a comment — I wasn’t sure how to contact you. I was interested in your Apress book on testing with .Net. Apress says the 2012 version of the book is just a changed cover but no changed content from the 2006 version. This seems bizarre and a bit misleading to me. Can you tell me please if there is anything new in the 2012 version of the book? Thanks very much.

• Tom,
As far as I know, there has been no change to the book’s content — at least I didn’t make any changes (sometimes book publishers will get a second author to revise a book — if Apress did this I’m not aware of it.)
James M

• Tom Nantais says:

Thanks very much James — Apress also confirms that there is no new content, just a new cover and new copyright date. Appreciate your response to clear up the confusion. Regards, Tom