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

Can't get GMMA working on xts #21

Closed mattizem closed 8 years ago

mattizem commented 8 years ago

FIrst of all. Big thanks for TTR!

I've noticed a difference in GMMA from old version to new version of TTR (or other updated part of my R setup...)

This used to work:

library(quantmod)
library(TTR)
getSymbols("^GSPC")
candleChart(GSPC, theme="white" , subset="last 5 months", TA=NULL)
# Line below is not working in new versions
addTA(GMMA(Cl(GSPC)),col=c(rep(c('blue','red'),each=6)), on=1)

But doesn't work on my new setup. I get this error:

Error in array(r, dim = d, dimnames = if (!(is.null(n1 <- names(x[[1L]])) &  : 
  length of 'dimnames' [1] not equal to array extent

After digging around I've settled on this instead for my new setup. I'm switching to data.frame as this is what the ttrc object is in example in the reference manual.

library(quantmod)
library(TTR)
getSymbols("^GSPC")
candleChart(GSPC, theme="white" , subset="last 5 months", TA=NULL)
GSPC.DF <- as.data.frame(GSPC)
GSPC.DF.GMMACL <- GMMA(GSPC.DF[,"GSPC.Close"])
addTA(GSPC.DF.GMMACL,col=c(rep(c('blue','red'),each=6)), on=1)

Am I thinking wrong or is there something in column naming or such I must adhere to in new version of TTR, as I suppose TTR is still working with xts?

Old system (don't laugh please):

> sessionInfo()
R version 2.15.0 (2012-03-30)
Platform: i386-apple-darwin9.8.0/i386 (32-bit)

locale:
[1] C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] quantmod_0.3-17 TTR_0.21-1      xts_0.8-6       zoo_1.7-7
[5] Defaults_1.1-1

loaded via a namespace (and not attached):
[1] grid_2.15.0    lattice_0.20-6

New system:

> sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.10.5 (Yosemite)

locale:
[1] C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] quantmod_0.4-5 TTR_0.23-0     xts_0.9-7      zoo_1.7-12    

loaded via a namespace (and not attached):
 [1] coin_1.1-2        lattice_0.20-33   codetools_0.2-14  mvtnorm_1.0-3    
 [5] grid_3.2.3        stats4_3.2.3      multcomp_1.4-1    strucchange_1.5-1
 [9] party_1.0-25      sandwich_2.3-4    splines_3.2.3     TH.data_1.0-6    
[13] tools_3.2.3       survival_2.38-3   modeltools_0.2-21

Big thanks!

joshuaulrich commented 8 years ago

I'm not sure why that function would have worked before, but not now... it hasn't changed since v0.20-1. As you suggest, it might have something to do with R itself, and/or xts.

That said, I can verify that it does not work now, so thank you very much for the report and reproducible example:

require(quantmod)
getSymbols("^GSPC")
GMMA(Cl(GSPC))
Error in array(r, dim = d, dimnames = if (!(is.null(n1 <- names(x[[1L]])) &  : 
  length of 'dimnames' [1] not equal to array extent