braverock / braverock/quantstrat
[R-Forge #5884] applyStrategy.rebalancing ignores first date when rebalancing on all dates
- 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=5884&group_id=316&atid=1269)
The applyStrategy.rebalancing function is set-up to rebalance either on all periods or on specified endpoints, but the endpoint loop assumes endpoints were specified. Specifically, the endpoint loop starts with the second index
for(i in 2:length(pindex)
which causes the first date to be skipped when no endpoints are specified (intention being to rebalance on all dates). I believe the endpoints loop and mktdata subset logic should be updated to something the example below
for(i in ifelse(names(plist) == 'all', 1, 2):length(pindex))
...
# now subset
if (names(plist) == 'all')
md_subset<-mktdata[as.POSIXct(index(mktdata)) == pindex[i]]
else
md_subset<-mktdata[as.POSIXct(index(mktdata))>pindex[i-1]&as.POSIXct(index(mktdata))<=pindex[i]]
Followups:
Date: 2014-11-06 20:09
Sender: Jonathan Owen
See also #5804. This becomes a bigger concern when rebalancing is run without a rebalancing rule.
Date: 2014-11-06 20:01
Sender: Jonathan Owen
Attaching diff file of proposed updates.
Contributor guide
Research direction
Start at the applyStrategy.rebalancing function and inspect the endpoint loop and mktdata subset logic described in the issue. Compare the proposed diff with the behavior when names(plist) is 'all', including the first date, and verify that rebalancing occurs on every intended date; the payload names no test file.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- r
- Domain
- fintech-quant
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100