[Returnanalytics-commits] r2932 - in pkg/PortfolioAnalytics: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Aug 29 19:30:10 CEST 2013
Author: rossbennett34
Date: 2013-08-29 19:30:09 +0200 (Thu, 29 Aug 2013)
New Revision: 2932
Modified:
pkg/PortfolioAnalytics/R/charts.efficient.frontier.R
pkg/PortfolioAnalytics/man/chart.EfficientFrontier.Rd
pkg/PortfolioAnalytics/man/chart.EfficientFrontierOverlay.Rd
Log:
Adding pch.assets parameter for efficient frontier. Change efficient frontier chart for optimize.portfolio objects to use plot for the efficient frontier and points for the assets.
Modified: pkg/PortfolioAnalytics/R/charts.efficient.frontier.R
===================================================================
--- pkg/PortfolioAnalytics/R/charts.efficient.frontier.R 2013-08-29 16:49:14 UTC (rev 2931)
+++ pkg/PortfolioAnalytics/R/charts.efficient.frontier.R 2013-08-29 17:30:09 UTC (rev 2932)
@@ -48,6 +48,7 @@
#' @param cex.legend A numerical value giving the amount by which the legend should be magnified relative to the default.
#' @param RAR.text Risk Adjusted Return ratio text to plot in the legend
#' @param asset.names TRUE/FALSE to include the asset names in the plot
+#' @param pch.assets plotting character of the assets, same as in \code{\link{plot}}
#' @author Ross Bennett
#' @export
chart.EfficientFrontier <- function(object, match.col="ES", n.portfolios=25, xlim=NULL, ylim=NULL, cex.axis=0.8, element.color="darkgray", main="Efficient Frontier", ...){
@@ -56,7 +57,7 @@
#' @rdname chart.EfficientFrontier
#' @export
-chart.EfficientFrontier.optimize.portfolio.ROI <- function(object, match.col="ES", n.portfolios=25, xlim=NULL, ylim=NULL, cex.axis=0.8, element.color="darkgray", main="Efficient Frontier", ..., rf=0, cex.legend=0.8, asset.names=TRUE){
+chart.EfficientFrontier.optimize.portfolio.ROI <- function(object, match.col="ES", n.portfolios=25, xlim=NULL, ylim=NULL, cex.axis=0.8, element.color="darkgray", main="Efficient Frontier", ..., rf=0, cex.legend=0.8, asset.names=TRUE, pch.assets=21){
if(!inherits(object, "optimize.portfolio.ROI")) stop("object must be of class optimize.portfolio.ROI")
portf <- object$portfolio
@@ -123,11 +124,13 @@
ylim[2] <- ylim[2] * 1.1
}
- # plot a scatter of the assets
- plot(x=asset_risk, y=asset_ret, xlab=match.col, ylab="Mean", main=main, xlim=xlim, ylim=ylim, axes=FALSE, ...)
+ # plot the efficient frontier line
+ plot(x=x.f, y=y.f, ylab="Mean", xlab=match.col, main=main, xlim=xlim, ylim=ylim, axes=FALSE, ...)
+
+ # risk-return scatter of the assets
+ points(x=asset_risk, y=asset_ret, pch=pch.assets)
if(asset.names) text(x=asset_risk, y=asset_ret, labels=rnames, pos=4, cex=0.8)
- # plot the efficient line
- lines(x=x.f, y=y.f, col="darkgray", lwd=2)
+
# plot the optimal portfolio
points(opt_risk, opt_ret, col="blue", pch=16) # optimal
text(x=opt_risk, y=opt_ret, labels="Optimal",col="blue", pos=4, cex=0.8)
@@ -147,7 +150,7 @@
#' @rdname chart.EfficientFrontier
#' @export
-chart.EfficientFrontier.optimize.portfolio <- function(object, match.col="ES", n.portfolios=25, xlim=NULL, ylim=NULL, cex.axis=0.8, element.color="darkgray", main="Efficient Frontier", ..., RAR.text="SR", rf=0, cex.legend=0.8, asset.names=TRUE){
+chart.EfficientFrontier.optimize.portfolio <- function(object, match.col="ES", n.portfolios=25, xlim=NULL, ylim=NULL, cex.axis=0.8, element.color="darkgray", main="Efficient Frontier", ..., RAR.text="SR", rf=0, cex.legend=0.8, asset.names=TRUE, pch.assets=21){
# This function will work with objects of class optimize.portfolio.DEoptim,
# optimize.portfolio.random, and optimize.portfolio.pso
@@ -212,11 +215,13 @@
ylim[2] <- ylim[2] * 1.1
}
- # plot a scatter of the assets
- plot(x=asset_risk, y=asset_ret, xlab=match.col, ylab="Mean", main=main, xlim=xlim, ylim=ylim, axes=FALSE, ...)
+ # plot the efficient frontier line
+ plot(x=x.f, y=y.f, ylab="Mean", xlab=match.col, main=main, xlim=xlim, ylim=ylim, axes=FALSE, ...)
+
+ # risk-return scatter of the assets
+ points(x=asset_risk, y=asset_ret, pch=pch.assets)
if(asset.names) text(x=asset_risk, y=asset_ret, labels=rnames, pos=4, cex=0.8)
- # plot the efficient line
- lines(x=x.f, y=y.f, col="darkgray", lwd=2)
+
# plot the optimal portfolio
points(opt_risk, opt_ret, col="blue", pch=16) # optimal
text(x=opt_risk, y=opt_ret, labels="Optimal",col="blue", pos=4, cex=0.8)
@@ -375,7 +380,7 @@
#' @rdname chart.EfficientFrontier
#' @export
-chart.EfficientFrontier.efficient.frontier <- function(object, match.col="ES", n.portfolios=NULL, xlim=NULL, ylim=NULL, cex.axis=0.8, element.color="darkgray", main="Efficient Frontier", ..., RAR.text="SR", rf=0, cex.legend=0.8, asset.names=TRUE){
+chart.EfficientFrontier.efficient.frontier <- function(object, match.col="ES", n.portfolios=NULL, xlim=NULL, ylim=NULL, cex.axis=0.8, element.color="darkgray", main="Efficient Frontier", ..., RAR.text="SR", rf=0, cex.legend=0.8, asset.names=TRUE, pch.assets=21){
if(!inherits(object, "efficient.frontier")) stop("object must be of class 'efficient.frontier'")
# get the returns and efficient frontier object
@@ -426,7 +431,7 @@
plot(x=frontier[, mtc], y=frontier[, mean.mtc], ylab="Mean", xlab=match.col, main=main, xlim=xlim, ylim=ylim, axes=FALSE, ...)
# risk-return scatter of the assets
- points(x=asset_risk, y=asset_ret)
+ points(x=asset_risk, y=asset_ret, pch=pch.assets)
if(asset.names) text(x=asset_risk, y=asset_ret, labels=rnames, pos=4, cex=0.8)
if(!is.null(rf)){
@@ -465,9 +470,10 @@
#' @param ylim set the y-axis limit, same as in \code{\link{plot}}
#' @param ... passthrough parameters to \code{\link{plot}}
#' @param asset.names TRUE/FALSE to include the asset names in the plot
+#' @param pch.assets plotting character of the assets, same as in \code{\link{plot}}
#' @author Ross Bennett
#' @export
-chart.EfficientFrontierOverlay <- function(R, portfolio_list, type, n.portfolios=25, match.col="ES", search_size=2000, main="Efficient Frontiers", cex.axis=0.8, element.color="darkgray", legend.loc=NULL, legend.labels=NULL, cex.legend=0.8, xlim=NULL, ylim=NULL, ..., asset.names=TRUE){
+chart.EfficientFrontierOverlay <- function(R, portfolio_list, type, n.portfolios=25, match.col="ES", search_size=2000, main="Efficient Frontiers", cex.axis=0.8, element.color="darkgray", legend.loc=NULL, legend.labels=NULL, cex.legend=0.8, xlim=NULL, ylim=NULL, ..., asset.names=TRUE, pch.assets=21){
# create multiple efficient frontier objects (one per portfolio in portfolio_list)
if(!is.list(portfolio_list)) stop("portfolio_list must be passed in as a list")
if(length(portfolio_list) == 1) warning("Only one portfolio object in portfolio_list")
@@ -495,7 +501,7 @@
}
# plot the assets
- plot(x=asset_risk, y=asset_ret, xlab=match.col, ylab="Mean", main=main, xlim=xlim, ylim=ylim, axes=FALSE, ...)
+ plot(x=asset_risk, y=asset_ret, xlab=match.col, ylab="Mean", main=main, xlim=xlim, ylim=ylim, axes=FALSE, pch=pch.assets, ...)
axis(1, cex.axis = cex.axis, col = element.color)
axis(2, cex.axis = cex.axis, col = element.color)
box(col = element.color)
Modified: pkg/PortfolioAnalytics/man/chart.EfficientFrontier.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/chart.EfficientFrontier.Rd 2013-08-29 16:49:14 UTC (rev 2931)
+++ pkg/PortfolioAnalytics/man/chart.EfficientFrontier.Rd 2013-08-29 17:30:09 UTC (rev 2932)
@@ -15,21 +15,23 @@
ylim = NULL, cex.axis = 0.8,
element.color = "darkgray",
main = "Efficient Frontier", ..., rf = 0,
- cex.legend = 0.8, asset.names = TRUE)
+ cex.legend = 0.8, asset.names = TRUE, pch.assets = 21)
chart.EfficientFrontier.optimize.portfolio(object,
match.col = "ES", n.portfolios = 25, xlim = NULL,
ylim = NULL, cex.axis = 0.8,
element.color = "darkgray",
main = "Efficient Frontier", ..., RAR.text = "SR",
- rf = 0, cex.legend = 0.8, asset.names = TRUE)
+ rf = 0, cex.legend = 0.8, asset.names = TRUE,
+ pch.assets = 21)
chart.EfficientFrontier.efficient.frontier(object,
match.col = "ES", n.portfolios = NULL, xlim = NULL,
ylim = NULL, cex.axis = 0.8,
element.color = "darkgray",
main = "Efficient Frontier", ..., RAR.text = "SR",
- rf = 0, cex.legend = 0.8, asset.names = TRUE)
+ rf = 0, cex.legend = 0.8, asset.names = TRUE,
+ pch.assets = 21)
}
\arguments{
\item{object}{optimal portfolio created by
@@ -75,6 +77,9 @@
\item{asset.names}{TRUE/FALSE to include the asset names
in the plot}
+
+ \item{pch.assets}{plotting character of the assets, same
+ as in \code{\link{plot}}}
}
\description{
This function charts the efficient frontier and
Modified: pkg/PortfolioAnalytics/man/chart.EfficientFrontierOverlay.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/chart.EfficientFrontierOverlay.Rd 2013-08-29 16:49:14 UTC (rev 2931)
+++ pkg/PortfolioAnalytics/man/chart.EfficientFrontierOverlay.Rd 2013-08-29 17:30:09 UTC (rev 2932)
@@ -8,7 +8,7 @@
cex.axis = 0.8, element.color = "darkgray",
legend.loc = NULL, legend.labels = NULL,
cex.legend = 0.8, xlim = NULL, ylim = NULL, ...,
- asset.names = TRUE)
+ asset.names = TRUE, pch.assets = 21)
}
\arguments{
\item{R}{an xts object of asset returns}
@@ -61,6 +61,9 @@
\item{asset.names}{TRUE/FALSE to include the asset names
in the plot}
+
+ \item{pch.assets}{plotting character of the assets, same
+ as in \code{\link{plot}}}
}
\description{
Overlay the efficient frontiers of multiple portfolio
More information about the Returnanalytics-commits
mailing list