{
"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": [
"