joshuaulrich / TTR

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

WMA can't return a zoo object when nrow(wts)==n and x contains na #50

Closed mearsdj closed 3 years ago

mearsdj commented 6 years ago

It seems like there is an error, or unintended behavior, in WMA in the situation where NROW(wts)==n is true. That's because: if( NROW(wts) == n ) { 275
276 x <- na.omit(x)

You remove all na's from the data input and then calculate ma on x.

However, when you then call reclass(ma,x) after the ma is calculated, ma and x are of different length in the situation where x contained na. I think that means reclass will never succeed in that situation. Agree? If so, is there a reason for that, or is it just an situation that hasn't come up?

joshuaulrich commented 6 years ago

Can you please provide a minimal, reproducible example that demonstrates the behavior?

mearsdj commented 6 years ago

Thanks for the quick response. Sure: dts<-seq(as.Date("2017/01/01"),by=1,length.out=105) d<-zoo(c(NA,NA,NA,NA,NA,1:100),dts) d2<-WMA(d,n=10,wts=((1:10)/55)) str(d) str(d2)

joshuaulrich commented 3 years ago

This is a duplicate of #96 and was fixed in 9fe5cc53e3a63e085f7c67cfe0b5ad691440cbea.