# Stochastic volatility estimation in R

Can anyone help me with the stochvol package in R? I estimated the volatilities using this package but I am not being able to understand how to download the estimated volatilities. I used volplot function to plot the volatilities but not understanding how to download that output.

I have used the following code. When I use the volplot function, estimated volatilities look very different compared to the ones when I try to extract the median values in the m_export_oil dataframe.

library(stochvol)
library(xlsx)

set.seed(123)
oil_qtrly <- read.xlsx("oil_qtrly.xlsx", sheetIndex = 1L)
oil_qtrly$$log_real_op <- log(oil_qtrly$$real_price)

sv_model_oil <- svsample(oil_qtrly$log_real_op, priormu = c(-10, 1), priorphi = c(20, 1.1), priorsigma = 0.1,designmatrix = "ar1") summary(sv_model_oil, showlatent = FALSE) sigma_oil <- sv_model_oil$latent;
sigma_matrix_oil <- matrix(unlist(sigma_oil), ncol = 100, byrow = TRUE)

num_draws_oil <- dim(sigma_matrix_oil)
num_quarters_oil <- dim(sigma_matrix_oil)

m_export_oil <- matrix(ncol = 4, nrow = num_quarters_oil)

for (i in 1:num_quarters_oil) {
qq_oil = quantile(100*exp(sigma_matrix_oil[,i]/2),  probs = c(0.05, 0.5,0.95))
m_export_oil[i,1:3]<- qq_oil
m_export_oil[i,4] <- oil_qtrly$real_price[i] } m_export_oil<-data.frame(m_export_oil) volplot(sv_model_oil, forecast = NULL, dates = oil_qtrly$date[-1])


The underlying data for this plot can be found in sv_model_oil$summary$sd columns c('5%', '50%', '95%'). It also has the mean and sd (sd of the simulations I presume).
A great trick in R(Studio) you can use to figure this out is just to inspect the source. In an R console just run volplot without parens or in RStudio select "volplot" and press F2. Another approach is to execute the function step by step by first running debug(volplot) followed by your original command. The debugger allows you to inspect values, step forward using the command n and continue running using the command c. To stop debugging run undebug(volplot).