I have a range of returns for a certain number of days. I'm wondering how I could calculate the cumulative geometric average returns.
Eg. day 1 return =5 % day 2 return =-1% day 3 return =4
so the cumulative geometric average return for day one would be (1+0.05)^(1/1)-1
For day 2 it would be ((1+0.05)*(1+0.99))^(1/2)-1
and for day 3 it would be ((1+0.05)*(1+0.99)*(1+0.04))^(1/3)-1
Rg=((1+R1)*(1+R2)*(1+R3)...(1+Rn))^(1/n)-1
I am unsure about the logic needed for the accumulation because I am multiplying the returns together rather than adding
where I could do something like sum=sum+return to find an average for example.

답변 (1개)

KSSV
KSSV 2020년 6월 8일
편집: KSSV 2020년 6월 8일

0 개 추천

Let R be your array of size 1*n.
iwant = cumprod(1+R).^(1./(1:n))-1

댓글 수: 4

Asanka Subasinghe
Asanka Subasinghe 2020년 6월 8일
I know this is MATLAB Answers, but I am doing this with VBA. So I can only access a cell at a time using a for loop,
and I am trying to do it without using an inbuilt function.
R = 1:5 ;
n = 5 ;
iwant = cumprod(1+R).^(1./(1:n))-1 ; % Using inbuilt functions
% Using loops
CR = zeros(1,n) ;
for i = 1:n
T = 1 ;
for j = 1:i
T = T*(1+R(j)) ;
end
CR(i) = T^(1/i)-1 ;
end
isequal(iwant,CR)
Asanka Subasinghe
Asanka Subasinghe 2020년 6월 8일
Thank you!
KSSV
KSSV 2020년 6월 8일
Thanks ia accepting the answer.

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

카테고리

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

질문:

2020년 6월 8일

댓글:

2020년 6월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by