{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# The Saint Petersberg paradox"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"This notebook is an element of the free [risk-engineering.org courseware](https://risk-engineering.org/). It can be distributed under the terms of the [Creative Commons Attribution-ShareAlike licence](https://creativecommons.org/licenses/by-sa/4.0/).\n",
"\n",
"Author: Eric Marsden \n",
"\n",
"---\n",
"\n",
"This notebook contains an exploration of the Saint Petersberg paradox, first proposed by Daniel Bernoulli around 1738. See the [associated lecture slides](https://risk-engineering.org/risk-treatment-decisions/) for some background on the economic theory of risk aversion and decision-making. The notebook explains why stochastic simulation methods such as Monte Carlo are not suitable for situations where a very unlikely event has a significant impact on the output of interest in your simulations. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## The rules of the game"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You flip a coin repeatedly until a tail first appears. The pot starts at 1€ and doubles every time a head appears. You win whatever is in the pot the first time you throw tails and the game ends.\n",
" \n",
"For example:\n",
"\n",
"- T (tail on the first toss): win 1€\n",
"- H T (tail on the second toss): win 2€\n",
"- H H T: win 4€\n",
"- H H H T: win 8€\n",
"\n",
"Which would you prefer?\n",
"\n",
"- 10€ for sure\n",
"- the right to play the St. Petersberg game"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## The expected value of playing"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The probability of throwing a tail on a given round:\n",
"\n",
"- 1st round: $\\Pr(Tails) = ½$\n",
"- 2nd round: $\\Pr(Heads) × \\Pr(Tails) = ¼$\n",
"- 3rd round: $\\Pr(Heads) × \\Pr(Heads) × \\Pr(Tails) = \\frac{1}{8}$\n",
"- $k^{th}$ round: $\\frac{1}{2k}$\n",
"\n",
"How much can you expect to win on average?\n",
"\n",
"- with probability ½ you win 1€, ¼ you win 2€, $\\frac{1}{8}$ you win 4€, $\\frac{1}{16}$ you win 8€ …\n",
"- $\\mathbb{E}(win) = ½ + ½ + ½ + … = ∞$\n",
"\n",
"The expected value of the game is infinite, yet few people would be willing to pay more than 20€ to play: this is what’s known as “the St. Petersberg Paradox”. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## A Monte Carlo simulation of the expected value"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let’s try to estimate the expected value of this game using a stochastic simulation."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy, matplotlib.pyplot as plt\n",
"import seaborn as sns\n",
"%matplotlib inline\n",
"%config InlineBackend.figure_formats=['svg']\n",
"\n",
"def petersburg():\n",
" payoff = 1\n",
" while numpy.random.uniform() > 0.5:\n",
" payoff *= 2\n",
" return payoff\n",
"\n",
"N = 1000000\n",
"games = numpy.zeros(N)\n",
"for i in range(N):\n",
" games[i] = petersburg()"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plt.hist(numpy.log(games), alpha=0.5);"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"11.501125999999999"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"games.mean()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This game illustrates a situation where very unlikely events have an extremely high impact on the mean outcome: Monte Carlo simulation will not allow us to obtain a good estimation of the true (theoretical) expected value."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## The risk aversion explanation"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Bernoulli suggested in 1738 that the “value” of a gamble is not its monetary value, but that people attach some subjective value, or *utility*, to monetary outcomes. Bernoulli’s suggestion: people do not seek to maximize expected values, but instead\n",
"maximize *expected utility*.\n",
"\n",
"- marginal utility declines as wealth increases (poor people value increments in wealth more than rich people do)\n",
" \n",
"- an individual is not necessarily twice as happy getting 200€ compared to 100€\n",
"\n",
"- people are “risk averse”\n",
"\n",
"This is a possible explanation for why very few people are willing to pay anything close to the theoretical value of playing this game. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## The “casino bust” explanation"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Casinos are rich, but their riches are limited. Once you break their bank, they can’t pay out any more, and thus the expected return is finite. Let’s consider the case where the bank has a limit to their resources. We keep doubling the pot and halving the probability of winning the amount in the pot (half because you get the pot on a tail but not a head), until we reach the limit. \n",
"\n",
"(This section was inspired by [Peter Norvig’s notebook on probabilities and paradoxes](https://nbviewer.jupyter.org/url/norvig.com/ipython/ProbabilityParadox.ipynb).)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"def petersburg_finite(limit):\n",
" payoff = 1\n",
" while numpy.random.uniform() > 0.5:\n",
" payoff *= 2\n",
" if payoff > limit:\n",
" payoff = limit\n",
" break\n",
" return payoff"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can calculate the expected value of playing the Saint Petersburg game against a casino which has a finite limit to their bankroll. The expected value is the sum of the possible payoffs multiplied by their probabilities. "
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"def expectation_petersburg_finite(limit):\n",
" expectation = 0\n",
" payoff = 1\n",
" probability = 1\n",
" while payoff < limit:\n",
" payoff *= 2\n",
" probability *= 0.5\n",
" expectation += payoff * probability\n",
" return expectation"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"27.0"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"expectation_petersburg_finite(1e8)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"So even with a fairly large casino bankroll of 100 million euros, the expected value of this limited game is only moderate. Would you pay 27€ to have the possibility to play this game? If not, perhaps the risk aversion explanation above remains relevant…"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
}
},
"nbformat": 4,
"nbformat_minor": 1
}