Issue with roll_lm

Issue #14 resolved
Former user created an issue

I was comparing QuantTools::roll_lm and roll::roll_lm and after contacting author of roll package Jason he figured out that there might be an unintended naming issue in calculations of QuantTools::roll_lm. Please see example below (comments on the switch of x and y):

library(quantmod)
library(roll)
library(QuantTools)

DXJ <- getSymbols("DXJ", src="google", auto.assign= FALSE, from="2017-01-01")
DXJ <- na.omit(DXJ)

x <- as.matrix(1:NROW(DXJ))
colnames(x) <- "time"
y <- coredata(Cl(DXJ))

test2 <- cbind(x, y)

test3 <- roll::roll_lm(x=x, y=y, width=25, intercept=TRUE, na_restore=TRUE)
# We need to switch x and y to make it work
test4 <- QuantTools::roll_lm(x=y, y=x, n=25)
all.equal(as.vector(test3$r.squared), as.vector(test4$r.squared)) # OK
all.equal(as.vector(test3$coefficients[, 1]), as.vector(test4$alpha)) # OK
all.equal(as.vector(test3$coefficients[, 2]), as.vector(test4$beta)) # OK

# now let's use x and y as they are normally used (common naming convention)
test4 <- QuantTools::roll_lm(x=x, y=y, n=25)
all.equal(as.vector(test3$r.squared), as.vector(test4$r.squared)) # OK
all.equal(as.vector(test3$coefficients[, 1]), as.vector(test4$alpha)) # Not OK
all.equal(as.vector(test3$coefficients[, 2]), as.vector(test4$beta)) # Not OK

Comments (1)

  1. Log in to comment