blotter provides transaction infrastructure for defining transactions, portfolios and accounts for trading systems and simulation. Provides portfolio support for multi-asset class and multi-currency portfolios. Actively maintained and developed.
112
stars
49
forks
source link
perTradeStats with tradeDef="increased.to.reduced" breaks when open trade shares a timestamp with an unwind trade #57
Found a potential edge case where if a transaction results in a position going through zero and the resulting open trade is part of the final open position at the end of the strategy, then we do not build the trades$Start vector appropriately...adding both time stamps as opposed to only the one which resulted in the open trade.
Solution (ln 205) is to reference only the last matching timestamp from which(index(incrPos) == testdf$start_ts[first(which(is.na(testdf$end_ts)))]) which is the index of the opening portion of the relevant transaction taking the position through zero.
# add extra 'trade start' if there's an open trade, so 'includeOpenTrade' logic will work
if(any(is.na(testdf$end_ts))){
trades$Start <- c(trades$Start,last(which(index(incrPos) == testdf$start_ts[first(which(is.na(testdf$end_ts)))])))
}
Found a potential edge case where if a transaction results in a position going through zero and the resulting open trade is part of the final open position at the end of the strategy, then we do not build the trades$Start vector appropriately...adding both time stamps as opposed to only the one which resulted in the open trade.
Solution (ln 205) is to reference only the last matching timestamp from
which(index(incrPos) == testdf$start_ts[first(which(is.na(testdf$end_ts)))])
which is the index of the opening portion of the relevant transaction taking the position through zero.