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 个评论

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?
It would be helpful to have a small, but sufficiently general example of the input and expected output.

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Transaction Cost Analysis 的更多信息

产品

提问:

2017-1-10

Community Treasure Hunt

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

Start Hunting!

Translated by