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 个评论
John Chilleri
2017-1-12
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
2017-1-12
It would be helpful to have a small, but sufficiently general example of the input and expected output.
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Transaction Cost Analysis 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!