[Matlab] Simulation of Stochastic Process

In summary, the conversation is about a beginner trying to simulate a Mean Reverting process using MATLAB. The code provided seems to run fine and the plot looks reasonable, but the beginner is not sure if it is correct. Upon further inspection, it is pointed out that there are some errors in the discretization of the Wiener increment. Suggestions are provided for correcting the code, such as multiplying dW by the square root of dt. It is also recommended to refer to resources such as the Wikipedia entry for the first order scheme and the book of Kloeden and Platen for higher order methods.
  • #1
FrancescoMi
5
0
Hi all,
I have this dynamic:
2vwuyph.png

is a Mean Reverting process. I want to simulate the sde with MATLAB but I am a beginner and I have some problems. I show you the code that I have created:

Code:
%% Simulazione prezzo Geometric Ornstein-Ulenbeck

clear all
clc

%Parameters
mu = 0.5;
sigma = 0.12;
eta = 1;
T = 2;
N_t = 300; %Temporal Intervals
N = 1000; %Number of Simulations
t=linspace(0,T,N_t); %Temporal line

dt=T/N_t; %Temporal increments
P_t=zeros(N,N_t); 
P_t(:,1)=20; %First Price

%Model
for i=1:N
    for j=2:N_t
        dW = randn;
        P_t(i,j) = P_t(i,j-1) + eta*(mu-log(P_t(i,j-1)))*P_t(i,j-1)*dt+sigma*P_t(i,j-1)*dW;
    end
end

plot(t,P_t(1,:));

But I don't know if it is correct. Can you help me?
 
Physics news on Phys.org
  • #2
The code seems to run fine and the plot looks reasonable. Is there some reason that you think it is wrong?
 
  • #3
kreil said:
The code seems to run fine and the plot looks reasonable. Is there some reason that you think it is wrong?

Because is my first work alone and I'm not sure of the cicle. Do you think it's ok?
 
  • #4
It is not OK. The discretization of the Wiener increment is wrong. Here is the first link that I could find that explains how to do it correctly in Matlab:

http://www.caam.rice.edu/~cox/stoch/dhigham.pdf

To summarize: [itex]dW \approx \sqrt(dt)N(0,1)[/itex], so you forgot to multiply your dW by the square root of dt.

Also, the wikipedia entry for the first order scheme has some example code for exactly this problem:
http://en.wikipedia.org/wiki/Euler–Maruyama_method

Note that this is a first order discretization, there are also higher order methods that you can find in the literature, e.g. in the book of Kloeden and Platen. I highly recommend this book if you want to numerically solve stochastic differential equations. The basic idea of these methods comes from Ito calculus and the idea of stochastic Taylor expansion.
 

1. What is a stochastic process?

A stochastic process is a mathematical model that describes the evolution of a system over time, taking into account random or unpredictable factors. It is often used to model real-world phenomena that involve randomness, such as stock prices, weather patterns, and traffic flow.

2. How is a stochastic process simulated in Matlab?

In Matlab, a stochastic process can be simulated using the randn function, which generates a sequence of random numbers from a standard normal distribution. This sequence can then be used to create a time series that represents the stochastic process.

3. What are the advantages of using Matlab for simulating stochastic processes?

One of the main advantages of using Matlab for simulating stochastic processes is its powerful built-in functions for generating random numbers and performing statistical analysis. Additionally, Matlab's user-friendly interface and extensive documentation make it easy for researchers and scientists to use for their simulations.

4. Can Matlab simulate complex stochastic processes?

Yes, Matlab is capable of simulating complex stochastic processes. It offers a wide range of functions and tools for simulating different types of stochastic processes, including Markov chains, Brownian motion, and Poisson processes. With some programming knowledge, users can also create their own custom simulations in Matlab.

5. How can the results of a stochastic process simulation in Matlab be analyzed?

Matlab provides various tools for analyzing the results of a stochastic process simulation. These include statistical functions for calculating mean, median, and variance, as well as plotting functions for visualizing the data. Users can also apply different statistical tests to determine the significance of their results.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
2
Replies
41
Views
8K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • Classical Physics
Replies
0
Views
153
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
752
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
  • Set Theory, Logic, Probability, Statistics
Replies
1
Views
113
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top