R/ts_utils.R

Defines functions time_to_date ev.xts ev.mts ev.ts ev

ev <- function(x){
    UseMethod("ev", x)
}
ev.ts <- function(x){
    result <- (x/stats::lag(x, k = -1) - 1) * 100
    return(result)
}
ev.mts <- function(x){
    result <- (x/stats::lag(x, k = -1) - 1) * 100
    colnames(result) <- colnames(x)
    return(result)
}
ev.xts <- function(x){
    result <- (x / stats::lag(x, k = 1) - 1) * 100
    return(result)
}

time_to_date <- function(x){
    time <- time(x)
    years <- as.integer(round(round(time,3) - (round(time,3) %% 1), 1))
    months <- as.integer((time %% 1) * 12 + 1)
    dates <- sprintf("%i-%02d-01", years, months)
    dates <- as.Date(dates)
    dates
}

Try the rjdqa package in your browser

Any scripts or data that you put into this service are public.

rjdqa documentation built on Oct. 5, 2023, 5:08 p.m.