Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addTxn having format issues? "Transactions must be added in order" error #76

Open
mrjohn357 opened this issue Feb 13, 2019 · 5 comments

Comments

@mrjohn357
Copy link

I have received the following error on different stocks when addTxn is called on the same day by different signals (all xts indices were loaded using POSIXct and all appear to have tz = "UTC")...

"Transactions must be added in order. TxnDate (2017-08-15) is before last transaction in portfolio (2017-08-15 00:00:00) for XYZ"

using traceback(),
lastTxnDate str is: POSIXct[1:1], format: "2017-08-15 00:00:00"
TxnDate str is: POSIXct[1:1], format: "2017-08-15"

in the ruleOrderProc
txntime is: POSIXct[1:1], format: "2017-08-15"
timestamp is: POSIXct[1:1], format: "2017-08-15"

not sure how to fix the seeming conflict between formats...please advise. many thanks.

@jaymon0703
Copy link
Collaborator

hi @mrjohn357 could you share a reproducible example perhaps?

@braverock braverock changed the title addTxn having format issues? addTxn having format issues? "Transactions must be added in order" error Feb 14, 2019
@braverock
Copy link
Owner

I second the call for a reproducible example, but I'll unpack what you did say...

You said you are entering transactions from two different "signals".

This suggests one or both of two separate behaviors, both of which could result in the error you describe.

The first behavior that would cause this error would be to process your signals e.g. on a daily timeframe, and then generate transactions for the next day after the signal (hopefully not the same day, since you cant see something and act on it instantly). This would generate multiple transactions on the same timestamp. Most of the time this will be fine, for daily data, but may fail on POSIXct data, due to floating point rounding.

The other behavior is, as the error suggests, entering transactions out of order:

initPortf('dailytest',symbols='foo')
stock('foo')
stock('foo','USD')
addTxn('dailytest','foo',100,1)
addTxn('dailytest','foo','2019-01-01',100,1) 
addTxn('dailytest','foo','2019-01-01',101,1) #should be OK
addTxn('dailytest','foo','2018-12-31',99,1) #transaction from second signals, will fail

In this second case, I would suggest using separate portfolios for each signal process that you hope to run independently. You would likely do this in real life anyway, so you could keep track of post trade statistics for each of your strategies. Alternately, aggregate your signals first, and then generate transactions.

If you provide more details @mrjohn357 , we will see what we can do to assist.

@braverock braverock reopened this Feb 14, 2019
@mrjohn357
Copy link
Author

thank you both for the quick response...appreciate the insights and am investigating (as well as figure out how to provide a reproducible example)

@braverock
Copy link
Owner

@mrjohn357 any further input?

I care a lot about 'transaction out of order' issues if they are occurring where they shouldn't, but we need an example to validate that.

@mrjohn357
Copy link
Author

mrjohn357 commented Mar 23, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants