Calculate 10y returns out of monthly data

hey guys,
i have monthly returns (1mil. simulations). Now i want to calculate corresponding 10 year returns. for example vextor x: 0.05 0.02 0.03 0.4 -0.21 ...
what matlab should do now is to calculate: ((1+r(1))*(1+r(2))*...(1+r(120)))-1 and ((1+r(121))*(1+r(122))*...(1+r(240)))-1 and so on...
thx for your help

 채택된 답변

Andrei Bobrov
Andrei Bobrov 2014년 10월 24일
편집: Andrei Bobrov 2014년 10월 24일

0 개 추천

out = prod(1 + reshape(x,120,[])) - 1;
or
out = accumarray(ceil((1:numel(x))'/120),x(:),[],@(x)prod(1+x)-1);

추가 답변 (1개)

Roger Wohlwend
Roger Wohlwend 2014년 10월 24일

0 개 추천

y = exp(filter(ones(120,1),1,log(1+r)))-1;
y = y(120:end);

댓글 수: 2

Markus
Markus 2014년 10월 24일
thx thats what i wanted, but now it calculates: ((1+r(1))*(1+r(2))*...(1+r(120)))-1 and ((1+r(2))*(1+r(3))*...(1+r(121)))-1 and so on. what i wanted was: ((1+r(1))*(1+r(2))*...(1+r(120)))-1 and ((1+r(121))*(1+r(122))*...(1+r(240)))-1 and so on..
Oh, my mistake.
y = exp(filter(ones(120,1),1,log(1+r)))-1;
y = y(120:120:end);

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

질문:

2014년 10월 23일

편집:

2014년 10월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by