I'm simulating a simple Ornstein-Uhlenbeck process
$dx=-x dt+\sqrt{2}dW$
which is well-known to have a steady state distribution of
$p_s(x)=\frac{1}{\sqrt{2\pi}}e^{-x^2/2}$
Here's my matlab code to run the simulation
dt = 0.01;
T= 5000;
X = zeros(size(0:dt:T));
for t=0:dt:T
% This is the Euler scheme
X(:,i+1)=X(:,i)-X(:,i)*dt+sqrt(2*dt)*randn;
% This is the exact formula
% X(:,i+1)=X(:,i)*exp(-dt)+sqrt(1-exp(-2*dt))*randn;
i=i+1;
end
Then I do the Kolmogorov–Smirnov test to check the normality of the resulting distribution
[h,p] = kstest(X);
but always get h = 1, which rejects the null hypothesis that the data obeys standard normal distribution.
To find out the reason, I generate random numbers of normal distribution
x = randn(size(X))
and compare their cumulative distribution function with the standard normal distribution
pd = makedist('normal',0,1);
[fX,t] = ecdf(X);
y = cdf(pd,t);
plot(t,fX-y)
[fx,t] = ecdf(x);
hold on;
plot(t,fx-y);
The simulation-generated X and the matlab-generated x show very similar shape.
Then I do the two-sample KS test,
[h,p] = kstest2(X,x)
It returns h=0 (X and x are from the same distribution). So I'm really confused here. Why the simulated X cannot pass the normality test and the p value is far less than the significance level 0.05?
No comments:
Post a Comment