How can i sum specific variables within an array?

I have the following data which is the signal (0,1 or 2) fromm a trading indicator plus the daily return of that position. Signal returns zero if model is flat, 1 for one unit of long risk and 2 for 2 unit of long risk. thus over a period of time i would have a period of time where the model is flat (0) and then long (either 1 or 2). What I want to do is count the number of times the model has triggered a trade, and calculate the pnl for those trades.
Data looks like this - where I have a 504x2 array with the signal in column 1 and the daily pnl in column 2, and the model is long through rows 39:51 and goes flat in 52. Thus I want way to sum those rows where the model has traded and count the number of occurences also. Many thanks.

2 comentarios

John Chilleri
John Chilleri el 12 de En. de 2017
When does one know that the model has traded? When the signal jumps from 2 to 0, or is a period of nonzeros a trade?
the cyclist
the cyclist el 12 de En. de 2017
It would be helpful to have a small, but sufficiently general example of the input and expected output.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Productos

Preguntada:

el 10 de En. de 2017

Comentada:

el 12 de En. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by