Skip to content

Instantly share code, notes, and snippets.

@thistleknot
Last active December 11, 2021 23:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thistleknot/eeaf1631f736e20806c37107f344d50e to your computer and use it in GitHub Desktop.
Save thistleknot/eeaf1631f736e20806c37107f344d50e to your computer and use it in GitHub Desktop.
undifference seasonally (and non seasonally) differenced data
raw <- read.csv("https://raw.githubusercontent.com/thistleknot/Python-Stock/master/data/combined_set.csv",row.names=1,header=TRUE)
nv_diff_sets <- function(var_of_int,dataset,f_casts)
{
s_=sndif_[which(colnames(raw)==var_of_int)]
d_=ndif_[which(colnames(raw)==var_of_int)]
startRow = which(rownames(raw)==rownames(dataset[1:d_,,drop=FALSE]))
data_ <- c(na.omit(c(dataset[,var_of_int], f_casts)))
if(s_==0)
{
inv_d <- diffinv(data_,differences=d_,xi=raw[startRow,var_of_int])
}else
{
inv_d <- diffinv(diffinv(data_,differences = d_, xi=raw[startRow,var_of_int]), differences = s_,xi=raw[startRow:(startRow+season-1),var_of_int])
}
return(inv_d)
}
nv_diff_sets(var_of_int,dataframe,c())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment