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!