0

I am getting the following error message from the code below:

In to_period(xx, period = on.opts[[period]], ...) :
  missing values removed from data*

It works with some stocks, but some get the same error message as this one. Should I just use na.omit(N225) before tq_transmute?

N225 <- tq_get("^N225",   
               from = "2016-01-01",
               to = "2020-12-31",
               get = "stock.prices")
    
N225_monthly_returns <- N225 %>%
      tq_transmute(select = adjusted,
                   mutate_fun = periodReturn,
                   period = "monthly",
                   col_rename = "n225_returns")
jimjames
  • 41
  • 4

1 Answers1

0

Using na.omit drops the NA rows and doesn't give any warnings. It also gives the same output as the one without using na.omit so we don't loose any rows.

library(tidyquant)

N225_monthly_returns1 <- N225 %>%
  tq_transmute(select = adjusted,
               mutate_fun = periodReturn,
               period = "monthly",
               col_rename = "n225_returns")

N225_monthly_returns2 <- na.omit(N225) %>%
  tq_transmute(select = adjusted,
               mutate_fun = periodReturn,
               period = "monthly",
               col_rename = "n225_returns")

identical(N225_monthly_returns1, N225_monthly_returns2)
#[1] TRUE
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213