Skip to content

Commit afd90ca

Browse files
committed
update plotFrontier for EQS
1 parent 76d8e56 commit afd90ca

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

R/plotFrontiers.R

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,28 @@
1414
#'
1515
#' @details
1616
#' This function provides the ability to plot frontiers based on the result of
17-
#' `meanvar.efficient.frontier`, `meanetl.efficient.frontier` or `meancsm.efficient.frontier`.
17+
#' `meanvar.efficient.frontier`, `meanetl.efficient.frontier`, `meancsm.efficient.frontier`
18+
#' or `meaneqs.efficient.frontier`.
1819
#'
19-
#' When using \code{meanvar.efficient.frontier}, \code{meanetl.efficient.frontier}
20-
#' and \code{meancsm.efficient.frontier}, the result will be frontiers data,
21-
#' including the weights for each point on the mean-risk efficient frontiers.
22-
#' Before using this function, user should declare which risk that they want to
23-
#' compare, and what parameters that they want to use to calculate the risk,
24-
#' e.g. \code{ES_alpha} for ES, \code{moment_setting} for var. Then this function
25-
#' will calculate back mean and risk based on the weight, and draw a plot.
20+
#' When using \code{meanvar.efficient.frontier}, \code{meanetl.efficient.frontier},
21+
#' \code{meancsm.efficient.frontier} and \code{meaneqs.efficient.frontier}, the
22+
#' result will be frontiers data, including the weights for each point on the
23+
#' mean-risk efficient frontiers. Before using this function, user should declare
24+
#' which risk that they want to compare, and what parameters that they want to
25+
#' use to calculate the risk, e.g. \code{ES_alpha} for ES, \code{moment_setting}
26+
#' for var. Then this function will calculate back mean and risk based on the
27+
#' weight, and draw a plot.
2628
#'
2729
#' Default settings use colors and line types to differentiate portfolios, and set
2830
#' the portfolio name as 'Portfolio 1' and so on. Users could customize col, lty,
2931
#' lwd and legend.labels to better the plot.
3032
#'
3133
#' @param R an xts object of asset returns
3234
#' @param frontiers a list of frontiers, for example, list(ef1=meanvar.efficient.frontier(), ef2=meanvar.efficient.frontier())
33-
#' @param risk type of risk that you want to compare, could be 'StdDev', 'ES', 'CSM'
35+
#' @param risk type of risk that you want to compare, could be 'StdDev', 'ES', 'CSM', 'EQS'
3436
#' @param ES_alpha the default value is 0.05, but could be specified as any value between 0 and 1
3537
#' @param CSM_alpha the default value is 0.05, but could be specified as any value between 0 and 1
38+
#' @param EQS_alpha the default value is 0.05, but could be specified as any value between 0 and 1
3639
#' @param moment_setting the default is NULL, if customize momentFUN please provide moment_setting=list(mu=, sigma=)
3740
#' @param main title used in the plot.
3841
#' @param plot_type define the plot_type, default is "l"
@@ -53,13 +56,15 @@
5356
#' @author Xinran Zhao
5457
#' @export plotFrontiers
5558
#'
56-
plotFrontiers <- function(R, frontiers, risk, ES_alpha = 0.05, CSM_alpha = 0.05, moment_setting = NULL, main="Efficient Frontiers", plot_type = "l", cex.axis=0.5, element.color="darkgray", legend.loc=NULL, legend.labels=NULL, cex.legend=0.8, xlim=NULL, ylim=NULL, ..., labels.assets=TRUE, pch.assets=21, cex.assets=0.8, col=NULL, lty=NULL, lwd=NULL){
59+
plotFrontiers <- function(R, frontiers, risk, ES_alpha = 0.05, CSM_alpha = 0.05, EQS_alpha = 0.05, moment_setting = NULL, main="Efficient Frontiers", plot_type = "l", cex.axis=0.5, element.color="darkgray", legend.loc=NULL, legend.labels=NULL, cex.legend=0.8, xlim=NULL, ylim=NULL, ..., labels.assets=TRUE, pch.assets=21, cex.assets=0.8, col=NULL, lty=NULL, lwd=NULL){
5760
if(risk %in% c('StdDev', 'var', 'stdDev')){
5861
risk = 'StdDev'
5962
} else if(risk %in% c('etl', 'ES', 'es')){
6063
risk = 'ES'
6164
} else if(risk %in% c('CSM', 'csm')){
6265
risk = 'CSM'
66+
} else if(risk %in% c('EQS', 'eqs')){
67+
risk = 'EQS'
6368
} else {print('please give the right risk type')}
6469

6570
wname = paste0('w.', colnames(R))
@@ -74,7 +79,7 @@ plotFrontiers <- function(R, frontiers, risk, ES_alpha = 0.05, CSM_alpha = 0.05,
7479
mean_value = c()
7580
risk_value = c()
7681
for(j in 1:dim(w)[1]){
77-
risk_measures = extract_risk(R, w[j,], ES_alpha = ES_alpha, CSM_alpha = CSM_alpha, moment_setting = moment_setting)
82+
risk_measures = extract_risk(R, w[j,], ES_alpha = ES_alpha, CSM_alpha = CSM_alpha, EQS_alpha = EQS_alpha, moment_setting = moment_setting)
7883
mean_value = append(mean_value, risk_measures$mean)
7984
risk_value = append(risk_value, risk_measures[risk])
8085
}

man/plotFrontiers.Rd

Lines changed: 15 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)