How to generate M sets of a time serie?

4 views (last 30 days)
Filippo Patrignani
Filippo Patrignani on 16 Jun 2021
Answered: Ayush on 30 Apr 2024
I have to solve this exercise: Simulate data from the following model yt = α1yt−1 + α2yt−2 + εt, use α1 = 0.7 and α2 = 0.3 and for a given T generate M = 5000 sets of time series.
I can simulate data for M=1, but i don't know how to implement the simulation for M=500.
Thanks

Answers (1)

Ayush
Ayush on 30 Apr 2024
Hi,
To simulate data for (M=5000) sets of time series based on the given equation, follow the steps below. In the example given below, I have assumed that "ϵt" is drawn from a standard normal distribution and in the equation "yt−1" represents the value of "y" at time "t-1" and "yt−2" represents the value of "y" at time "t-2". The steps are:
  1. Set the values of "", "", "M", and "T".
  2. For efficiency, preallocate memory for storing the simulated time series data.
  3. For each set of time series, generate the data.
  4. For each time series, start with initial values for "y_0" and "y_{-1}", then generate the data based on the model.
Refer to the example implementation below for better understanding:
% Parameters
alpha1 = 0.7;
alpha2 = 0.3;
M = 5000; % Number of time series sets
T = 100; % Length of each time series
% Preallocate memory for the simulated data
% Assuming y_0 and y_{-1} are zeros, or you can set them to any initial value
simData = zeros(T, M);
% Loop over M to generate each set of time series
for m = 1:M
% Initialize the first two values
y = zeros(T, 1); % This will store one time series
% Assuming y_0 = 0 and y_{-1} = 0, you can change these initial conditions
y(1) = 0; % This could be set to a specific value or randomized
y(2) = 0; % This could be set to a specific value or randomized
% Generate the time series data
for t = 3:T
% Generate epsilon_t from a standard normal distribution
epsilon_t = randn;
% Update y_t based on the model
y(t) = alpha1 * y(t-1) + alpha2 * y(t-2) + epsilon_t;
end
% Store the generated time series in simData
simData(:, m) = y;
end
% At this point, simData contains M columns, each a time series of length T

Categories

Find more on Genomics and Next Generation Sequencing in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!