#' ConeChart for the asset or fund under investigation
#' Evaluate the returns of an investment manager giventheir return and volatility
#' expectations. Calculates 1 and 2 standard deviations from the expected return.
#' @param return_series : The return series of the asset or fund that you are planning to invest in
#' @param target_return : The target return you have for the asset or fund that you are planning to invest in
#' @param expected_volatility: The expected volatility you have for the asset or fund that you are planning to invest in
#' @param timeseries_frequency: Daily, Monthly, Weekly, Yearly
#'
#' @return
#' @export
#'
#' @examples
generate_cone_chart <- function(return_series, target_return, expected_volatility, timeseries_frequency){
# Number of Observations in time series
n_obs <- nrow(return_series)
# The Cummalative Return Path of The Return Series
path <- PerformanceAnalytics::log(Return.portfolio(return_series, wealth.index = TRUE))
path <- data.frame(date = index(path), coredata(path))
colnames(path) <- c('date', 'value')
mult <- timeseries_frequency
target <- target_return
e_mu <-target_return/mult
e_sigma <- expected_volatility / sqrt(mult)
mu_path <- cumprod(rep(target+1, n_obs))-1
sigma_path <- c(e_sigma * sqrt(1:n_obs))
# Put all the paths into a tibble in preparation for graphing
dat <- tibble::tibble(
date = path$date,
'return path' = log(path$value),
'expected return path' = cumprod(rep(target + 1, n_obs))-1,
'up 1 sigma' = mu_path + sigma_path,
'up 2 sigma' = mu_path + 2*sigma_path,
'down 1 sigma' = mu_path - sigma_path,
'down 2 sigma' = mu_path - 2*sigma_path)
# Reshape the data for final graphs
plot_dat <- reshape2::melt(dat, id = "date")
plot_dat$variable <- factor(x = plot_dat$variable,
levels = c("return path", "expected return path", "up 1 sigma",
"up 2 sigma", "down 1 sigma","down 2 sigma"))
ggplot2::ggplot(data = plot_dat, aes(x = date, y = value, color = variable))+
geom_line()
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.