Info
此问题已关闭。 请重新打开它进行编辑或回答。
Computing the same series two different ways produces different results
1 次查看(过去 30 天)
显示 更早的评论
I have 2 time series, one containing the nominal price of a good (price_n) and one containing the consumer price index (cpi). I am interested in getting the real return on that good.
Method 1:
Get the real price series (price_r) and then the real return (ret_r).
price_r = price_n./cpi*cpi(1);
ret_r = price_r(2:end)./price_r(1:end-1)-1;
Method 2:
Get the nominal return (ret_n), inflation (infl) and then the real return.
ret_n = price_n(2:end)./price_n(1:end-1)-1;
infl = cpi(2:end)./cpi(1:end-1)-1;
ret_r = (1+ret_n)./(1+infl)-1;
When I do the above in Excel I am getting the exact same result, when I do it in MATLAB however I don't. Method 1 produces in MATLAB the same result I get in Excel, but Method 2 gives me a series that differs from the first one by as much as +/- 0.001 at times. My first guess was that it's a rounding error, but I find it strange to have a rounding error in MATLAB when Excel can do this and especially one of this size. Can anybody point to me what am I doing wrong?
Thank you, Alex
3 个评论
Matt Fig
2012-8-18
Yes, we need some values. For instance, I use this data:
price_n = round(rand(1,15)*100000)/100; % Up to 1000
cpi = round(rand(1,15)*20000)/100; % Up to 200
price_r = price_n./cpi*cpi(1);
ret_r = price_r(2:end)./price_r(1:end-1)-1;
ret_n = price_n(2:end)./price_n(1:end-1)-1;
infl = cpi(2:end)./cpi(1:end-1)-1;
ret_R = (1+ret_n)./(1+infl)-1;
% Now find the maximum difference:
max(diff([ret_r.',ret_R'],[],2))
And the most I have found is 1e-14.
回答(0 个)
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!