[R-SIG-Finance] MACD crash problem
Brian G. Peterson
brian at braverock.com
Wed Oct 10 19:47:24 CEST 2012
On 10/10/2012 12:38 PM, Bos, Roger wrote:
> Here is some reproducible code that causes R to crash while running the MACD function in the TTR library. The problem seems to be when the nSlow and nSig parameters are so large that the function is not able to calculate the moving average length denoted by nSig. Now that I know what the problem is I can avoid it, but it would be nice if the MACD function returned an error instead of crashing R (unless its just my setup-R 2.15.1 64-bit win7). Maybe someone can confirm for me by testing out the code below.
> The first call to MACD should work as many times as you call it, as expected. However the second one causes problems because the data in temp is too short to product a moving average over 22 data points. This crashes R almost always, but occasionally it does work once or twice. That's why I used for loops to make my point. First lets see if other people have the same results that I do. If so, it would be nice if MACD produced an error instead of crashing R.
> temp <- 1:60
> for (i in 1:10) x <- MACD(temp, nFast=15, nSlow=40, nSig=21) # Works fine
> print("okay so far")
> for (i in 1:10) x <- MACD(temp, nFast=15, nSlow=40, nSig=22) # Crashes R
> print("bet you don't see this")
This is reproducible for me with TTR-0.21-1 on 64 bit linux, and with
svn r135 from R-Forge.
More information about the R-SIG-Finance