I have a daily frequency dataframe which I am trying to convert as timeseries data & then do decompose() on it. Daily freq stock data doesn't have weekend data in it so I am not sure how to deal with general formula ts(frequency = 365)
Code that I have attempted:
data
library(tidyverse)
library(lubridate)
library(quantmod)
library(zoo)
library(xts)
adani_green_df <- read.csv("https://raw.githubusercontent.com/johnsnow09/covid19-df_stack-code/main/adani_daily_data.csv")
Getting day of the year for start() formula input
adani_green_df %>%
head(n = 1) %>%
mutate(day_of_year = lubridate::yday(date)) %>%
select(date, day_of_year)
######### output ###########
date day_of_year
<date> <dbl>
1 2018-06-18 169
I am not sure if the formula that I have used in below code: ts(frequency = 365, start = c(2018,169)) is correct or not ?
adani_green_df %>%
select(date,CLOSE) %>%
`colnames<-`(c("date","close")) %>%
column_to_rownames("date") %>%
as.xts() %>%
# print(.,calendar = TRUE) %>%
ts(frequency = 365, start = c(2018,169)) %>%
decompose() %>%
plot()
Reason of Doubt: The above plot doesn't show 2022 data where as the max date in data is 2022-09-19 as checked in below code:
# getting data range of Stock prices
adani_green_df %>%
select(date) %>%
summary()
######### output ##########
date
Min. :2018-06-18
1st Qu.:2019-07-14
Median :2020-08-06
Mean :2020-08-04
3rd Qu.:2021-08-26
Max. :2022-09-19
Update 1: Attempting code based on Answer 1
library(timetk)
plot_stl_diagnostics(adani_green_df, .date_var = date, .value = CLOSE)
plot_stl_diagnostics(adani_green_df, .date_var = date, .value = CLOSE,.feature_set = c("season"))



