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!