How do I calculate log returns for stock prices?

26 views (last 30 days)
Athirah Sabtu
Athirah Sabtu on 18 Apr 2015
Edited: dpb on 20 Apr 2015
I have the coding but I don't know how to do it.
for t=1:length(data)
Logreturn(t+1)=log(data(t+1))-log(data(t));
end
my data is for 10 years. so, t=1 or t=10?

Answers (1)

dpb
dpb on 19 Apr 2015
Edited: dpb on 20 Apr 2015
r=log(data(2:end./data(1:end-1));
Annualized is dependent upon what definition you want--the averaged annualized would then simply be
Ra=mean(r);
the annualized log return over the period is simply
Rp=log(data(end)/data(1))/length(data);
whereas the geometric ROR would be
Rg=(prod(1+r)^^1/length(data))-1;

Community Treasure Hunt

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

Start Hunting!