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 comentarios

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

Iniciar sesión para comentar.

 Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 4 de Mayo de 2012

1 voto

sign(diff(P));

3 comentarios

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Financial Toolbox en Centro de ayuda y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by