calculate YoY growth rate

10 次查看(过去 30 天)
Peihong
Peihong 2013-9-18
Hi,friend,
price2ret function is able to calculate the growth rate of two adjacent values, if it's monthly data, it can be viewed as month over month change, can I use this function to calculate year over year change on the same monthly data series? thanks

回答(1 个)

Piyush Kumar
Piyush Kumar 2024-9-26
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:');
Monthly Data:
disp(data);
Columns 1 through 18 100.4717 98.9071 97.1829 96.8052 97.3194 97.3258 97.6066 99.1177 98.9409 98.4027 98.3130 99.1845 100.9937 100.2317 101.1831 101.5197 102.4079 104.3278 Columns 19 through 24 104.3520 105.3635 104.8089 103.4179 104.7385 103.2417
disp('MoM Growth Rates:');
MoM Growth Rates:
disp(mom_growth_rate);
Columns 1 through 18 -0.0157 -0.0176 -0.0039 0.0053 0.0001 0.0029 0.0154 -0.0018 -0.0055 -0.0009 0.0088 0.0181 -0.0076 0.0094 0.0033 0.0087 0.0186 0.0002 Columns 19 through 23 0.0096 -0.0053 -0.0134 0.0127 -0.0144
disp('YoY Growth Rates:');
YoY Growth Rates:
disp(yoy_growth_rate);
0.0052 0.0133 0.0403 0.0476 0.0510 0.0695 0.0668 0.0611 0.0576 0.0497 0.0633 0.0401

类别

Help CenterFile Exchange 中查找有关 Econometrics Toolbox 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by