0

Using function slidify() in package timetk to create lm_roll(), how to retrieve the coefficients calculated by lm_roll() and calculate slope ? Below code , the last muate can't work . Thanks!

   library(timetk)
    library(tidyverse)
    library(tidyquant)
    lm_roll <- slidify(~lm(.x ~ .y),.period=90,.unlist=FALSE,.align ="right")
    FB <- FANG %>% filter(symbol == "FB")
    FB %>% 
      drop_na() %>% 
      mutate(numeric_date = as.numeric(date)) %>% 
      mutate(rolling_lm = lm_roll(adjusted,numeric_date)) %>% 
      filter(!is.na(rolling_lm))  %>% mutate(intercept= coef(rolling_lm)[1],
                                             numeric_date_index = coef(rolling_lm)[2],
                                             slope=coef(rolling_lm)[1]/coef(rolling_lm)[2])
anderwyang
  • 1,801
  • 4
  • 18

0 Answers0