I'm a new to R. I have an Excel file called "bitcoin" which contains two columns: "date" and "BTC.Close". I've imported the data into R and transformed it into an xts object. However, I'm encountering an issue when attempting to compute returns using the following code:
library(quantmod)
ret_btc <- diff(log(Cl(bitcoin)))
This is resulting in an error message:
Error in log(Cl(bitcoin)) : non-numeric argument to mathematical function.
My objective is to generate a return series in the form of an xts object. I would greatly appreciate any assistance with this matter.
I transformed the file into an xts format using the following code:
btc$date <- as.POSIXct(btc$date, format = "%Y-%m-%d %H:%M:%S")
bitcoin <- xts(btc, order.by = btc$date)
str(bitcoin)
## An xts object on 2020-01-01 / 2021-12-31 23:00:00 containing:
## Data: character [17544, 2]
## Columns: date, BTC.Close
## Index: POSIXct, POSIXt [17544] (Time Zone: "UTC")