Can anyone see if there is something wrong in my matlab code? My objective is to replicate this formula:
q can take value 1,2,3 and 5.
I constructed my vector Xt where each element are a cumulative sum of log(1+return) at each time (t) – for stock returns – first element is normalized to log(1).
Then to compute each element Sq(T,delta t) for the four values of q this is my matlab code:
for j=1:length(dt);
E=Xt(1:dt(j):end);
EE=diff(E(2:end));
EEE=diff(E(1:end-1));
Sqone(j)=sum(abs(EE-EEE).^1);
Sqtwo(j)=sum(abs(EE-EEE).^2);
Sqthree(j)=sum(abs(EE-EEE).^3);
Sqfive(j)=sum(abs(EE-EEE).^5); end;
Is there something wrong in the code above? I am asking this because I know there is something wrong since I am not getting the expected results. I am convinced that it is due to my code posted above.
the vector dt is a vector that goes from 1 to high number – depending on the size of Xt. But my vector dt is not the problem.
Thank you for all your help!
You are taking the difference twice. Once using
diffand once usingEE-EEE. The correct code is: