You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Submitted by: Ilya Kipnis
Assigned to: Nobody R-Forge link
So thanks to help from Josh Ulrich, I was able to get to the bottom of why my relatively simple strategy was taking an obnoxiously long time (or at least one of the reasons), in that addTxns calls getInstrument on each call if ConMult is not passed in as an argument to applyStrategy. Since applyRules already calls getInstrument, I'm hoping there's a way to cache each instrument for the duration of the strategy with only one call to getInstrument for each instrument?
Because for the futures contract I'm testing on, it takes 1.5 seconds for a call to getInstrument to finish execution on it, and when that call is made ~20,000 times over the course of the backtest, that alone takes up more than 8 hours.
Here's the offending chunk of code, in addTxns (near the beginning of the function):
if (is.null(ConMult) | !hasArg(ConMult)) {
tmp_instr <- try(getInstrument(Symbol), silent = TRUE)
if (inherits(tmp_instr, 'try-error') | !is.instrument(tmp_instr)) {
warning(paste('Instrument', Symbol, ' not found, using contract multiplier of 1'))
ConMult <- 1
}
else {
ConMult <- tmp_instr$multiplier
}
}
Calling getInstrument thousands of times IMO is highly excessive, and there is probably a workaround somewhere that reduces this operation to O(k), where k is the number of instruments, rather than O(N), where N is the number of transactions.
The text was updated successfully, but these errors were encountered:
Submitted by: Ilya Kipnis
Assigned to: Nobody
R-Forge link
So thanks to help from Josh Ulrich, I was able to get to the bottom of why my relatively simple strategy was taking an obnoxiously long time (or at least one of the reasons), in that addTxns calls getInstrument on each call if ConMult is not passed in as an argument to applyStrategy. Since applyRules already calls getInstrument, I'm hoping there's a way to cache each instrument for the duration of the strategy with only one call to getInstrument for each instrument?
Because for the futures contract I'm testing on, it takes 1.5 seconds for a call to getInstrument to finish execution on it, and when that call is made ~20,000 times over the course of the backtest, that alone takes up more than 8 hours.
Here's the offending chunk of code, in addTxns (near the beginning of the function):
if (is.null(ConMult) | !hasArg(ConMult)) {
tmp_instr <- try(getInstrument(Symbol), silent = TRUE)
if (inherits(tmp_instr, 'try-error') | !is.instrument(tmp_instr)) {
warning(paste('Instrument', Symbol, ' not found, using contract multiplier of 1'))
ConMult <- 1
}
else {
ConMult <- tmp_instr$multiplier
}
}
Calling getInstrument thousands of times IMO is highly excessive, and there is probably a workaround somewhere that reduces this operation to O(k), where k is the number of instruments, rather than O(N), where N is the number of transactions.
The text was updated successfully, but these errors were encountered: