Azzera filtri
Azzera filtri

Loop plus diff function with non-integers: Feasible?

2 visualizzazioni (ultimi 30 giorni)
hi all,
I am not sure if this is easy or not but I am struggling with the following:
Say that I have a vector Xt (10,000*1) of daily stock returns. I built this partition function formula:
for j=1:125;
E=Xt(1:j:end);
EE=diff(E(2:end));
EEE=diff(E(1:end-1));
Sq(j)=sum(abs(EE-EEE).^3);
end;
where j=1:125 is the various intervals that I wish to calculate the difference EE-EEE from the vector Xt. Now, what is the most efficient way for me to calculate the EE-EEE using non integer numbers?
If I construct a new vector as follow:
expo=0:1000;
A=1.1*ones(size(expo));
ddt=A.^expo;
in ddt there are numbers in which I would like to implement rather than 1:125.
(ddt vector looks like [1 1.1 1.21 1.331 1.4641 1.61051 1.771561 1.9487 2.14358]
What's the best way for to achieve this? In my orignal formula, I generate a Sq vector of size 1X125 for integer intervals but I want more numbers therefore I must turn to non-integer numbers.
Thank you very much for the help!

Risposta accettata

Oleg Komarov
Oleg Komarov il 31 Mag 2012
If I understood correctly, you want to partition non non integer ontervals. Say you want to select Xt every 1.331 step.
Since you have values only at Xt(1), Xt(2) etc... and not on Xt(1.331), Xt(2.662) etc but you still want to get those number then you can interpolate.
  2 Commenti
Charles Martineau
Charles Martineau il 31 Mag 2012
Yes exactly! Basically the best is for me to generate a new Xt vector with elements 1.331 2.662. ... and then take the diff of this vector.
Oleg Komarov
Oleg Komarov il 31 Mag 2012
Use interp1() to generate the interpolated values of Xt.

Accedi per commentare.

Più risposte (1)

Charles Martineau
Charles Martineau il 31 Mag 2012
If anyone can help... I am really struggling with this one!

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by