import numpy as np
x = np.array((0.794, 0.884, 0.774, 0.559, 0.240,
0.754, 0.705, 0.639, 0.614, 0.897))
print(x)[0.794 0.884 0.774 0.559 0.24 0.754 0.705 0.639 0.614 0.897]
Let \(X\) follow a power distribution, with density \[f(x) = \alpha x^{\alpha-1}, \quad 0<x<1,\quad \alpha>0.\]
[0.794 0.884 0.774 0.559 0.24 0.754 0.705 0.639 0.614 0.897]
Use a bootstrap routine to estimate the 5th and 95th percentile of the estimator using
Hint: The stated distribution is a special case of a beta distribution with \(b=1\) and \(a=\alpha\). We can simulate from it using the following code, provided a value for alpha.
A startup offering hands-on craft beer brewing workshops is piloting a weekend course format. Each session runs on Saturdays only and is limited to 4 participants due to space and brewing setup constraints. Based on early demand, the number of participants X per Saturday follows this discrete distribution:
| Participants (X) | 0 | 1 | 2 | 3 | 4 |
|---|---|---|---|---|---|
| Probability P(X=x) | 0.10 | 0.25 | 0.30 | 0.20 | 0.15 |
Each participant pays NOK 2,200, and costs the company NOK 250 in materials. There is also a fixed cost of NOK 4,200 per workshop. The company starts with NOK 50,000 in capital and plans to run the workshop every Saturday for one year (52 weeks).
The expected number of participants per week is \(2.05\) and that the standard deviation is \(1.20\). See Seminar 1, Exercise 5.
Let \(X_1, X_2,...,X_n\) be a sequence of independent and identically distributed random variables having a distribution with expectation \(E(X)=\mu_X\) and finite variance \(Var(X)=\sigma^2\). Then the sum \(\sum_{i=1}^n X_i\) is approximately normally distributed with expectation \(n\cdot\mu\) and variance \(n\cdot\sigma^2\), i.e. \(N(n\cdot\mu, n\cdot\sigma^2)\).
Roulette is a game of chance where a roulette wheel has 37 numbered pockets where a ball can land. 18 of these pockets are red, 18 are black, and 1 is green (at least in Europe).
If, for example, you bet 1, on red, and red occurs, then you win your bet back plus 1, (i.e., a gain of 1). But if black or green occurs, you lose the bet (a gain of -1).
You bet 1, on red. In Seminar 1 you found the following:
i) What is the expected gain? -1/37
ii) What is the variance of this gain? 0.99
iii) What is the probability of a positive gain? 18/37
You continue this strategy for \(n=50\) times. Use the Central Limit Theorem to answer the questions in part (a) for the average gain.
Solve (a) using simulation techniques in Python. Explain what method you use and why. Compare the value to the central limit theorem approximation.
A common strategy is to double the bet if you loose (to win back the loss). Say you start out with 100 euros. Simulate one such game and plot the status of your wallet (balances in the code below) after for each spin of the roulette. The code below can be used as a starting point.
import numpy as np
import matplotlib.pyplot as plt
# --- Parameters ---
p_win = 18 / 37
initial_balance = 100
max_spins = 5000 # safety cap to avoid infinite loops
# --- Initialization ---
balance = initial_balance
bet = 1
balances = [balance]
for spin in range(max_spins):
# Check if you can afford the bet
if bet > balance:
print("Bankrupt!")
break
# Place bet
balance -= bet
# Simulate outcome
win = np.random.binomial(size=1, p=p_win, n = 1) == 1
if win:
# Win: receive 2*bet (stake + winnings)
balance += 2 * bet
bet = 1 # reset bet after win
else:
# Loss: double the bet
bet *= 2
balances.append(balance)
else:
print("Maximum spins reached")
print("Bankrupt after round ", spin)Adapt the code from (c) to a python function and run a Monte Carlo simulation to find the expected number of games before you are bankrupt with this strategy.
What is the problem with this strategy in the long run? How much money will you need to cover your bets if the roulette outcomes are 10 consecutive blacks?
Say you have a stopping rule: If your balance reaches 200 euros, you will stop playing. What is the probably that you will leave richer? What is the probability that you go bankrupt with this stopping rule?
What if you set an upper limit for the bets in addition to the stopping rule? With this strategy, you will not increase the bet to more than \(2^5\). Does this increase the probability of reaching 200 euros instead of going bankrupt?