[prev in list] [next in list] [prev in thread] [next in thread] 

List:       r-sig-finance
Subject:    [R-SIG-Finance] GET LOG RETURNS FUNCTION
From:       AIE ATUMA via R-SIG-Finance <r-sig-finance () r-project ! org>
Date:       2020-09-26 21:16:56
Message-ID: 1287057176.1052895.1601155016499 () mail ! yahoo ! com
[Download RAW message or body]

Dear All,

Kindly help to resolve the below.

get_log_returns <- function(x, return_format = "tibble", period = 'daily', ...) {
# Convert tibble to xts
if (!is.xts(x)) {
x <- xts(x[,-1], order.by = x$Date)
}
# Get log returns
log_returns_xts <- periodReturn(x = x$Adjusted, type = 'log', period = period, ...)
# Rename
names(log_returns_xts) <- "Log.Returns"
# Return in xts format if tibble is not specified
if (return_format == "tibble") {
log_returns <- log_returns_xts %>%
as_tibble() %>%
rownames_to_column(var = "Date") %>%
mutate(Date = ymd(Date))
} else {
log_returns <- log_returns_xts
}
log_returns
}
"MA" %>%
get_stock_prices(return_format = 'tibble')%>%
get_log_returns(return_format = "tibble")%>%head()


ERROR MESSAGE:

Error in to_period(xx, period = on.opts[[period]], ...) :  
   unsupported type
Called from: to_period(xx, period = on.opts[[period]], ...)


Thank You and Best Regards,  
Emeka I. Atuma
Integrity - Walk Your Talk Don't Talk Your Work

_______________________________________________
R-SIG-Finance@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic