ArOk
ArOk

Reputation: 193

R: lubridate with ts() gives wrong date

I am working with some data from the FRED and I try to convert the data to a time series with weekly observation. I use the following code:

library(quantmod)
library(lubridate)
getSymbols('WALCL',src='FRED')
assets <- ts(WALCL, frequency = 365.25/7, end = decimal_date(ymd("2020-07-15")))

But instead of the end date being set to 2020-07-15 it is always set to 2021 and the start date to 2003 instead of 2002. The same thing happens when I specify the start date instead. When I try to specify both I get the error Error in attr(data, "tsp") <- c(start, end, frequency) : invalid time series parameters specified.

Is there something obvious I am missing or is there an error with the data I downloaded or with lubridate?

Upvotes: 0

Views: 518

Answers (1)

carlo_sguera
carlo_sguera

Reputation: 395

Try

decimal_date(ymd("2020-07-15")) == max(time(assets))

You will get a comforting TRUE. In your enviornment you see 2021, but I think that it is a rounding issue. If you build your time series with end = decimal_date(ymd("2020-05-15")), 2021 disappears, right?

Upvotes: 1

Related Questions