|
|
|
|
|
by mrow84
1898 days ago
|
|
I was interested in seeing the results myself, so here is some python: import numpy as np
import itertools
from matplotlib import pyplot as plt
def ensemble_mean(outcomes):
# Assume we are given a (K, T) array of outcomes, and compute the ensemble average
# for T+1 time steps, starting with 1 wealth.
K, T = outcomes.shape
X = np.ones((K, T+1), dtype=np.float64)
X[:, 1:] = np.where(outcomes, 1.5, 0.6)
Z = np.cumprod(X, axis=1)
return Z.mean(axis=0)
time_steps = 20
all_outcomes = np.array(list(itertools.product([0, 1], repeat=time_steps-1)))
exhaustive_mean = ensemble_mean(all_outcomes)
ensemble_size = 100
ensemble_samples = 10000
ensemble_means = np.zeros((time_steps, ensemble_samples))
for i in range(ensemble_samples):
print(i)
# generate ensembles as though we were sampling (i.e. with replacement)
J = np.random.choice(all_outcomes.shape[0], size=ensemble_size, replace=True)
ensemble_means[:, i] = ensemble_mean(all_outcomes[J, :])
plt.hist(ensemble_means[-1], bins=1000, histtype='step')
plt.axvline(exhaustive_mean[-1])
plt.title("Modal sampled ensemble mean is below true ensemble mean")
plt.show()
|
|