• C++ Programming for Financial Engineering
    Highly recommended by thousands of MFE students. Covers essential C++ topics with applications to financial engineering. Learn more Join!
    Python for Finance with Intro to Data Science
    Gain practical understanding of Python to read, understand, and write professional Python code for your first day on the job. Learn more Join!
    An Intuition-Based Options Primer for FE
    Ideal for entry level positions interviews and graduate studies, specializing in options trading arbitrage and options valuation models. Learn more Join!

My simulated Wiener process (Matlab)

Hi,


I am using Matlab to simulate a pure Wiener process. The initial value is 1, drift is 0, diffusion is 1, 100 timesteps, 1000 paths, from t = 0 to 1. My results is attached with this post.

My graph clearly shows the expected value at T = 1 is 1, so this is good. Theoretical Wiener has variance (1-0=1) at T=1. So the final values should be in [0,2] range, but this is not the case in my graph. Anybody knows why?



x0 = 1;
A = 0;
B = 1;
T = 1;
N = 100
M = 1000;

randn('state', 88); % Initalise the random generator
dt = repmat(T/N, 1, M); % Size of a single time step
x = repmat(x0, N+1, M); % Array to hold the simulation
t = linspace(0, T, N+1); % Array to hold times

for i=1:N
x(i+1,: ) = x(i,: ) + (A * dt) + (B * sqrt(T/N) * randn(1,M));
end

% Draw the distributions

clf reset;
plot(t,x);

Wiener.jpg
 

Attachments

  • Wiener.jpg
    Wiener.jpg
    59.5 KB · Views: 230
Looks very much like an assignment question to me :D. But what do you mean by,

" So the final values should be in [1,2] range, but this is not the case in my graph"??

Why should they be within that range???
 
Yes, this is an assignment question. I wrote the program and tried to verify my results. I thought Brownian Motion have variance T-t, so the values at maturity must be in [1-1,1+1] range.
 
You are simulating from time 0 to time 1, so the variance at time t=1 should be equal to 1 (theoretically). Empirically, the variance across the 1000 sims of your simulated values at time t=1, will not be exactly equal to 1. You will have to play around a bit with the discretisation of the sde (e.g. increase number of time steps) and/ or your number of sims to achieve better approximation to the theoretical variance. Also for the particular example given, your theoretical variance is,

(\int_0^1 E\[\sigma^2 \]ds=1)
 

Bastian Gross

German Mathquant
The variance of a random variable averages the squares of the deviations of its possible values from its mean value.

In your discrete case
( \operatorname{Var}(X)=\frac{1}{M}\sum_{m=1}^{M}(x^m-\mu)^2)
Therefore you recognize that some (x^m) are near the mean value (\mu) and a few of them are far apart from (\mu).
 
For a normal distribution with standard deviation 1, 95% of the data falls within 2 standard deviations of the mean. That is what your graph shows at time T=1.
 
Top