braverock / blotter

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.
114 stars 50 forks source link

Refactor perTradeStats and error handle scenario where timespan is length 1 (buy and sell txn on same timestamp) #110

Open jaymon0703 opened 4 years ago

jaymon0703 commented 4 years ago

It is possible there is a round turn trade with buy and sell transactions occurring on the same whole second timestamp. Not sure about microseconds...should be rare if possible.

This feature request is about handling the error by giving the user an appropriate message if the condition is triggered.

braverock commented 4 years ago

I think the fix might be better done in addTxns than in perTradeStats.

make.index.unique in xts was created in part for this exact problem, to ensure strict time ordering of transactions even when timestamp frequency isn't high enough to keep things separated.