Created
April 19, 2020 07:06
-
-
Save IlievskiV/9c08a4d3b53095f4b15ba27c8d811239 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scipy import stats | |
num_simulations = 10000 # how many times to repeat | |
Ns, Ts, hs = 20000, 10.0, 1.0 # discrete steps, continuous steps, veriance | |
dts = 1.0 * T/N # total number of time steps | |
u = 2. # the difference in time points | |
t = int(np.floor((np.random.uniform(low=u+0.01, high=1. * T - u)/T) * N)) # random starting point | |
# initialize the means | |
rand_val_t = np.zeros(num_simulations) | |
rand_val_t_plus_u = np.zeros(num_simulations) | |
rand_val_t_minus_u = np.zeros(num_simulations) | |
for i in range(num_simulations): | |
# generate a brownian motion | |
Xs, _ = brownian_motion(Ns, Ts, hs) | |
# store the means at the two points | |
rand_val_t[i] = Xs[t] | |
rand_val_t_plus_u[i] = Xs[t + int(u*Ns/Ts)] | |
# calculate the difference | |
diff = rand_val_t_plus_u - rand_val_t | |
# print stats | |
print('The mean is: {0}'.format(np.mean(diff))) | |
print('The variance is: {0}'.format(np.var(diff))) | |
# make normality test with null hypothesis: x comes from a normal distribution | |
k2, p = stats.normaltest(diff) | |
print("Null hypothesis can be rejected") if p < 1e-3 else print("Null hypothesis cannot be rejected") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment