# \donttest{
library(stochcorr)
data("nse2020")
## using von Mises process as the correlation process
a <- stochcorr(nse2020$`USD/INR`, nse2020$Nifty, 1 / 250, corr_process = "vmp")
b <- stoch.bootstrap(a, nse2020$`USD/INR`, nse2020$Nifty, seed = 100)
rho_data <- as.data.frame(cbind(a$rho, nse2020$Date))
rho_data[, 2] <- as.Date(rho_data[, 2], origin = "1970-01-01")
colnames(rho_data) <- c("Correlation", "Time")
if(requireNamespace("ggplot2")){
library(ggplot2)
ggplot2::ggplot(rho_data, aes(x = Time, y = Correlation)) +
theme_test() +
theme(
text = element_text(size = 15),
axis.text.x = element_text(angle = 90, hjust = 1)
) +
geom_line() +
geom_ribbon(aes(ymin = b[1, ], ymax = b[2, ]), fill = "blue", alpha = 0.15) +
scale_y_continuous(breaks = round(seq(-1, 1, by = 0.05), 1)) +
scale_x_date(breaks = "1 month", date_labels = "%B %Y")
}
## using Circular Brownian Motions as the correlation process
a <- stochcorr(nse2020$`USD/INR`, nse2020$Nifty, 1 / 250, corr_process = "cbm")
b <- stoch.bootstrap(a, nse2020$`USD/INR`, nse2020$Nifty, seed = 100)
rho_data <- as.data.frame(cbind(a$rho, nse2020$Date))
rho_data[, 2] <- as.Date(rho_data[, 2], origin = "1970-01-01")
colnames(rho_data) <- c("Correlation", "Time")
if(requireNamespace("ggplot2")){
library(ggplot2)
ggplot2::ggplot(rho_data, aes(x = Time, y = Correlation)) +
theme_test() +
theme(
text = element_text(size = 15),
axis.text.x = element_text(angle = 90, hjust = 1)
) +
geom_line() +
geom_ribbon(aes(ymin = b[1, ], ymax = b[2, ]), fill = "blue", alpha = 0.15) +
scale_y_continuous(breaks = round(seq(-1, 1, by = 0.05), 1)) +
scale_x_date(breaks = "1 month", date_labels = "%B %Y")}
# }
Run the code above in your browser using DataLab