0

I'm trying to use Brian Peterson's code to learn applications of MACD for our investment management situation, but have run into this error:

"Error in addTxn(Portfolio = portfolio, Symbol = symbol, TxnDate = txntime, : Transactions must be added in order. TxnDate (2007-01-03) is before last transaction in portfolio (2014-04-29) for AAPL"

I see here that this was a bug for which Josh Ulrich pushed a fix last May (2017), so why am I still getting it, especially when I am using posted code by a quantstrat author? I tried another fix Brian suggested here, but that didn't help.

The problem occurs with the applyStrategy call (about line 109 in Brian's code):

 out<-applyStrategy(strat.st , portfolios=portfolio.st,
               parameters=list(nFast=fastMA, nSlow=slowMA,
               nSig=signalMA,maType=maType),verbose=TRUE)

I realize quantstrat is "still in heavy development", so maybe I've missed some recent development. Have I? I've searched for quite a while to no avail.

Also, as a side, but related question: why is it an error that 2007-01-03 "is before last transaction in portfolio (2014-04-29)" since the former actually is chronologically before the latter date? Am I right to assume that the error is prompted by quantstrat's (actually, I guess it is blotter's) mistaken view that the former is LISTED after the latter in the object?

NelsonGon
  • 13,015
  • 7
  • 27
  • 57
W Barker
  • 324
  • 2
  • 8
  • Update: I just tried restarting my computer and the above code worked. While that is interesting, restarting my computer each time I want to run this code is hardly practical. I've tried using code from [link] (https://stackoverflow.com/questions/6313079/quit-and-restart-a-clean-r-session-from-within-r) to fix this, but it doesn't help. (Thanks to #NelsonGon for editing; maybe he can help with links in comments). So I am still looking for help on the substantive matter. – W Barker Jul 18 '19 at 16:39
  • Another update: after trying this over and over, I've realized I only need to restart R Studio for the code to work. This is a little more practical than restarting the computer, but any help in understanding how to avoid even this would be appreciated. – W Barker Jul 19 '19 at 13:59
  • Try to update quantstrat and all it's dependencies; blotter, etc. – Jared Marks Jul 21 '19 at 13:33
  • #Jared, your suggestion sounds like it might help, but aside from trail and error, is there a way of systematically understanding what packages have what dependencies to insure I cover them all? – W Barker Jul 21 '19 at 20:03
  • I found [link] (https://cran.r-project.org/web/packages/miniCRAN/vignettes/miniCRAN-dependency-graph.html) as an answer to my question about package dependencies, although -- while interesting -- I'm still not sure what to actually do with it....I'm still restarting RStudio between each run and it's getting old fast. – W Barker Jul 23 '19 at 01:45
  • It appears that I have having a conversation with myself at this point :) but just in case this will help someone else, I fixed my problem with '.blotter <- new.env()', and '.strategy <- new.env()'. – W Barker Jul 23 '19 at 14:48
  • it's very hard to speculate what the issue here is unless you provide a reproducible example – FXQuantTrader Aug 04 '19 at 04:39

0 Answers0