Simulation of Markov Chain with Generator

조회 수: 9 (최근 30일)
Richard Harrison
Richard Harrison 2019년 9월 24일
답변: Shantanu Dixit 2025년 5월 30일
How to generate sample paths of a markov chain with given generator Q where and also given a step size on the interval . I believe I need graphs of the sample paths and we've discussed "two-state" Markov chains where {1,2} are the states for bull and bear markets. I'm unsure if I need to have 1 and 2 on the y axis.

답변 (1개)

Shantanu Dixit
Shantanu Dixit 2025년 5월 30일
Hi Richard,
If I understood the query correctly, you want to simulate sample paths of a two-state continuous-time Markov chain with generator matrix:
% From state 1 (Bull) to state 2 (Bear): rate = 6
% From state 2 (Bear) to state 1 (Bull): rate = 10
Q = [-6 6; 10 -10];
To simulate this in MATLAB you can:
  1. Start in a state (eg. state 1 for Bull).
  2. Wait for an exponentially distributed time with rate = '−Q(i,i)'.
  3. Jump to the other state.
  4. Repeat until you reach your total simulation time ('T_max')
You can refer to the below example that simulates and plots a sample path using 'stairs': https://www.mathworks.com/help/matlab/ref/stairs.html
Q = [-6 6; 10 -10];
T_max = 10; t = 0; state = 1;
times = 0; states = state;
while t < T_max
lambda = -Q(state,state);
delta_t = exprnd(1/lambda);
t = t + delta_t;
if t > T_max, break; end
state = 3 - state; % toggle between 1 and 2
times(end+1) = t;
states(end+1) = state;
end
times(end+1) = T_max; states(end+1) = states(end);
% Resample with fixed step size (e.g., 0.1)
stepSize = 0.1;
t_fixed = 0:stepSize:T_max;
states_fixed = interp1(times, states, t_fixed, 'previous');
stairs(t_fixed, states_fixed, 'LineWidth', 2)
ylim([0.5 2.5]); yticks([1 2]); yticklabels({'Bull','Bear'})
xlabel('Time'); ylabel('Market State')
title('Markov Chain Sample Path (Fixed Step Size)'); grid on
Hope this helps!

카테고리

Help CenterFile Exchange에서 Markov Chain Models에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by