[Matlab] Simulation of Stochastic Process

Click For Summary

Discussion Overview

The discussion revolves around simulating a Mean Reverting process using MATLAB, specifically focusing on the implementation of a stochastic differential equation (SDE). Participants are addressing issues related to the code provided by the original poster and its correctness in the context of numerical methods for stochastic processes.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • The original poster shares MATLAB code for simulating a Mean Reverting process and expresses uncertainty about its correctness.
  • Some participants note that the code runs without errors and the resulting plot appears reasonable, questioning the original poster's concerns.
  • Another participant identifies a potential issue with the discretization of the Wiener increment in the code, suggesting that it should be multiplied by the square root of the time increment, dt.
  • This participant provides references to external resources for correct implementation and mentions the existence of higher-order methods for numerical solutions of SDEs.

Areas of Agreement / Disagreement

There is disagreement regarding the correctness of the original code. While some participants believe the code is functioning properly, others point out a specific error in the discretization method used.

Contextual Notes

The discussion highlights the importance of proper discretization in numerical simulations of stochastic processes, but does not resolve the overall correctness of the original code provided.

FrancescoMi
Messages
5
Reaction score
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
The code seems to run fine and the plot looks reasonable. Is there some reason that you think it is wrong?
 
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?
 
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: dW \approx \sqrt(dt)N(0,1), 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.
 

Similar threads

  • · Replies 41 ·
2
Replies
41
Views
10K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K