%% Euler Simulation for a CIR Object
% The Cox-Ingersoll-Ross (CIR) short rate class derives directly from SDE with mean-reverting drift (SDEMRD): $d{X_t} = S(t)[L(t) - {X_t}]dt + D(t,X_t^{\frac{1}{2}})V(t)dW
% where D is a diagonal matrix whose elements are the square root of the corresponding element of the state vector.
%
% Create a cir object to represent the model: $d{X_t} = 0.2(0.1 - {X_t})dt + 0.05X_t^{\frac{1}{2}}dW.

CIR = cir(0.2, 0.1, 0.05)  % (Speed, Level, Sigma)

% Simulate a single path over a year using simByEuler.

nPeriods = 249;      % # of simulated observations
dt       =   1;      % time increment = 1 day
rng(142857,'twister')
[Paths,Times] = simByEuler(CIR,nPeriods,'Method','higham-mao','DeltaTime', dt)

% Copyright 2018 The MathWorks, Inc.