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;

end

AverageReturnBetweenDaysSepartedBy1yearOverTheLast22years=Ptot/d

******************************

AverageAnnualReturnPercentLast22y =

1.0575

AverageReturnBetweenDaysSepartedBy1yearOverTheLast22years =

1.0863