- #1
JohanL
- 158
- 0
First i calculate the the average annual return for the Dow jones industrial average
over the last 22 years by using the first and last value.
To continue writing my code i also need to calculate
the average return between two days separated by one year
for every day over the last 22 years.
Shouldnt these two numbers be the same?
clear
fid = fopen( 'DJ30Daily.csv', 'r' );
str = fread( fid, '*char' );
sts = fclose( fid );
str( str == '"' ) = [];
str( str == ',' ) = '.';
cac = textscan( str, '%f' );
DJ30Daily = cell2mat(cac);
DJ30Daily = DJ30Daily(121:5668);
n=length(DJ30Daily);
K=DJ30Daily(n)-DJ30Daily(1);
P=(K/DJ30Daily(1));
AverageAnnualReturnPercentLast22y = nthroot(P, 22)m=252-1;
d=n-m;
Ptot=0;for i=1:d
K2=DJ30Daily(i+m)-DJ30Daily(i);
P2=K2/DJ30Daily(i);
P2=P2+1;
Ptot=Ptot+P2;
endAverageReturnBetweenDaysSepartedBy1yearOverTheLast22years=Ptot/d
******************************
AverageAnnualReturnPercentLast22y =
1.0575AverageReturnBetweenDaysSepartedBy1yearOverTheLast22years =
1.0863
over the last 22 years by using the first and last value.
To continue writing my code i also need to calculate
the average return between two days separated by one year
for every day over the last 22 years.
Shouldnt these two numbers be the same?
clear
fid = fopen( 'DJ30Daily.csv', 'r' );
str = fread( fid, '*char' );
sts = fclose( fid );
str( str == '"' ) = [];
str( str == ',' ) = '.';
cac = textscan( str, '%f' );
DJ30Daily = cell2mat(cac);
DJ30Daily = DJ30Daily(121:5668);
n=length(DJ30Daily);
K=DJ30Daily(n)-DJ30Daily(1);
P=(K/DJ30Daily(1));
AverageAnnualReturnPercentLast22y = nthroot(P, 22)m=252-1;
d=n-m;
Ptot=0;for i=1:d
K2=DJ30Daily(i+m)-DJ30Daily(i);
P2=K2/DJ30Daily(i);
P2=P2+1;
Ptot=Ptot+P2;
endAverageReturnBetweenDaysSepartedBy1yearOverTheLast22years=Ptot/d
******************************
AverageAnnualReturnPercentLast22y =
1.0575AverageReturnBetweenDaysSepartedBy1yearOverTheLast22years =
1.0863