Hi,
You can calculate year over year change on the same monthly data series.
For example, I have created dummy data for 24 months. To calculate YoY growth rated, we will pass data with gap of 12 months, like Jan 2023 and Jan 2024.
% Generate dummy data for 24 months (2 years)
months = 1:24;
data = 100 + cumsum(randn(1, 24)); % Starting at 100 and adding random changes
% Initialize arrays to store MoM and YoY growth rates
mom_growth_rate = zeros(1, 23); % 23 because MoM is between adjacent months
yoy_growth_rate = zeros(1, 12); % 12 because YoY is between same months in consecutive years
% Calculate MoM growth rates
for i = 2:24
mom_growth_rate(i-1) = price2ret([data(i-1), data(i)]);
end
% Calculate YoY growth rates
for i = 13:24
yoy_growth_rate(i-12) = price2ret([data(i-12), data(i)]);
end
% Display results
disp('Monthly Data:');
disp(data);
disp('MoM Growth Rates:');
disp(mom_growth_rate);
disp('YoY Growth Rates:');
disp(yoy_growth_rate);