joshuaulrich / TTR

Technical analysis and other functions to construct technical trading rules with R
GNU General Public License v2.0
330 stars 103 forks source link

EMA(ttrc, n) crashes randomly #15

Closed tonytonov closed 8 years ago

tonytonov commented 9 years ago

I'm been investigating whether TTR::EMA works well on multidimensional (multi-column) xts objects. Eventually I called EMA on ttrc (which is a data frame, but anyway, I was just wondering what happens), and I'm consistently getting random crashes with that call. Here's my devtools::session_info():

Session info ----------------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.2.1 (2015-06-18)
 system   x86_64, mingw32             
 ui       RStudio (0.99.441)          
 language (EN)                        
 collate  English_United States.1252  
 tz       Europe/Moscow               

Packages --------------------------------------------------------------------------------------------------------
 package    * version date       source        
 curl         0.9.2   2015-08-08 CRAN (R 3.2.1)
 devtools   * 1.8.0   2015-05-09 CRAN (R 3.2.1)
 digest       0.6.8   2014-12-31 CRAN (R 3.2.0)
 git2r        0.11.0  2015-08-12 CRAN (R 3.2.1)
 lattice      0.20-33 2015-07-14 CRAN (R 3.2.1)
 memoise      0.2.1   2014-04-22 CRAN (R 3.2.0)
 Rcpp         0.12.0  2015-07-25 CRAN (R 3.2.1)
 rstudioapi   0.3.1   2015-04-07 CRAN (R 3.2.0)
 rversions    1.0.2   2015-07-13 CRAN (R 3.2.1)
 TTR        * 0.23-0  2015-07-10 CRAN (R 3.2.1)
 xml2         0.1.1   2015-06-02 CRAN (R 3.2.1)
 xts        * 0.9-7   2014-01-02 CRAN (R 3.2.1)
 zoo        * 1.7-12  2015-03-16 CRAN (R 3.2.1)

Now, this is more or less reproducible example. I've tried ~10 times (in R, RStudio, with devel/stable version of xts), and the crash may occur on the first or the second call, but it is most likely to happen on the third.

library(TTR)
data(ttrc)
EMA(ttrc)
EMA(ttrc, 20)
EMA(ttrc, 30)

FWIW, I'm running Win 10, though sessionInfo() says it's Running under: Windows 8 x64 (build 9200).

joshuaulrich commented 9 years ago

I can confirm this behavior. EMA does not currently support multi-column inputs, so it should throw an error or warning (it certainly shouldn't crash your R session).

tonytonov commented 9 years ago

Thanks for the quick reply. It's probably a good idea to throw a warning for matrices as well. Running e.g. EMA(matrix(1:100, 20)) silently operates on the first column and drops all others.