[R-SIG-Finance] MACD crash problem
Joshua Ulrich
josh.m.ulrich at gmail.com
Thu Oct 11 14:28:58 CEST 2012
Hi Roger,
Thanks for the report. The problem was in the EMA function, which is
now fixed on R-Forge (revision 136). It now throws an error if there
are not enough non-NA values to calculate a n-period EMA.
Best,
--
Joshua Ulrich | about.me/joshuaulrich
FOSS Trading | www.fosstrading.com
On Wed, Oct 10, 2012 at 12:38 PM, Bos, Roger <roger.bos at rothschild.com> wrote:
> All,
>
> 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.
>
> Thanks,
>
> Roger
>
>
> library(TTR)
> 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")
>
>
> Roger J. Bos, CFA
> Rothschild Asset Management, Inc.
> Tel +1 (212) 403-5471
> Email roger.bos at rothschild.com<mailto:roger.bos at rothschild.com>
> 1251 Avenue of the Americas, NY, NY 10020
>
>
> ***************************************************************
>
> This message is for the named person's use only. It may\...{{dropped:15}}
>
> _______________________________________________
> R-SIG-Finance at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.
More information about the R-SIG-Finance
mailing list