I am trying to replicate the article "The Crypto Cycle and US Monetary Policy" (Che & al., 2023). Page 19, they measure the 90-day variance of the MSCI Index and of Bitcoin price.
Is there a way in R, possibly with the dplyr packages and pipes so that I can integrate the code easily, to create a new variable being the N-days realized variance (calculated summing over daily returns.)
The idea here is that I want to have a measure of volatility which is similar to the one of Miranda-Aggripino & Rey (2019) (US Monetary Policy and Global Financial Cycle), i.e. not comprised between 0 and 1 (that you obtain with any other measure of volatility) so that I can take the log of volatility as in Che & al. (2023). If anyone has a solution, I would appreciate !)
If needed, I can provide the following code to extract bitcoin prices data :
library(quantmod)
startDate=as.Date("2022-12-29")
endDate=as.Date("2024-01-17")
symbol.vec=c("BTC-USD")
getSymbols(symbol.vec , from=startDate, to=endDate)
BTC_USD=`BTC-USD`
names(BTC_USD) = gsub("-", "_", names(BTC_USD))
names(BTC_USD) <- c("Open", "High", "Low", "Close", "Volume",
"Adjusted")
btc <- BTC_USD$Close
btc2 <- subset(btc, !isWeekend(as.timeDate(time(btc)))=="TRUE")
#Here, I import Bitcoin price data (and only keep the Close prices during weekdays). However, no idea how I could compute N-days realised variance
I've posted this question in CrossValidated and still have no clue
Ignoring
btc2for now, we can calculate rolling variance withzoo::rollapply(for example).