braverock / braverock/quantstrat
[R-Forge #5834] unexpected order date if symbol index is Date class
- Dominant language
- R
- Stars
- 310
- Forks
- 121
- PR merge metrics
- No merged PRs in 30d
Description
Submitted by: Jonathan Owen
Assigned to: Nobody
[R-Forge link](http://r-forge.r-project.org/tracker/index.php?func=detail&aid=5834&group_id=316&atid=1269)
I'm not sure is this is a bug or shows a need for additional input data checks/documentation. When running the attached script (provided by Samo Pahor), which uses daily symbol data with a Date class index and a exit rule delay=1, there is both an order and transaction dated on 2/11, but the transaction uses the price from 2/10.
Signals are generated on 2/9, so using allowMagicalThinking one would expect to see an enter order and transaction on 2/9 and, due to the delay=1, an exit order and transaction on 2/10. It appears that the price logic is working as expected, but the order date (and transaction date) is not. This may have something to do with how the delay is handled in addOrder (lines 386-7) in orders.R--instead of is.timeBased, should the validation be that timestamp is POSIXct? The discrepancy is gone if the index on the symbol data is changed to be POSIXct (see line 37 of attached script).
I think it would make sense to add some logic to applyStrategy that validates that the index class for the symbol and mktdata is POSIXct, and if not either throw a warning and/or convert. Any thoughts?
Contributor guide
Research direction
Start with orders.R lines 386-7, especially how addOrder handles delay and timestamps, then trace the related validation in applyStrategy. Reproduce the discrepancy with the attached script, comparing Date and POSIXct symbol indexes. Done means the order and transaction dates match the intended delayed execution, with the index handling or its validation documented by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- fintech-quant
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100