I want to simulate price with the following code:

import numpy as np
import matplotlib.pyplot as plt

final_price = []

for i in range(1000):
    amp = 0.01
    length = 10000
    diff = np.random.uniform(-0.01, 0.01, length)
    price = np.cumprod(1 + diff)

plt.hist(final_price, bins=100)

the final price has the following distribution:

enter image description here

I found the following from this paper for question 2.

enter image description here


I ran the simulation with the following code and the result is very surprising: at each step, the change is uniformly distributed between -1% and 1%, but at the end, 810 / 1000 ends up smaller than 1, and 190 bigger than 1. This is very counter-intuitive

import matplotlib.pyplot as plt
import numpy as np

Y = []
for i in range(1000):
    X = np.random.uniform(0.99, 1.01, 100000)
Y = np.array(Y)
bigger = sum(Y > 1)
smaller = sum(Y < 1)
plt.title(f"bigger than 1: {bigger}, smaller than 1: {smaller}")
plt.hist(Y, 100)

enter image description here

  • 2
    $\begingroup$ Please add the self-study tag & read its wiki. Then tell us what you understand thus far, what you've tried & where you're stuck. We'll provide hints to help you get unstuck. Please make these changes as just posting your homework & hoping someone will do it for you is grounds for closing. $\endgroup$ Commented Mar 11 at 16:23
  • $\begingroup$ @kjetilbhalvorsen This is not a homework question. I googled and asked ChatGPT, but couldn't find answers, this is all I got so far. $\endgroup$
    – em1971
    Commented Mar 11 at 16:27
  • $\begingroup$ stats.stackexchange.com/questions/3707 is a closely related question. $\endgroup$
    – whuber
    Commented Mar 11 at 17:43
  • $\begingroup$ Re "surprising:" Consider the simplest possible non-trivial instance of this phenomenon where the price changes independently twice, increasing or decreasing 50% with equal chances each time. The four possible outcomes, each with chance $1/4,$ are relative prices of $(1-0.5)^2=0.25,$ $(1-0.5)(1.5)=0.75,$ $(1+0.5)(1-0.5)=0.75,$ and $(1+0.5)(1+0.5)=2.25.$ Please contemplate (a) what the expected outcome is and (b) what proportion of outcomes are net decreases from the original price. $\endgroup$
    – whuber
    Commented Mar 11 at 20:39
  • $\begingroup$ There’s a difference between taking the same random variable and raising it to a power and taking many random variables (even if they are identically distributed) and multiplying them @em1971 $\endgroup$
    – Taylor
    Commented Mar 11 at 23:50


Browse other questions tagged or ask your own question.