Hi there, I have a 6 million x 1 array of prices. I want to change it so that it is +1 if P+1 > P, -1 if P-1 <P and 0 if P+1=P

2 Kommentare

Mate 2u
Mate 2u am 4 Mai 2012
Additionally would prefer if algorithm is quick.
Daniel Shub
Daniel Shub am 4 Mai 2012
What happens if P < P+1 and P > P-1?

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 4 Mai 2012

1 Stimme

sign(diff(P));

3 Kommentare

Mate 2u
Mate 2u am 4 Mai 2012
What happens if the diff is 0?
Andrei Bobrov
Andrei Bobrov am 4 Mai 2012
hence P(ii) == P(ii + 1)
Daniel Shub
Daniel Shub am 4 Mai 2012
@Mate, the documentation for sign clearly states that sign(0) is 0.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Financial Toolbox finden Sie in Hilfe-Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by