I believe I have managed to do something similar to what the question asks.
If it’s not the following, maybe I can adapt to your problem.
The trick is to divide the data by month, using the base function split
and the function as.yearmon
package zoo
. This package is also used to create a time series, the series z
, only with two database columns tickers
.
library(BatchGetSymbols)
library(PerformanceAnalytics)
library(zoo)
ibvsp <- BatchGetSymbols('^BVSP', first.date = as.Date('2012-01-01'),
last.date = as.Date('2017-12-31'))
tickers <- ibvsp$df.tickers[complete.cases(ibvsp$df.tickers), ]
z <- zoo(tickers[9:10], order.by = tickers[, 7])
z_month <- split(z, as.yearmon(index(z)))
cvar <- as.data.frame(t(sapply(z_month, CVaR)))
names(cvar) <- names(tickers[9:10])
head(cvar)
# ret.adjusted.prices ret.closing.prices
#jan 2012 -0.01410941 -0.01410941
#fev 2012 -0.02108851 -0.02108851
#mar 2012 -0.02402775 -0.02402775
#abr 2012 -0.02146428 -0.02146428
#mai 2012 -0.03548744 -0.03548744
#jun 2012 -0.03252744 -0.03252744
It is best to post the code you used. Just as it is is hard to say how to solve the problem. Post the code you used both to download the data and to calculate Cvar, please.
– Rui Barradas