From noreply at r-forge.r-project.org Tue Feb 17 00:06:00 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 17 Feb 2015 00:06:00 +0100 (CET) Subject: [Introcompfinr-commits] r7 - / pkg/IntroCompFinR pkg/IntroCompFinR/R pkg/IntroCompFinR/man Message-ID: <20150216230600.2AC2A1842F7@r-forge.r-project.org> Author: bethanyyollin Date: 2015-02-17 00:05:59 +0100 (Tue, 17 Feb 2015) New Revision: 7 Modified: / pkg/IntroCompFinR/DESCRIPTION pkg/IntroCompFinR/R/efficient.frontier.R pkg/IntroCompFinR/R/efficient.portfolio.R pkg/IntroCompFinR/R/getPortfolio.R pkg/IntroCompFinR/R/globalMin.portfolio.R pkg/IntroCompFinR/R/plot.Markowitz.R pkg/IntroCompFinR/R/plot.portfolio.R pkg/IntroCompFinR/R/print.Markowitz.R pkg/IntroCompFinR/R/print.portfolio.R pkg/IntroCompFinR/R/summary.Markowitz.R pkg/IntroCompFinR/R/summary.portfolio.R pkg/IntroCompFinR/R/tangency.portfolio.R pkg/IntroCompFinR/man/efficient.frontier.Rd pkg/IntroCompFinR/man/efficient.portfolio.Rd pkg/IntroCompFinR/man/getPortfolio.Rd pkg/IntroCompFinR/man/globalMin.portfolio.Rd pkg/IntroCompFinR/man/plot.Markowitz.Rd pkg/IntroCompFinR/man/plot.portfolio.Rd pkg/IntroCompFinR/man/print.Markowitz.Rd pkg/IntroCompFinR/man/print.portfolio.Rd pkg/IntroCompFinR/man/summary.Markowitz.Rd pkg/IntroCompFinR/man/summary.portfolio.Rd pkg/IntroCompFinR/man/tangency.portfolio.Rd Log: Roxygenized existing functions. Property changes on: ___________________________________________________________________ Added: svn:ignore + .Rproj.user .Rhistory .RData Modified: pkg/IntroCompFinR/DESCRIPTION =================================================================== --- pkg/IntroCompFinR/DESCRIPTION 2012-08-29 16:17:36 UTC (rev 6) +++ pkg/IntroCompFinR/DESCRIPTION 2015-02-16 23:05:59 UTC (rev 7) @@ -1,11 +1,14 @@ Package: IntroCompFinR Type: Package -Title: Introduction to computational Finance in R +Title: Introduction to Computational Finance in R Version: 1.0 Date: 2012-08-26 Author: Eric Zivot Maintainer: Eric Zivot -Description: The package is for the introduction to computational finance in R for Econ 424 in University of Washington, Seattle. There are examples and function for demonstration and teaching purpose. Students are expected to download the package and learn from the codes and examples. Moreover, the book coming soon is also based on this package. +Description: The package is for the introduction to computational finance in R for Econ 424 in + University of Washington, Seattle. There are examples and function for demonstration and teaching + purpose. Students are expected to download the package and learn from the codes and examples. + Moreover, the book coming soon is also based on this package. License: GPL-2 Depends: R (>= 2.12.2),quadprog,tseries,zoo -LazyLoad: yes +LazyLoad: yes \ No newline at end of file Modified: pkg/IntroCompFinR/R/efficient.frontier.R =================================================================== --- pkg/IntroCompFinR/R/efficient.frontier.R 2012-08-29 16:17:36 UTC (rev 6) +++ pkg/IntroCompFinR/R/efficient.frontier.R 2015-02-16 23:05:59 UTC (rev 7) @@ -1,3 +1,67 @@ +#' @title Compute efficient frontier of risky assets +#' +#' @author Eric Zivot +#' +#' @description +#' The function constructs the set of efficient portfolios using this method (see details) for a +#' collection of alpha values. +#' +#' @details +#' The the set of efficient portfolios of risky assets can be computed as a convex combination of +#' any two efficient portfolios. It is convenient to use the global minimum variance portfolio as +#' one portfolio and an efficient portfolio with target expected return equal to the maximum +#' expected return of the assets under consideration as the other portfolio. Call these portfolios +#' \eqn{m} and \eqn{x}, respectively. For any number alpha, another efficient +#' portfolio can be computed as \eqn{z=\alpha m+(1-\alpha)x}. +#' +#' @param er N x 1 vector of expected returns +#' @param cov.mat N x N return covariance matrix +#' @param nport scalar, number of efficient portfolios to compute +#' @param alpha.min minimum value of alpha, default is -.5 +#' @param alpha.max maximum value of alpha, defualt is 1.5 +#' @param shorts logical, allow shorts is \code{TRUE} +#' @param object object of class Markowitz +#' @param plot.assets logical, if \code{TRUE} then plot asset \code{sd} and \code{er} +#' @param risk.free numeric, risk free rate +#' @param ... controlled variables for \code{plot()} or \code{print()} +#' +#' @return +#' \item{call}{captures function call} +#' \item{er}{nport x 1 vector of expected returns on efficient porfolios} +#' \item{sd}{nport x 1 vector of std deviations on efficient portfolios} +#' \item{weights}{nport x N matrix of weights on efficient portfolios} +#' +#' @examples +#' # construct the data +#' asset.names = c("MSFT", "NORD", "SBUX") +#' er = c(0.0427, 0.0015, 0.0285) +#' names(er) = asset.names +#' covmat = matrix(c(0.0100, 0.0018, 0.0011, +#' 0.0018, 0.0109, 0.0026, +#' 0.0011, 0.0026, 0.0199), +#' nrow=3, ncol=3) +#' r.free = 0.005 +#' dimnames(covmat) = list(asset.names, asset.names) +#' +#' # tangency portfolio +#' tan.port <- tangency.portfolio(er, covmat, r.free) +#' # compute global minimum variance portfolio +#' gmin.port = globalMin.portfolio(er, covmat) +#' +#' # compute portfolio frontier +#' ef <- efficient.frontier(er, covmat, alpha.min=-2, +#' alpha.max=1.5, nport=20) +#' attributes(ef) +#' +#' plot(ef) +#' plot(ef, plot.assets=TRUE, col="blue", pch=16) +#' points(gmin.port$sd, gmin.port$er, col="green", pch=16, cex=2) +#' points(tan.port$sd, tan.port$er, col="red", pch=16, cex=2) +#' text(gmin.port$sd, gmin.port$er, labels="GLOBAL MIN", pos=2) +#' text(tan.port$sd, tan.port$er, labels="TANGENCY", pos=2) +#' sr.tan = (tan.port$er - r.free)/tan.port$sd +#' abline(a=r.free, b=sr.tan, col="green", lwd=2) + efficient.frontier <- function(er, cov.mat, nport=20, alpha.min=-0.5, alpha.max=1.5, shorts=TRUE) { @@ -81,4 +145,4 @@ "weights" = we.mat) class(ans) <- "Markowitz" ans -} +} \ No newline at end of file Modified: pkg/IntroCompFinR/R/efficient.portfolio.R =================================================================== --- pkg/IntroCompFinR/R/efficient.portfolio.R 2012-08-29 16:17:36 UTC (rev 6) +++ pkg/IntroCompFinR/R/efficient.portfolio.R 2015-02-16 23:05:59 UTC (rev 7) @@ -1,3 +1,54 @@ +#' @title Compute minimum variance portfolio subject to target return +#' +#' @author Eric Zivot +#' +#' @description +#' Compute minimum variance portfolio subject to target return. +#' +#' @details +#' A mean-variance efficient portfolio \eqn{x} that achieves the target expected return \eqn{\mu_0} +#' solves the optimization problem: min \eqn{t(x)\Sigma x} s.t. \eqn{t(x)1=1} and +#' \eqn{t(x)\mu=\mu_0} +#' +#' @param er N x 1 vector of expected returns +#' @param cov.mat N x N return covariance matrix +#' @param target.return scalar, target expected return +#' @param shorts logical, allow shorts is \code{TRUE} +#' @param object object of class portfolio +#' @param risk.free numeric, risk free rate +#' @param ... controlled variables for \code{plot()}, \code{print()} and \code{summary()} +#' +#' @return +#' \item{call}{captures function call} +#' \item{er}{portfolio expected return} +#' \item{sd}{portfolio standard deviation} +#' \item{weights}{N x 1 vector of portfolio weights} +#' +#' @examples +#' asset.names = c("MSFT", "NORD", "SBUX") +#' er = c(0.0427, 0.0015, 0.0285) +#' names(er) = asset.names +#' covmat = matrix(c(0.0100, 0.0018, 0.0011, +#' 0.0018, 0.0109, 0.0026, +#' 0.0011, 0.0026, 0.0199), +#' nrow=3, ncol=3) +#' r.free = 0.005 +#' dimnames(covmat) = list(asset.names, asset.names) +#' +#' # compute efficient portfolio subject to target return +#' target.return = er["MSFT"] +#' e.port.msft = efficient.portfolio(er, covmat, target.return) +#' e.port.msft +#' summary(e.port.msft, risk.free=r.free) +#' plot(e.port.msft, col="blue") +#' +#' # compute efficient portfolio subject to target return with no short sales +#' target.return = er["MSFT"] +#' e.port.msft.ns = efficient.portfolio(er, covmat, target.return, shorts=FALSE) +#' e.port.msft.ns +#' summary(e.port.msft.ns, risk.free=r.free) +#' plot(e.port.msft.ns, col="blue") + efficient.portfolio <- function(er, cov.mat, target.return, shorts=TRUE) { @@ -64,4 +115,4 @@ "weights" = w) class(ans) <- "portfolio" return(ans) -} +} \ No newline at end of file Modified: pkg/IntroCompFinR/R/getPortfolio.R =================================================================== --- pkg/IntroCompFinR/R/getPortfolio.R 2012-08-29 16:17:36 UTC (rev 6) +++ pkg/IntroCompFinR/R/getPortfolio.R 2015-02-16 23:05:59 UTC (rev 7) @@ -1,3 +1,51 @@ +#' @title Create portfolio object +#' +#' @author Eric Zivot +#' +#' @description +#' Construct the portfolio with expected return vector and covariance matrix. +#' +#' @details +#' To specify a portfolio, an expected return vector and covariance matrix for the assets under +#' consideration as well as a vector of portfolio weights are needed. +#' +#' @param er N x 1 vector of expected returns +#' @param cov.mat N x N return covariance matrix +#' @param weigths N x 1 vector of portfolio weights +#' @param object object of class portfolio +#' @param risk.free numeric, risk free rate +#' @param ... controlled variables for \code{plot()}, \code{print()} and \code{summary()} +#' +#' @return +#' \item{call}{captures function call} +#' \item{er}{portfolio expected return} +#' \item{sd}{portfolio standard deviation} +#' \item{weights}{N x 1 vector of portfolio weights} +#' +#' @examples +#' # Examples from Introduction to Financial Econometrics +#' asset.names = c("MSFT", "NORD", "SBUX") +#' er = c(0.0427, 0.0015, 0.0285) +#' names(er) = asset.names +#' covmat = matrix(c(0.0100, 0.0018, 0.0011, +#' 0.0018, 0.0109, 0.0026, +#' 0.0011, 0.0026, 0.0199), +#' nrow=3, ncol=3) +#' r.free = 0.005 +#' dimnames(covmat) = list(asset.names, asset.names) +#' er +#' covmat +#' r.free +#' +#' # compute equally weighted portfolio +#' ew = rep(1,3)/3 +#' equalWeight.portfolio = getPortfolio(er=er,cov.mat=covmat,weights=ew) +#' class(equalWeight.portfolio) +#' names(equalWeight.portfolio) +#' equalWeight.portfolio +#' summary(equalWeight.portfolio) +#' plot(equalWeight.portfolio, col="blue") + getPortfolio <- function(er, cov.mat, weights) { Modified: pkg/IntroCompFinR/R/globalMin.portfolio.R =================================================================== --- pkg/IntroCompFinR/R/globalMin.portfolio.R 2012-08-29 16:17:36 UTC (rev 6) +++ pkg/IntroCompFinR/R/globalMin.portfolio.R 2015-02-16 23:05:59 UTC (rev 7) @@ -1,3 +1,52 @@ +#' @title Compute global minimum variance portfolio +#' +#' @author Eric Zivot +#' +#' @description +#' Compute global minimum variance portfolio. +#' +#' @details +#' The global minimum variance portfolio (allowing for short sales) \eqn{m} solves the optimization +#' problem: min \eqn{t(m)\Sigma m} s.t. \eqn{t(m)1=1}. +#' +#' @param er N x 1 vector of expected returns +#' @param cov.mat N x N return covariance matrix +#' @param shorts logical, allow shorts is \code{TRUE} +#' @param object object of class portfolio +#' @param risk.free numeric, risk free rate +#' @param ... controlled variables for \code{plot()}, \code{print()} and \code{summary()} +#' +#' @return +#' \item{call}{captures function call} +#' \item{er}{portfolio expected return} +#' \item{sd}{portfolio standard deviation} +#' \item{weights}{N x 1 vector of portfolio weights} +#' +#' @examples +#' asset.names = c("MSFT", "NORD", "SBUX") +#' er = c(0.0427, 0.0015, 0.0285) +#' names(er) = asset.names +#' covmat = matrix(c(0.0100, 0.0018, 0.0011, +#' 0.0018, 0.0109, 0.0026, +#' 0.0011, 0.0026, 0.0199), +#' nrow=3, ncol=3) +#' r.free = 0.005 +#' dimnames(covmat) = list(asset.names, asset.names) +#' +#' # compute global minimum variance portfolio +#' gmin.port = globalMin.portfolio(er, covmat) +#' attributes(gmin.port) +#' print(gmin.port) +#' summary(gmin.port, risk.free=r.free) +#' plot(gmin.port, col="blue") +#' +#' # compute global minimum variance portfolio with no short sales +#' gmin.port.ns = globalMin.portfolio(er, covmat, shorts=FALSE) +#' attributes(gmin.port.ns) +#' print(gmin.port.ns) +#' summary(gmin.port.ns, risk.free=r.free) +#' plot(gmin.port.ns, col="blue") + globalMin.portfolio <- function(er, cov.mat, shorts=TRUE) { @@ -56,4 +105,4 @@ "weights" = w.gmin) class(gmin.port) <- "portfolio" gmin.port -} +} \ No newline at end of file Modified: pkg/IntroCompFinR/R/plot.Markowitz.R =================================================================== --- pkg/IntroCompFinR/R/plot.Markowitz.R 2012-08-29 16:17:36 UTC (rev 6) +++ pkg/IntroCompFinR/R/plot.Markowitz.R 2015-02-16 23:05:59 UTC (rev 7) @@ -1,3 +1,45 @@ +#' @title Plot method of class Markowitz +#' +#' @author Eric Zivot +#' +#' @description +#' Plot efficient frontier. +#' +#' @param object object of class Markowitz +#' @param plot.assets if \code{TRUE} then plot asset \code{sd} and \code{er} +#' @param ... controlled variables for \code{plot()} +#' +#' @examples +#' construct the data +#' asset.names = c("MSFT", "NORD", "SBUX") +#' er = c(0.0427, 0.0015, 0.0285) +#' names(er) = asset.names +#' covmat = matrix(c(0.0100, 0.0018, 0.0011, +#' 0.0018, 0.0109, 0.0026, +#' 0.0011, 0.0026, 0.0199), +#' nrow=3, ncol=3) +#' r.free = 0.005 +#' dimnames(covmat) = list(asset.names, asset.names) +#' +#' # tangency portfolio +#' tan.port <- tangency.portfolio(er, covmat, r.free) +#' # compute global minimum variance portfolio +#' gmin.port = globalMin.portfolio(er, covmat) +#' +#' # compute portfolio frontier +#' ef <- efficient.frontier(er, covmat, alpha.min=-2, +#' alpha.max=1.5, nport=20) +#' attributes(ef) +#' +#' plot(ef) +#' plot(ef, plot.assets=TRUE, col="blue", pch=16) +#' points(gmin.port$sd, gmin.port$er, col="green", pch=16, cex=2) +#' points(tan.port$sd, tan.port$er, col="red", pch=16, cex=2) +#' text(gmin.port$sd, gmin.port$er, labels="GLOBAL MIN", pos=2) +#' text(tan.port$sd, tan.port$er, labels="TANGENCY", pos=2) +#' sr.tan = (tan.port$er - r.free)/tan.port$sd +#' abline(a=r.free, b=sr.tan, col="green", lwd=2) + plot.Markowitz <- function(object, plot.assets=FALSE, ...) # plot.assets logical. If true then plot asset sd and er @@ -21,4 +63,4 @@ text(sd.vals, mu.vals, labels=names(mu.vals)) } invisible() -} +} \ No newline at end of file Modified: pkg/IntroCompFinR/R/plot.portfolio.R =================================================================== --- pkg/IntroCompFinR/R/plot.portfolio.R 2012-08-29 16:17:36 UTC (rev 6) +++ pkg/IntroCompFinR/R/plot.portfolio.R 2015-02-16 23:05:59 UTC (rev 7) @@ -1,3 +1,29 @@ +#' @title Plot method of class portfolio +#' +#' @author Eric Zivot +#' +#' @description +#' The \code{plot()} method shows a bar chart of the portfolio weights. +#' +#' @param object object of class portfolio +#' @param ... controlled variables for \code{barplot()} +#' +#' @examples +#' asset.names = c("MSFT", "NORD", "SBUX") +#' er = c(0.0427, 0.0015, 0.0285) +#' names(er) = asset.names +#' covmat = matrix(c(0.0100, 0.0018, 0.0011, +#' 0.0018, 0.0109, 0.0026, +#' 0.0011, 0.0026, 0.0199), +#' nrow=3, ncol=3) +#' r.free = 0.005 +#' dimnames(covmat) = list(asset.names, asset.names) +#' +#' # compute equally weighted portfolio +#' ew = rep(1,3)/3 +#' equalWeight.portfolio = getPortfolio(er=er,cov.mat=covmat,weights=ew) +#' plot(equalWeight.portfolio, col="blue") + plot.portfolio <- function(object, ...) { Modified: pkg/IntroCompFinR/R/print.Markowitz.R =================================================================== --- pkg/IntroCompFinR/R/print.Markowitz.R 2012-08-29 16:17:36 UTC (rev 6) +++ pkg/IntroCompFinR/R/print.Markowitz.R 2015-02-16 23:05:59 UTC (rev 7) @@ -1,3 +1,36 @@ +#' @title Print efficient frontier +#' +#' @author Eric Zivot +#' +#' @description +#' Print efficient frontier +#' +#' @param object object of class Markowitz +#' @param ... controlled variables for \code{print()} +#' +#' @examples +#' # construct the data +#' asset.names = c("MSFT", "NORD", "SBUX") +#' er = c(0.0427, 0.0015, 0.0285) +#' names(er) = asset.names +#' covmat = matrix(c(0.0100, 0.0018, 0.0011, +#' 0.0018, 0.0109, 0.0026, +#' 0.0011, 0.0026, 0.0199), +#' nrow=3, ncol=3) +#' r.free = 0.005 +#' dimnames(covmat) = list(asset.names, asset.names) +#' +#' # tangency portfolio +#' tan.port <- tangency.portfolio(er, covmat, r.free) +#' # compute global minimum variance portfolio +#' gmin.port = globalMin.portfolio(er, covmat) +#' +#' # compute portfolio frontier +#' ef <- efficient.frontier(er, covmat, alpha.min=-2, +#' alpha.max=1.5, nport=20) +#' attributes(ef) +#' print(ef) + print.Markowitz <- function(object, ...) { @@ -8,4 +41,4 @@ cat("\nFrontier portfolios' expected returns and standard deviations\n") print(round(xx,4), ...) invisible(object) -} +} \ No newline at end of file Modified: pkg/IntroCompFinR/R/print.portfolio.R =================================================================== --- pkg/IntroCompFinR/R/print.portfolio.R 2012-08-29 16:17:36 UTC (rev 6) +++ pkg/IntroCompFinR/R/print.portfolio.R 2015-02-16 23:05:59 UTC (rev 7) @@ -1,3 +1,29 @@ +#' @title Print method of class portfolio +#' +#' @author Eric Zivot +#' +#' @description +#' Print method of class portfolio. +#' +#' @param object object of class portfolio +#' @param ... controlled variables for \code{print()} +#' +#' @examples +#' asset.names = c("MSFT", "NORD", "SBUX") +#' er = c(0.0427, 0.0015, 0.0285) +#' names(er) = asset.names +#' covmat = matrix(c(0.0100, 0.0018, 0.0011, +#' 0.0018, 0.0109, 0.0026, +#' 0.0011, 0.0026, 0.0199), +#' nrow=3, ncol=3) +#' r.free = 0.005 +#' dimnames(covmat) = list(asset.names, asset.names) +#' +#' # compute equally weighted portfolio +#' ew = rep(1,3)/3 +#' equalWeight.portfolio = getPortfolio(er=er,cov.mat=covmat,weights=ew) +#' print(equalWeight.portfolio) + print.portfolio <- function(object, ...) { @@ -8,4 +34,4 @@ cat("Portfolio weights:\n") print(round(object$weights,4), ...) invisible(object) -} +} \ No newline at end of file Modified: pkg/IntroCompFinR/R/summary.Markowitz.R =================================================================== --- pkg/IntroCompFinR/R/summary.Markowitz.R 2012-08-29 16:17:36 UTC (rev 6) +++ pkg/IntroCompFinR/R/summary.Markowitz.R 2015-02-16 23:05:59 UTC (rev 7) @@ -1,3 +1,37 @@ +#' @title Summary method of class Markowitz +#' +#' @author Eric Zivot +#' +#' @description +#' Summary method of efficient frontier function. The weights of the portfolio will be shown. The +#' class \code{summary.Markozitz} will be created. +#' +#' @param object object of class Markowitz +#' @param risk.free numeric, risk free rate +#' +#' @examples +#' construct the data +#' asset.names = c("MSFT", "NORD", "SBUX") +#' er = c(0.0427, 0.0015, 0.0285) +#' names(er) = asset.names +#' covmat = matrix(c(0.0100, 0.0018, 0.0011, +#' 0.0018, 0.0109, 0.0026, +#' 0.0011, 0.0026, 0.0199), +#' nrow=3, ncol=3) +#' r.free = 0.005 +#' dimnames(covmat) = list(asset.names, asset.names) +#' +#' # tangency portfolio +#' tan.port <- tangency.portfolio(er, covmat, r.free) +#' # compute global minimum variance portfolio +#' gmin.port = globalMin.portfolio(er, covmat) +#' +#' # compute portfolio frontier +#' ef <- efficient.frontier(er, covmat, alpha.min=-2, +#' alpha.max=1.5, nport=20) +#' attributes(ef) +#' summary(ef) + summary.Markowitz <- function(object, risk.free=NULL) { @@ -38,4 +72,4 @@ "weights"=we.mat) class(ans) <- "summary.Markowitz" ans -} +} \ No newline at end of file Modified: pkg/IntroCompFinR/R/summary.portfolio.R =================================================================== --- pkg/IntroCompFinR/R/summary.portfolio.R 2012-08-29 16:17:36 UTC (rev 6) +++ pkg/IntroCompFinR/R/summary.portfolio.R 2015-02-16 23:05:59 UTC (rev 7) @@ -1,3 +1,30 @@ +#' @title Summary method of class portfolio +#' +#' @author Eric Zivot +#' +#' @description +#' Summary method of class portfolio. +#' +#' @param object object of class portfolio +#' @param risk.free numeric, risk free rate +#' @param ... controlled variables for \code{summary()} +#' +#' @examples +#' asset.names = c("MSFT", "NORD", "SBUX") +#' er = c(0.0427, 0.0015, 0.0285) +#' names(er) = asset.names +#' covmat = matrix(c(0.0100, 0.0018, 0.0011, +#' 0.0018, 0.0109, 0.0026, +#' 0.0011, 0.0026, 0.0199), +#' nrow=3, ncol=3) +#' r.free = 0.005 +#' dimnames(covmat) = list(asset.names, asset.names) +#' +#' # compute equally weighted portfolio +#' ew = rep(1,3)/3 +#' equalWeight.portfolio = getPortfolio(er=er,cov.mat=covmat,weights=ew) +#' summary(equalWeight.portfolio) + summary.portfolio <- function(object, risk.free=NULL, ...) # risk.free risk-free rate. If not null then @@ -15,4 +42,4 @@ cat("Portfolio weights:\n") print(round(object$weights,4), ...) invisible(object) -} +} \ No newline at end of file Modified: pkg/IntroCompFinR/R/tangency.portfolio.R =================================================================== --- pkg/IntroCompFinR/R/tangency.portfolio.R 2012-08-29 16:17:36 UTC (rev 6) +++ pkg/IntroCompFinR/R/tangency.portfolio.R 2015-02-16 23:05:59 UTC (rev 7) @@ -1,3 +1,51 @@ +#' @title Compute tangency portfolio +#' +#' @author Eric Zivot +#' +#' @description +#' Compute tangency portfolio. +#' +#' @details +#' The tangency portfolio t is the portfolio of risky assets with the highest Sharpe's slope and +#' solves the optimization problem: max \eqn{(t(t)\mu-r_f)/(t(t)\Sigma t^{1/2})} s.t. \eqn{t(t)1=1} +#' where \eqn{r_f} denotes the risk-free rate. +#' +#' @param er N x 1 vector of expected returns +#' @param cov.mat N x N return covariance matrix +#' @param risk.free numeric, risk free rate +#' @param shorts logical, allow shorts is \code{TRUE} +#' @param object object of class Markowitz +#' @param ... controlled variables for \code{plot()}, \code{print()} and \code{summary()} +#' +#' @return +#' \item{call}{captures function call} +#' \item{er}{portfolio expected return} +#' \item{sd}{portfolio standard deviation} +#' \item{weights}{N x 1 vector of portfolio weights} +#' +#' @examples +#' asset.names = c("MSFT", "NORD", "SBUX") +#' er = c(0.0427, 0.0015, 0.0285) +#' names(er) = asset.names +#' covmat = matrix(c(0.0100, 0.0018, 0.0011, +#' 0.0018, 0.0109, 0.0026, +#' 0.0011, 0.0026, 0.0199), +#' nrow=3, ncol=3) +#' r.free = 0.005 +#' dimnames(covmat) = list(asset.names, asset.names) +#' +#' # compute tangency portfolio +#' tan.port <- tangency.portfolio(er, covmat, r.free) +#' tan.port +#' summary(tan.port, risk.free=r.free) +#' plot(tan.port, col="blue") +#' +#' # compute tangency portfolio with no short sales +#' tan.port.ns <- tangency.portfolio(er, covmat, r.free, shorts=FALSE) +#' tan.port.ns +#' summary(tan.port.ns, risk.free=r.free) +#' plot(tan.port.ns, col="blue") + tangency.portfolio <- function(er,cov.mat,risk.free, shorts=TRUE) { Modified: pkg/IntroCompFinR/man/efficient.frontier.Rd =================================================================== --- pkg/IntroCompFinR/man/efficient.frontier.Rd 2012-08-29 16:17:36 UTC (rev 6) +++ pkg/IntroCompFinR/man/efficient.frontier.Rd 2015-02-16 23:05:59 UTC (rev 7) @@ -1,83 +1,60 @@ +% Generated by roxygen2 (4.1.0): do not edit by hand +% Please edit documentation in R/efficient.frontier.R \name{efficient.frontier} \alias{efficient.frontier} -\title{ -Compute efficient frontier. -} -\description{ -The function constructs the set of efficient portfolios using this method for a collection of alpha values. -} +\title{Compute efficient frontier of risky assets} \usage{ -efficient.frontier(er, cov.mat, nport = 20, alpha.min = -0.5, alpha.max = 1.5, shorts = TRUE) -\method{plot}{Markowitz}(object, plot.assets = FALSE, ...) -\method{print}{Markowitz}(object, ...) -\method{summary}{Markowitz}(object, risk.free = NULL) +efficient.frontier(er, cov.mat, nport = 20, alpha.min = -0.5, + alpha.max = 1.5, shorts = TRUE) } -%- maybe also 'usage' for other objects documented here. \arguments{ - \item{er}{ -N x 1 vector of expected returns -} - \item{cov.mat}{ -N x N return covariance matrix -} - \item{nport}{ -scalar, number of efficient portfolios to compute -} - \item{alpha.min}{ -minimum value of alpha, default is -.5 -} - \item{alpha.max}{ -maximum value of alpha, defualt is 1.5 -} - \item{shorts}{ -logical, allow shorts is TRUE -} - \item{object}{ -object of class Markowitz. -} - \item{plot.assets}{ -logical. If true then plot asset sd and er -} - \item{risk.free}{ -Numeric number of risk free rate -} - \item{\dots}{ -controlled variables for \code{plot()} or \code{print()} -} +\item{er}{N x 1 vector of expected returns} +\item{cov.mat}{N x N return covariance matrix} + +\item{nport}{scalar, number of efficient portfolios to compute} + +\item{alpha.min}{minimum value of alpha, default is -.5} + +\item{alpha.max}{maximum value of alpha, defualt is 1.5} + +\item{shorts}{logical, allow shorts is \code{TRUE}} + +\item{object}{object of class Markowitz} + +\item{plot.assets}{logical, if \code{TRUE} then plot asset \code{sd} and \code{er}} + +\item{risk.free}{numeric, risk free rate} + +\item{...}{controlled variables for \code{plot()} or \code{print()}} } -\details{ -The the set of efficient portfolios of risky assets can be computed as a convex combination of any two efficient portfolios. It is convenient to use the global minimum variance portfolio as one portfolio and an efficient portfolio with target expected return equal to the maximum expected return of the assets under consideration as the other portfolio. Call these portfolios m and x, respectively. For any number alpha, -another efficient portfolio can be computed as \eqn{z = \alpha m+ (1 ??? \alpha) x } -} \value{ - \item{call}{ - captures function call - } - \item{er}{ - nport x 1 vector of expected returns on efficient porfolios - } - \item{sd}{ - nport x 1 vector of std deviations on efficient portfolios - } - \item{weights}{ - nport x N matrix of weights on efficient portfolios - } +\item{call}{captures function call} + \item{er}{nport x 1 vector of expected returns on efficient porfolios} + \item{sd}{nport x 1 vector of std deviations on efficient portfolios} + \item{weights}{nport x N matrix of weights on efficient portfolios} } - -\author{ -Eric Zivot +\description{ +The function constructs the set of efficient portfolios using this method (see details) for a +collection of alpha values. } - +\details{ +The the set of efficient portfolios of risky assets can be computed as a convex combination of +any two efficient portfolios. It is convenient to use the global minimum variance portfolio as +one portfolio and an efficient portfolio with target expected return equal to the maximum +expected return of the assets under consideration as the other portfolio. Call these portfolios +\eqn{m} and \eqn{x}, respectively. For any number alpha, another efficient +portfolio can be computed as \eqn{z=\alpha m+(1-\alpha)x}. +} \examples{ # construct the data asset.names = c("MSFT", "NORD", "SBUX") er = c(0.0427, 0.0015, 0.0285) names(er) = asset.names covmat = matrix(c(0.0100, 0.0018, 0.0011, - 0.0018, 0.0109, 0.0026, - 0.0011, 0.0026, 0.0199), - nrow=3, ncol=3) + 0.0018, 0.0109, 0.0026, + 0.0011, 0.0026, 0.0199), + nrow=3, ncol=3) r.free = 0.005 dimnames(covmat) = list(asset.names, asset.names) @@ -86,9 +63,8 @@ # compute global minimum variance portfolio gmin.port = globalMin.portfolio(er, covmat) -# # compute portfolio frontier -ef <- efficient.frontier(er, covmat, alpha.min=-2, +ef <- efficient.frontier(er, covmat, alpha.min=-2, alpha.max=1.5, nport=20) attributes(ef) @@ -97,12 +73,11 @@ points(gmin.port$sd, gmin.port$er, col="green", pch=16, cex=2) points(tan.port$sd, tan.port$er, col="red", pch=16, cex=2) text(gmin.port$sd, gmin.port$er, labels="GLOBAL MIN", pos=2) -text(tan.port$sd, tan.port$er, labels="TANGENCY", pos=2) +text(tan.port$sd, tan.port$er, labels="TANGENCY", pos=2) sr.tan = (tan.port$er - r.free)/tan.port$sd abline(a=r.free, b=sr.tan, col="green", lwd=2) - } -% Add one or more standard keywords, see file 'KEYWORDS' in the -% R documentation directory. -\keyword{ ~kwd1 } -\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line +\author{ +Eric Zivot +} + Modified: pkg/IntroCompFinR/man/efficient.portfolio.Rd =================================================================== --- pkg/IntroCompFinR/man/efficient.portfolio.Rd 2012-08-29 16:17:36 UTC (rev 6) +++ pkg/IntroCompFinR/man/efficient.portfolio.Rd 2015-02-16 23:05:59 UTC (rev 7) @@ -1,80 +1,51 @@ +% Generated by roxygen2 (4.1.0): do not edit by hand +% Please edit documentation in R/efficient.portfolio.R \name{efficient.portfolio} \alias{efficient.portfolio} -\title{ -compute minimum variance portfolio subject to target return -} -\description{ -compute minimum variance portfolio subject to target return -} +\title{Compute minimum variance portfolio subject to target return} \usage{ efficient.portfolio(er, cov.mat, target.return, shorts = TRUE) +} +\arguments{ +\item{er}{N x 1 vector of expected returns} -\method{plot}{portfolio}(object, ...) -\method{print}{portfolio}(object, ...) -\method{summary}{portfolio}(object, risk.free = NULL, ...) +\item{cov.mat}{N x N return covariance matrix} +\item{target.return}{scalar, target expected return} + +\item{shorts}{logical, allow shorts is \code{TRUE}} + +\item{object}{object of class portfolio} + +\item{risk.free}{numeric, risk free rate} + +\item{...}{controlled variables for \code{plot()}, \code{print()} and \code{summary()}} } -%- maybe also 'usage' for other objects documented here. -\arguments{ - \item{er}{ -N x 1 vector of expected returns +\value{ +\item{call}{captures function call} + \item{er}{portfolio expected return} + \item{sd}{portfolio standard deviation} + \item{weights}{N x 1 vector of portfolio weights} } - \item{cov.mat}{ -N x N covariance matrix of returns +\description{ +Compute minimum variance portfolio subject to target return. } - \item{target.return}{ -scalar, target expected return -} - \item{shorts}{ -logical, allow shorts is TRUE -} -\item{object}{ -object of class portfolio -} - \item{risk.free}{ -Numeric, risk free rate. -} - \item{\dots}{ -controlled variables for generic function \code{print},\code{plot} and \code{summary} -} -} \details{ -A mean-variance efficient portfolio x that achieves the target expected return \eqn{\mu_0} -solves the optimization problem: -min \eqn{t(x)\Sigma x} s.t t(x)1 =1 and \eqn{ t(x)\mu = \mu_0} +A mean-variance efficient portfolio \eqn{x} that achieves the target expected return \eqn{\mu_0} +solves the optimization problem: min \eqn{t(x)\Sigma x} s.t. \eqn{t(x)1=1} and +\eqn{t(x)\mu=\mu_0} } -\value{ - \item{call}{ - original function call - } - \item{er}{ - portfolio expected return - } - \item{sd}{ - portfolio standard deviation - } - \item{weights}{ - N x 1 vector of portfolio weights - } -} -\references{ -%% ~put references to the literature/web site here ~ -} -\author{ -Eric Zivot -} - \examples{ asset.names = c("MSFT", "NORD", "SBUX") er = c(0.0427, 0.0015, 0.0285) names(er) = asset.names covmat = matrix(c(0.0100, 0.0018, 0.0011, - 0.0018, 0.0109, 0.0026, - 0.0011, 0.0026, 0.0199), - nrow=3, ncol=3) + 0.0018, 0.0109, 0.0026, + 0.0011, 0.0026, 0.0199), + nrow=3, ncol=3) r.free = 0.005 dimnames(covmat) = list(asset.names, asset.names) -# + # compute efficient portfolio subject to target return target.return = er["MSFT"] e.port.msft = efficient.portfolio(er, covmat, target.return) @@ -82,7 +53,6 @@ summary(e.port.msft, risk.free=r.free) plot(e.port.msft, col="blue") -# # compute efficient portfolio subject to target return with no short sales target.return = er["MSFT"] e.port.msft.ns = efficient.portfolio(er, covmat, target.return, shorts=FALSE) @@ -90,7 +60,7 @@ summary(e.port.msft.ns, risk.free=r.free) plot(e.port.msft.ns, col="blue") } -% Add one or more standard keywords, see file 'KEYWORDS' in the -% R documentation directory. -\keyword{ ~kwd1 } -\keyword{ ~kwd2 }% __ONLY ONE__ keyword per line +\author{ +Eric Zivot +} + Modified: pkg/IntroCompFinR/man/getPortfolio.Rd =================================================================== --- pkg/IntroCompFinR/man/getPortfolio.Rd 2012-08-29 16:17:36 UTC (rev 6) +++ pkg/IntroCompFinR/man/getPortfolio.Rd 2015-02-16 23:05:59 UTC (rev 7) @@ -1,80 +1,52 @@ +% Generated by roxygen2 (4.1.0): do not edit by hand +% Please edit documentation in R/getPortfolio.R \name{getPortfolio} \alias{getPortfolio} -\title{ -create portfolio object -} -\description{ -Construct the portfolio with expected return vector and covariance matrix. -} +\title{Create portfolio object} \usage{ getPortfolio(er, cov.mat, weights) +} +\arguments{ +\item{er}{N x 1 vector of expected returns} -\method{plot}{portfolio}(object, ...) -\method{print}{portfolio}(object, ...) -\method{summary}{portfolio}(object, risk.free = NULL, ...) +\item{cov.mat}{N x N return covariance matrix} +\item{weigths}{N x 1 vector of portfolio weights} + +\item{object}{object of class portfolio} + +\item{risk.free}{numeric, risk free rate} + +\item{...}{controlled variables for \code{plot()}, \code{print()} and \code{summary()}} } -%- maybe also 'usage' for other objects documented here. -\arguments{ - \item{er}{ -N x 1 vector of expected returns -} - \item{cov.mat}{ -N x N covariance matrix of returns -} - \item{weights}{ -N x 1 vector of portfolio weights -} - \item{object}{ -object of class portfolio -} - \item{risk.free}{ -Numeric, risk free rate. -} - \item{\dots}{ -controlled variables for generic function \code{print},\code{plot} and \code{summary} -} -} \value{ - \item{call}{ -The function call. +\item{call}{captures function call} + \item{er}{portfolio expected return} + \item{sd}{portfolio standard deviation} + \item{weights}{N x 1 vector of portfolio weights} } - \item{er}{ -Portfolio expected return. -} - \item{sd}{ -Portfolio standard deviation. -} - \item{weights}{ -Portfolio weights. +\description{ [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/introcompfinr -r 7 From noreply at r-forge.r-project.org Tue Feb 17 18:49:36 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 17 Feb 2015 18:49:36 +0100 (CET) Subject: [Introcompfinr-commits] r8 - in pkg/IntroCompFinR: R man Message-ID: <20150217174936.6D8D3187654@r-forge.r-project.org> Author: bethanyyollin Date: 2015-02-17 18:49:35 +0100 (Tue, 17 Feb 2015) New Revision: 8 Modified: pkg/IntroCompFinR/R/plot.Markowitz.R pkg/IntroCompFinR/R/summary.Markowitz.R pkg/IntroCompFinR/man/plot.Markowitz.Rd pkg/IntroCompFinR/man/summary.Markowitz.Rd Log: Fixed minor error in examples; missing '#'. Modified: pkg/IntroCompFinR/R/plot.Markowitz.R =================================================================== --- pkg/IntroCompFinR/R/plot.Markowitz.R 2015-02-16 23:05:59 UTC (rev 7) +++ pkg/IntroCompFinR/R/plot.Markowitz.R 2015-02-17 17:49:35 UTC (rev 8) @@ -10,7 +10,7 @@ #' @param ... controlled variables for \code{plot()} #' #' @examples -#' construct the data +#' # construct the data #' asset.names = c("MSFT", "NORD", "SBUX") #' er = c(0.0427, 0.0015, 0.0285) #' names(er) = asset.names Modified: pkg/IntroCompFinR/R/summary.Markowitz.R =================================================================== --- pkg/IntroCompFinR/R/summary.Markowitz.R 2015-02-16 23:05:59 UTC (rev 7) +++ pkg/IntroCompFinR/R/summary.Markowitz.R 2015-02-17 17:49:35 UTC (rev 8) @@ -10,7 +10,7 @@ #' @param risk.free numeric, risk free rate #' #' @examples -#' construct the data +#' # construct the data #' asset.names = c("MSFT", "NORD", "SBUX") #' er = c(0.0427, 0.0015, 0.0285) #' names(er) = asset.names Modified: pkg/IntroCompFinR/man/plot.Markowitz.Rd =================================================================== --- pkg/IntroCompFinR/man/plot.Markowitz.Rd 2015-02-16 23:05:59 UTC (rev 7) +++ pkg/IntroCompFinR/man/plot.Markowitz.Rd 2015-02-17 17:49:35 UTC (rev 8) @@ -17,7 +17,7 @@ Plot efficient frontier. } \examples{ -construct the data +# construct the data asset.names = c("MSFT", "NORD", "SBUX") er = c(0.0427, 0.0015, 0.0285) names(er) = asset.names Modified: pkg/IntroCompFinR/man/summary.Markowitz.Rd =================================================================== --- pkg/IntroCompFinR/man/summary.Markowitz.Rd 2015-02-16 23:05:59 UTC (rev 7) +++ pkg/IntroCompFinR/man/summary.Markowitz.Rd 2015-02-17 17:49:35 UTC (rev 8) @@ -16,7 +16,7 @@ class \code{summary.Markozitz} will be created. } \examples{ -construct the data +# construct the data asset.names = c("MSFT", "NORD", "SBUX") er = c(0.0427, 0.0015, 0.0285) names(er) = asset.names From noreply at r-forge.r-project.org Wed Feb 18 22:02:26 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 18 Feb 2015 22:02:26 +0100 (CET) Subject: [Introcompfinr-commits] r9 - in pkg/IntroCompFinR: . R man Message-ID: <20150218210226.154641876E8@r-forge.r-project.org> Author: bethanyyollin Date: 2015-02-18 22:02:25 +0100 (Wed, 18 Feb 2015) New Revision: 9 Modified: pkg/IntroCompFinR/NAMESPACE pkg/IntroCompFinR/R/efficient.frontier.R pkg/IntroCompFinR/R/efficient.portfolio.R pkg/IntroCompFinR/R/getPortfolio.R pkg/IntroCompFinR/R/globalMin.portfolio.R pkg/IntroCompFinR/R/plot.Markowitz.R pkg/IntroCompFinR/R/plot.portfolio.R pkg/IntroCompFinR/R/print.Markowitz.R pkg/IntroCompFinR/R/print.portfolio.R pkg/IntroCompFinR/R/summary.Markowitz.R pkg/IntroCompFinR/R/summary.portfolio.R pkg/IntroCompFinR/R/tangency.portfolio.R pkg/IntroCompFinR/man/efficient.frontier.Rd pkg/IntroCompFinR/man/efficient.portfolio.Rd pkg/IntroCompFinR/man/getPortfolio.Rd pkg/IntroCompFinR/man/globalMin.portfolio.Rd pkg/IntroCompFinR/man/plot.Markowitz.Rd pkg/IntroCompFinR/man/plot.portfolio.Rd pkg/IntroCompFinR/man/print.Markowitz.Rd pkg/IntroCompFinR/man/print.portfolio.Rd pkg/IntroCompFinR/man/summary.portfolio.Rd pkg/IntroCompFinR/man/tangency.portfolio.Rd Log: Constructed NAMESPACE with Roxygen. Standardized comments in examples and source code. Eliminated extraneous arguments listed in some of the documentation. Modified: pkg/IntroCompFinR/NAMESPACE =================================================================== --- pkg/IntroCompFinR/NAMESPACE 2015-02-17 17:49:35 UTC (rev 8) +++ pkg/IntroCompFinR/NAMESPACE 2015-02-18 21:02:25 UTC (rev 9) @@ -1,2 +1,13 @@ +# Generated by roxygen2 (4.1.0): do not edit by hand -export(efficient.frontier,efficient.portfolio,getPortfolio,globalMin.portfolio,plot.Markowitz,plot.portfolio,print.Markowitz,print.portfolio,summary.Markowitz,summary.portfolio,tangency.portfolio) +export(efficient.frontier) +export(efficient.portfolio) +export(getPortfolio) +export(globalMin.portfolio) +export(plot.Markowitz) +export(plot.portfolio) +export(print.Markowitz) +export(print.portfolio) +export(summary.Markowitz) +export(summary.portfolio) +export(tangency.portfolio) Modified: pkg/IntroCompFinR/R/efficient.frontier.R =================================================================== --- pkg/IntroCompFinR/R/efficient.frontier.R 2015-02-17 17:49:35 UTC (rev 8) +++ pkg/IntroCompFinR/R/efficient.frontier.R 2015-02-18 21:02:25 UTC (rev 9) @@ -12,7 +12,7 @@ #' one portfolio and an efficient portfolio with target expected return equal to the maximum #' expected return of the assets under consideration as the other portfolio. Call these portfolios #' \eqn{m} and \eqn{x}, respectively. For any number alpha, another efficient -#' portfolio can be computed as \eqn{z=\alpha m+(1-\alpha)x}. +#' portfolio can be computed as \eqn{z=\alpha m+(1-\alpha)x} #' #' @param er N x 1 vector of expected returns #' @param cov.mat N x N return covariance matrix @@ -20,10 +20,6 @@ #' @param alpha.min minimum value of alpha, default is -.5 #' @param alpha.max maximum value of alpha, defualt is 1.5 #' @param shorts logical, allow shorts is \code{TRUE} -#' @param object object of class Markowitz -#' @param plot.assets logical, if \code{TRUE} then plot asset \code{sd} and \code{er} -#' @param risk.free numeric, risk free rate -#' @param ... controlled variables for \code{plot()} or \code{print()} #' #' @return #' \item{call}{captures function call} @@ -61,23 +57,12 @@ #' text(tan.port$sd, tan.port$er, labels="TANGENCY", pos=2) #' sr.tan = (tan.port$er - r.free)/tan.port$sd #' abline(a=r.free, b=sr.tan, col="green", lwd=2) +#' +#' @export efficient.frontier efficient.frontier <- function(er, cov.mat, nport=20, alpha.min=-0.5, alpha.max=1.5, shorts=TRUE) { - # Compute efficient frontier with no short-sales constraints - # - # inputs: - # er N x 1 vector of expected returns - # cov.mat N x N return covariance matrix - # nport scalar, number of efficient portfolios to compute - # shorts logical, allow shorts is TRUE - # - # output is a Markowitz object with the following elements - # call captures function call - # er nport x 1 vector of expected returns on efficient porfolios - # sd nport x 1 vector of std deviations on efficient portfolios - # weights nport x N matrix of weights on efficient portfolios call <- match.call() # @@ -114,9 +99,9 @@ er.max <- max(er) port.max <- efficient.portfolio(er,cov.mat,er.max) w.max <- port.max$weights - a <- seq(from=alpha.min,to=alpha.max,length=nport) # convex combinations - we.mat <- a %o% w.gmin + (1-a) %o% w.max # rows are efficient portfolios - er.e <- we.mat %*% er # expected returns of efficient portfolios + a <- seq(from=alpha.min,to=alpha.max,length=nport) # convex combinations + we.mat <- a %o% w.gmin + (1-a) %o% w.max # rows are efficient portfolios + er.e <- we.mat %*% er # expected returns of efficient portfolios er.e <- as.vector(er.e) } else if(shorts==FALSE){ we.mat <- matrix(0, nrow=nport, ncol=N) @@ -131,7 +116,7 @@ names(er.e) <- port.names cov.e <- we.mat %*% cov.mat %*% t(we.mat) # cov mat of efficient portfolios - sd.e <- sqrt(diag(cov.e)) # std devs of efficient portfolios + sd.e <- sqrt(diag(cov.e)) # std devs of efficient portfolios sd.e <- as.vector(sd.e) names(sd.e) <- port.names dimnames(we.mat) <- list(port.names,asset.names) Modified: pkg/IntroCompFinR/R/efficient.portfolio.R =================================================================== --- pkg/IntroCompFinR/R/efficient.portfolio.R 2015-02-17 17:49:35 UTC (rev 8) +++ pkg/IntroCompFinR/R/efficient.portfolio.R 2015-02-18 21:02:25 UTC (rev 9) @@ -14,9 +14,6 @@ #' @param cov.mat N x N return covariance matrix #' @param target.return scalar, target expected return #' @param shorts logical, allow shorts is \code{TRUE} -#' @param object object of class portfolio -#' @param risk.free numeric, risk free rate -#' @param ... controlled variables for \code{plot()}, \code{print()} and \code{summary()} #' #' @return #' \item{call}{captures function call} @@ -25,6 +22,7 @@ #' \item{weights}{N x 1 vector of portfolio weights} #' #' @examples +#' # construct the data #' asset.names = c("MSFT", "NORD", "SBUX") #' er = c(0.0427, 0.0015, 0.0285) #' names(er) = asset.names @@ -48,31 +46,19 @@ #' e.port.msft.ns #' summary(e.port.msft.ns, risk.free=r.free) #' plot(e.port.msft.ns, col="blue") +#' +#' @export efficient.portfolio efficient.portfolio <- function(er, cov.mat, target.return, shorts=TRUE) { - # compute minimum variance portfolio subject to target return - # - # inputs: - # er N x 1 vector of expected returns - # cov.mat N x N covariance matrix of returns - # target.return scalar, target expected return - # shorts logical, allow shorts is TRUE - # - # output is portfolio object with the following elements - # call original function call - # er portfolio expected return - # sd portfolio standard deviation - # weights N x 1 vector of portfolio weights - # call <- match.call() # # check for valid inputs # asset.names <- names(er) - er <- as.vector(er) # assign names if none exist + er <- as.vector(er) # assign names if none exist N <- length(er) cov.mat <- as.matrix(cov.mat) if(N != nrow(cov.mat)) Modified: pkg/IntroCompFinR/R/getPortfolio.R =================================================================== --- pkg/IntroCompFinR/R/getPortfolio.R 2015-02-17 17:49:35 UTC (rev 8) +++ pkg/IntroCompFinR/R/getPortfolio.R 2015-02-18 21:02:25 UTC (rev 9) @@ -11,10 +11,7 @@ #' #' @param er N x 1 vector of expected returns #' @param cov.mat N x N return covariance matrix -#' @param weigths N x 1 vector of portfolio weights -#' @param object object of class portfolio -#' @param risk.free numeric, risk free rate -#' @param ... controlled variables for \code{plot()}, \code{print()} and \code{summary()} +#' @param weights N x 1 vector of portfolio weights #' #' @return #' \item{call}{captures function call} @@ -23,7 +20,7 @@ #' \item{weights}{N x 1 vector of portfolio weights} #' #' @examples -#' # Examples from Introduction to Financial Econometrics +#' # construct the data #' asset.names = c("MSFT", "NORD", "SBUX") #' er = c(0.0427, 0.0015, 0.0285) #' names(er) = asset.names @@ -45,23 +42,12 @@ #' equalWeight.portfolio #' summary(equalWeight.portfolio) #' plot(equalWeight.portfolio, col="blue") +#' +#' @export getPortfolio getPortfolio <- function(er, cov.mat, weights) { - # contruct portfolio object - # - # inputs: - # er N x 1 vector of expected returns - # cov.mat N x N covariance matrix of returns - # weights N x 1 vector of portfolio weights - # - # output is portfolio object with the following elements - # call original function call - # er portfolio expected return - # sd portfolio standard deviation - # weights N x 1 vector of portfolio weights - # call <- match.call() # @@ -70,7 +56,7 @@ asset.names <- names(er) weights <- as.vector(weights) names(weights) = names(er) - er <- as.vector(er) # assign names if none exist + er <- as.vector(er) # assign names if none exist if(length(er) != length(weights)) stop("dimensions of er and weights do not match") cov.mat <- as.matrix(cov.mat) @@ -90,4 +76,4 @@ "weights" = weights) class(ans) <- "portfolio" return(ans) -} +} \ No newline at end of file Modified: pkg/IntroCompFinR/R/globalMin.portfolio.R =================================================================== --- pkg/IntroCompFinR/R/globalMin.portfolio.R 2015-02-17 17:49:35 UTC (rev 8) +++ pkg/IntroCompFinR/R/globalMin.portfolio.R 2015-02-18 21:02:25 UTC (rev 9) @@ -12,9 +12,6 @@ #' @param er N x 1 vector of expected returns #' @param cov.mat N x N return covariance matrix #' @param shorts logical, allow shorts is \code{TRUE} -#' @param object object of class portfolio -#' @param risk.free numeric, risk free rate -#' @param ... controlled variables for \code{plot()}, \code{print()} and \code{summary()} #' #' @return #' \item{call}{captures function call} @@ -23,6 +20,7 @@ #' \item{weights}{N x 1 vector of portfolio weights} #' #' @examples +#' # construct the data #' asset.names = c("MSFT", "NORD", "SBUX") #' er = c(0.0427, 0.0015, 0.0285) #' names(er) = asset.names @@ -46,29 +44,19 @@ #' print(gmin.port.ns) #' summary(gmin.port.ns, risk.free=r.free) #' plot(gmin.port.ns, col="blue") +#' +#' @export globalMin.portfolio globalMin.portfolio <- function(er, cov.mat, shorts=TRUE) { - # Compute global minimum variance portfolio - # - # inputs: - # er N x 1 vector of expected returns - # cov.mat N x N return covariance matrix - # shorts logical, allow shorts is TRUE - # - # output is portfolio object with the following elements - # call original function call - # er portfolio expected return - # sd portfolio standard deviation - # weights N x 1 vector of portfolio weights call <- match.call() # # check for valid inputs # asset.names <- names(er) - er <- as.vector(er) # assign names if none exist + er <- as.vector(er) # assign names if none exist cov.mat <- as.matrix(cov.mat) N <- length(er) if(N != nrow(cov.mat)) Modified: pkg/IntroCompFinR/R/plot.Markowitz.R =================================================================== --- pkg/IntroCompFinR/R/plot.Markowitz.R 2015-02-17 17:49:35 UTC (rev 8) +++ pkg/IntroCompFinR/R/plot.Markowitz.R 2015-02-18 21:02:25 UTC (rev 9) @@ -7,7 +7,7 @@ #' #' @param object object of class Markowitz #' @param plot.assets if \code{TRUE} then plot asset \code{sd} and \code{er} -#' @param ... controlled variables for \code{plot()} +#' @param ... additional arguments passed to \code{plot()} #' #' @examples #' # construct the data @@ -39,10 +39,11 @@ #' text(tan.port$sd, tan.port$er, labels="TANGENCY", pos=2) #' sr.tan = (tan.port$er - r.free)/tan.port$sd #' abline(a=r.free, b=sr.tan, col="green", lwd=2) +#' +#' @export plot.Markowitz plot.Markowitz <- function(object, plot.assets=FALSE, ...) -# plot.assets logical. If true then plot asset sd and er { if (!plot.assets) { y.lim=c(0,max(object$er)) Modified: pkg/IntroCompFinR/R/plot.portfolio.R =================================================================== --- pkg/IntroCompFinR/R/plot.portfolio.R 2015-02-17 17:49:35 UTC (rev 8) +++ pkg/IntroCompFinR/R/plot.portfolio.R 2015-02-18 21:02:25 UTC (rev 9) @@ -6,9 +6,10 @@ #' The \code{plot()} method shows a bar chart of the portfolio weights. #' #' @param object object of class portfolio -#' @param ... controlled variables for \code{barplot()} +#' @param ... additional arguments passed to \code{barplot()} #' #' @examples +#' # construct the data #' asset.names = c("MSFT", "NORD", "SBUX") #' er = c(0.0427, 0.0015, 0.0285) #' names(er) = asset.names @@ -23,6 +24,8 @@ #' ew = rep(1,3)/3 #' equalWeight.portfolio = getPortfolio(er=er,cov.mat=covmat,weights=ew) #' plot(equalWeight.portfolio, col="blue") +#' +#' @export plot.portfolio plot.portfolio <- function(object, ...) @@ -31,4 +34,4 @@ barplot(object$weights, names=asset.names, xlab="Assets", ylab="Weight", main="Portfolio Weights", ...) invisible() -} +} \ No newline at end of file Modified: pkg/IntroCompFinR/R/print.Markowitz.R =================================================================== --- pkg/IntroCompFinR/R/print.Markowitz.R 2015-02-17 17:49:35 UTC (rev 8) +++ pkg/IntroCompFinR/R/print.Markowitz.R 2015-02-18 21:02:25 UTC (rev 9) @@ -6,7 +6,7 @@ #' Print efficient frontier #' #' @param object object of class Markowitz -#' @param ... controlled variables for \code{print()} +#' @param ... additional arguments passed to \code{print()} #' #' @examples #' # construct the data @@ -30,6 +30,8 @@ #' alpha.max=1.5, nport=20) #' attributes(ef) #' print(ef) +#' +#' @export print.Markowitz print.Markowitz <- function(object, ...) Modified: pkg/IntroCompFinR/R/print.portfolio.R =================================================================== --- pkg/IntroCompFinR/R/print.portfolio.R 2015-02-17 17:49:35 UTC (rev 8) +++ pkg/IntroCompFinR/R/print.portfolio.R 2015-02-18 21:02:25 UTC (rev 9) @@ -6,9 +6,10 @@ #' Print method of class portfolio. #' #' @param object object of class portfolio -#' @param ... controlled variables for \code{print()} +#' @param ... additional arguments passed to \code{print()} #' #' @examples +#' # construct the data #' asset.names = c("MSFT", "NORD", "SBUX") #' er = c(0.0427, 0.0015, 0.0285) #' names(er) = asset.names @@ -23,6 +24,8 @@ #' ew = rep(1,3)/3 #' equalWeight.portfolio = getPortfolio(er=er,cov.mat=covmat,weights=ew) #' print(equalWeight.portfolio) +#' +#' @export print.portfolio print.portfolio <- function(object, ...) Modified: pkg/IntroCompFinR/R/summary.Markowitz.R =================================================================== --- pkg/IntroCompFinR/R/summary.Markowitz.R 2015-02-17 17:49:35 UTC (rev 8) +++ pkg/IntroCompFinR/R/summary.Markowitz.R 2015-02-18 21:02:25 UTC (rev 9) @@ -31,6 +31,8 @@ #' alpha.max=1.5, nport=20) #' attributes(ef) #' summary(ef) +#' +#' @export summary.Markowitz summary.Markowitz <- function(object, risk.free=NULL) @@ -53,11 +55,11 @@ # # compute tangency portfolio tan.port <- tangency.portfolio(er,cov.mat,risk.free) - x.t <- sd.e/tan.port$sd # weights in tangency port - rf <- 1 - x.t # weights in t-bills + x.t <- sd.e/tan.port$sd # weights in tangency port + rf <- 1 - x.t # weights in t-bills er.e <- risk.free + x.t*(tan.port$er - risk.free) names(er.e) <- port.names - we.mat <- x.t %o% tan.port$weights # rows are efficient portfolios + we.mat <- x.t %o% tan.port$weights # rows are efficient portfolios dimnames(we.mat) <- list(port.names, asset.names) we.mat <- cbind(rf,we.mat) } Modified: pkg/IntroCompFinR/R/summary.portfolio.R =================================================================== --- pkg/IntroCompFinR/R/summary.portfolio.R 2015-02-17 17:49:35 UTC (rev 8) +++ pkg/IntroCompFinR/R/summary.portfolio.R 2015-02-18 21:02:25 UTC (rev 9) @@ -7,9 +7,10 @@ #' #' @param object object of class portfolio #' @param risk.free numeric, risk free rate -#' @param ... controlled variables for \code{summary()} +#' @param ... additional arguments passed to \code{summary()} #' #' @examples +#' # construct the data #' asset.names = c("MSFT", "NORD", "SBUX") #' er = c(0.0427, 0.0015, 0.0285) #' names(er) = asset.names @@ -24,12 +25,11 @@ #' ew = rep(1,3)/3 #' equalWeight.portfolio = getPortfolio(er=er,cov.mat=covmat,weights=ew) #' summary(equalWeight.portfolio) +#' +#' @export summary.portfolio summary.portfolio <- function(object, risk.free=NULL, ...) -# risk.free risk-free rate. If not null then -# compute and print Sharpe ratio -# { cat("Call:\n") print(object$call) Modified: pkg/IntroCompFinR/R/tangency.portfolio.R =================================================================== --- pkg/IntroCompFinR/R/tangency.portfolio.R 2015-02-17 17:49:35 UTC (rev 8) +++ pkg/IntroCompFinR/R/tangency.portfolio.R 2015-02-18 21:02:25 UTC (rev 9) @@ -14,8 +14,6 @@ #' @param cov.mat N x N return covariance matrix #' @param risk.free numeric, risk free rate #' @param shorts logical, allow shorts is \code{TRUE} -#' @param object object of class Markowitz -#' @param ... controlled variables for \code{plot()}, \code{print()} and \code{summary()} #' #' @return #' \item{call}{captures function call} @@ -24,6 +22,7 @@ #' \item{weights}{N x 1 vector of portfolio weights} #' #' @examples +#' # construct the data #' asset.names = c("MSFT", "NORD", "SBUX") #' er = c(0.0427, 0.0015, 0.0285) #' names(er) = asset.names @@ -45,23 +44,12 @@ #' tan.port.ns #' summary(tan.port.ns, risk.free=r.free) #' plot(tan.port.ns, col="blue") +#' +#' @export tangency.portfolio tangency.portfolio <- function(er,cov.mat,risk.free, shorts=TRUE) { - # compute tangency portfolio - # - # inputs: - # er N x 1 vector of expected returns - # cov.mat N x N return covariance matrix - # risk.free scalar, risk-free rate - # shorts logical, allow shorts is TRUE - # - # output is portfolio object with the following elements - # call captures function call - # er portfolio expected return - # sd portfolio standard deviation - # weights N x 1 vector of portfolio weights call <- match.call() # @@ -92,7 +80,7 @@ if(shorts==TRUE){ cov.mat.inv <- solve(cov.mat) w.t <- cov.mat.inv %*% (er - risk.free) # tangency portfolio - w.t <- as.vector(w.t/sum(w.t)) # normalize weights + w.t <- as.vector(w.t/sum(w.t)) # normalize weights } else if(shorts==FALSE){ Dmat <- 2*cov.mat dvec <- rep.int(0, N) @@ -114,4 +102,4 @@ "weights" = w.t) class(tan.port) <- "portfolio" return(tan.port) -} +} \ No newline at end of file Modified: pkg/IntroCompFinR/man/efficient.frontier.Rd =================================================================== --- pkg/IntroCompFinR/man/efficient.frontier.Rd 2015-02-17 17:49:35 UTC (rev 8) +++ pkg/IntroCompFinR/man/efficient.frontier.Rd 2015-02-18 21:02:25 UTC (rev 9) @@ -19,14 +19,6 @@ \item{alpha.max}{maximum value of alpha, defualt is 1.5} \item{shorts}{logical, allow shorts is \code{TRUE}} - -\item{object}{object of class Markowitz} - -\item{plot.assets}{logical, if \code{TRUE} then plot asset \code{sd} and \code{er}} - -\item{risk.free}{numeric, risk free rate} - -\item{...}{controlled variables for \code{plot()} or \code{print()}} } \value{ \item{call}{captures function call} @@ -44,7 +36,7 @@ one portfolio and an efficient portfolio with target expected return equal to the maximum expected return of the assets under consideration as the other portfolio. Call these portfolios \eqn{m} and \eqn{x}, respectively. For any number alpha, another efficient -portfolio can be computed as \eqn{z=\alpha m+(1-\alpha)x}. +portfolio can be computed as \eqn{z=\alpha m+(1-\alpha)x} } \examples{ # construct the data Modified: pkg/IntroCompFinR/man/efficient.portfolio.Rd =================================================================== --- pkg/IntroCompFinR/man/efficient.portfolio.Rd 2015-02-17 17:49:35 UTC (rev 8) +++ pkg/IntroCompFinR/man/efficient.portfolio.Rd 2015-02-18 21:02:25 UTC (rev 9) @@ -14,12 +14,6 @@ \item{target.return}{scalar, target expected return} \item{shorts}{logical, allow shorts is \code{TRUE}} - -\item{object}{object of class portfolio} - -\item{risk.free}{numeric, risk free rate} - -\item{...}{controlled variables for \code{plot()}, \code{print()} and \code{summary()}} } \value{ \item{call}{captures function call} @@ -36,6 +30,7 @@ \eqn{t(x)\mu=\mu_0} } \examples{ +# construct the data asset.names = c("MSFT", "NORD", "SBUX") er = c(0.0427, 0.0015, 0.0285) names(er) = asset.names Modified: pkg/IntroCompFinR/man/getPortfolio.Rd =================================================================== --- pkg/IntroCompFinR/man/getPortfolio.Rd 2015-02-17 17:49:35 UTC (rev 8) +++ pkg/IntroCompFinR/man/getPortfolio.Rd 2015-02-18 21:02:25 UTC (rev 9) @@ -11,13 +11,7 @@ \item{cov.mat}{N x N return covariance matrix} -\item{weigths}{N x 1 vector of portfolio weights} - -\item{object}{object of class portfolio} - -\item{risk.free}{numeric, risk free rate} - -\item{...}{controlled variables for \code{plot()}, \code{print()} and \code{summary()}} +\item{weights}{N x 1 vector of portfolio weights} } \value{ \item{call}{captures function call} @@ -33,7 +27,7 @@ consideration as well as a vector of portfolio weights are needed. } \examples{ -# Examples from Introduction to Financial Econometrics +# construct the data asset.names = c("MSFT", "NORD", "SBUX") er = c(0.0427, 0.0015, 0.0285) names(er) = asset.names Modified: pkg/IntroCompFinR/man/globalMin.portfolio.Rd =================================================================== --- pkg/IntroCompFinR/man/globalMin.portfolio.Rd 2015-02-17 17:49:35 UTC (rev 8) +++ pkg/IntroCompFinR/man/globalMin.portfolio.Rd 2015-02-18 21:02:25 UTC (rev 9) @@ -12,12 +12,6 @@ \item{cov.mat}{N x N return covariance matrix} \item{shorts}{logical, allow shorts is \code{TRUE}} - -\item{object}{object of class portfolio} - -\item{risk.free}{numeric, risk free rate} - -\item{...}{controlled variables for \code{plot()}, \code{print()} and \code{summary()}} } \value{ \item{call}{captures function call} @@ -33,6 +27,7 @@ problem: min \eqn{t(m)\Sigma m} s.t. \eqn{t(m)1=1}. } \examples{ +# construct the data asset.names = c("MSFT", "NORD", "SBUX") er = c(0.0427, 0.0015, 0.0285) names(er) = asset.names Modified: pkg/IntroCompFinR/man/plot.Markowitz.Rd =================================================================== --- pkg/IntroCompFinR/man/plot.Markowitz.Rd 2015-02-17 17:49:35 UTC (rev 8) +++ pkg/IntroCompFinR/man/plot.Markowitz.Rd 2015-02-18 21:02:25 UTC (rev 9) @@ -11,7 +11,7 @@ \item{plot.assets}{if \code{TRUE} then plot asset \code{sd} and \code{er}} -\item{...}{controlled variables for \code{plot()}} +\item{...}{additional arguments passed to \code{plot()}} } \description{ Plot efficient frontier. Modified: pkg/IntroCompFinR/man/plot.portfolio.Rd =================================================================== --- pkg/IntroCompFinR/man/plot.portfolio.Rd 2015-02-17 17:49:35 UTC (rev 8) +++ pkg/IntroCompFinR/man/plot.portfolio.Rd 2015-02-18 21:02:25 UTC (rev 9) @@ -9,12 +9,13 @@ \arguments{ \item{object}{object of class portfolio} -\item{...}{controlled variables for \code{barplot()}} +\item{...}{additional arguments passed to \code{barplot()}} } \description{ The \code{plot()} method shows a bar chart of the portfolio weights. } \examples{ +# construct the data asset.names = c("MSFT", "NORD", "SBUX") er = c(0.0427, 0.0015, 0.0285) names(er) = asset.names Modified: pkg/IntroCompFinR/man/print.Markowitz.Rd =================================================================== --- pkg/IntroCompFinR/man/print.Markowitz.Rd 2015-02-17 17:49:35 UTC (rev 8) +++ pkg/IntroCompFinR/man/print.Markowitz.Rd 2015-02-18 21:02:25 UTC (rev 9) @@ -9,7 +9,7 @@ \arguments{ \item{object}{object of class Markowitz} -\item{...}{controlled variables for \code{print()}} +\item{...}{additional arguments passed to \code{print()}} } \description{ Print efficient frontier Modified: pkg/IntroCompFinR/man/print.portfolio.Rd =================================================================== --- pkg/IntroCompFinR/man/print.portfolio.Rd 2015-02-17 17:49:35 UTC (rev 8) +++ pkg/IntroCompFinR/man/print.portfolio.Rd 2015-02-18 21:02:25 UTC (rev 9) @@ -9,12 +9,13 @@ \arguments{ \item{object}{object of class portfolio} -\item{...}{controlled variables for \code{print()}} +\item{...}{additional arguments passed to \code{print()}} } \description{ Print method of class portfolio. } \examples{ +# construct the data asset.names = c("MSFT", "NORD", "SBUX") er = c(0.0427, 0.0015, 0.0285) names(er) = asset.names Modified: pkg/IntroCompFinR/man/summary.portfolio.Rd =================================================================== --- pkg/IntroCompFinR/man/summary.portfolio.Rd 2015-02-17 17:49:35 UTC (rev 8) +++ pkg/IntroCompFinR/man/summary.portfolio.Rd 2015-02-18 21:02:25 UTC (rev 9) @@ -11,12 +11,13 @@ \item{risk.free}{numeric, risk free rate} -\item{...}{controlled variables for \code{summary()}} +\item{...}{additional arguments passed to \code{summary()}} } \description{ Summary method of class portfolio. } \examples{ +# construct the data asset.names = c("MSFT", "NORD", "SBUX") er = c(0.0427, 0.0015, 0.0285) names(er) = asset.names Modified: pkg/IntroCompFinR/man/tangency.portfolio.Rd =================================================================== --- pkg/IntroCompFinR/man/tangency.portfolio.Rd 2015-02-17 17:49:35 UTC (rev 8) +++ pkg/IntroCompFinR/man/tangency.portfolio.Rd 2015-02-18 21:02:25 UTC (rev 9) @@ -14,10 +14,6 @@ \item{risk.free}{numeric, risk free rate} \item{shorts}{logical, allow shorts is \code{TRUE}} - -\item{object}{object of class Markowitz} - -\item{...}{controlled variables for \code{plot()}, \code{print()} and \code{summary()}} } \value{ \item{call}{captures function call} @@ -34,6 +30,7 @@ where \eqn{r_f} denotes the risk-free rate. } \examples{ +# construct the data asset.names = c("MSFT", "NORD", "SBUX") er = c(0.0427, 0.0015, 0.0285) names(er) = asset.names From noreply at r-forge.r-project.org Thu Feb 19 20:06:06 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 19 Feb 2015 20:06:06 +0100 (CET) Subject: [Introcompfinr-commits] r10 - / Message-ID: <20150219190606.5E0FC186F19@r-forge.r-project.org> Author: bethanyyollin Date: 2015-02-19 20:06:05 +0100 (Thu, 19 Feb 2015) New Revision: 10 Added: text.R Log: Testing commits mailing list. Added: text.R =================================================================== --- text.R (rev 0) +++ text.R 2015-02-19 19:06:05 UTC (rev 10) @@ -0,0 +1 @@ +print("Hello world!") \ No newline at end of file From noreply at r-forge.r-project.org Fri Feb 20 01:32:34 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 20 Feb 2015 01:32:34 +0100 (CET) Subject: [Introcompfinr-commits] r11 - / pkg/IntroCompFinR/R pkg/IntroCompFinR/man Message-ID: <20150220003234.ED52C18727C@r-forge.r-project.org> Author: bethanyyollin Date: 2015-02-20 01:32:34 +0100 (Fri, 20 Feb 2015) New Revision: 11 Removed: text.R Modified: pkg/IntroCompFinR/R/efficient.frontier.R pkg/IntroCompFinR/R/efficient.portfolio.R pkg/IntroCompFinR/R/getPortfolio.R pkg/IntroCompFinR/R/globalMin.portfolio.R pkg/IntroCompFinR/R/plot.Markowitz.R pkg/IntroCompFinR/R/print.Markowitz.R pkg/IntroCompFinR/R/print.portfolio.R pkg/IntroCompFinR/R/summary.Markowitz.R pkg/IntroCompFinR/R/summary.portfolio.R pkg/IntroCompFinR/R/tangency.portfolio.R pkg/IntroCompFinR/man/efficient.frontier.Rd pkg/IntroCompFinR/man/efficient.portfolio.Rd pkg/IntroCompFinR/man/getPortfolio.Rd pkg/IntroCompFinR/man/globalMin.portfolio.Rd pkg/IntroCompFinR/man/plot.Markowitz.Rd pkg/IntroCompFinR/man/print.Markowitz.Rd pkg/IntroCompFinR/man/print.portfolio.Rd pkg/IntroCompFinR/man/summary.Markowitz.Rd pkg/IntroCompFinR/man/summary.portfolio.Rd pkg/IntroCompFinR/man/tangency.portfolio.Rd Log: Improved documentation. Modified: pkg/IntroCompFinR/R/efficient.frontier.R =================================================================== --- pkg/IntroCompFinR/R/efficient.frontier.R 2015-02-19 19:06:05 UTC (rev 10) +++ pkg/IntroCompFinR/R/efficient.frontier.R 2015-02-20 00:32:34 UTC (rev 11) @@ -3,29 +3,37 @@ #' @author Eric Zivot #' #' @description -#' The function constructs the set of efficient portfolios using this method (see details) for a -#' collection of alpha values. +#' The function constructs the set of mean-variance efficient portfolios that either allow all assets to be +#' sold short or not allow any asset to be sold short. The returned object is of class \samp{Markowitz} for +#' which there are \code{print}, \code{summary} and \code{plot} methods. #' #' @details -#' The the set of efficient portfolios of risky assets can be computed as a convex combination of +#' If short sales are allowed (negative weights) then the set of efficient portfolios of risky assets +#' can be computed as a convex combination of #' any two efficient portfolios. It is convenient to use the global minimum variance portfolio as #' one portfolio and an efficient portfolio with target expected return equal to the maximum #' expected return of the assets under consideration as the other portfolio. Call these portfolios -#' \eqn{m} and \eqn{x}, respectively. For any number alpha, another efficient -#' portfolio can be computed as \eqn{z=\alpha m+(1-\alpha)x} +#' \eqn{m} and \eqn{x}, respectively. Then for any number \samp{alpha}, another efficient +#' portfolio can be computed as \eqn{z=\alpha m+(1-\alpha)x}. If short sales are not allowed, then the set +#' of efficient portfolios is computed by repeated calls to the function \code{efficient.portfolio()}, +#' with \code{shorts=FALSE}, for a +#' grid of target expected returns starting at the expected return of the global minimum variance portfolio +#' (not allowing short sales) and ending at the expected return equal to the maximum expected return of +#' the assets under consideration. #' -#' @param er N x 1 vector of expected returns -#' @param cov.mat N x N return covariance matrix +#' @param er \samp{N x 1} vector of expected returns +#' @param cov.mat \samp{N x N} return covariance matrix #' @param nport scalar, number of efficient portfolios to compute -#' @param alpha.min minimum value of alpha, default is -.5 -#' @param alpha.max maximum value of alpha, defualt is 1.5 -#' @param shorts logical, allow shorts is \code{TRUE} +#' @param alpha.min minimum value of \samp{alpha}, default is \code{-.5} +#' @param alpha.max maximum value of \samp{alpha}, default is \code{1.5} +#' @param shorts logical, if \code{TRUE} then short sales (negative portfolio weights) +#' are allowed. If \code{FALSE} then no asset is allowed to be sold short #' #' @return #' \item{call}{captures function call} -#' \item{er}{nport x 1 vector of expected returns on efficient porfolios} -#' \item{sd}{nport x 1 vector of std deviations on efficient portfolios} -#' \item{weights}{nport x N matrix of weights on efficient portfolios} +#' \item{er}{\samp{nport x 1} vector of expected returns of efficient porfolios} +#' \item{sd}{\samp{nport x 1} vector of standard deviations of efficient portfolios} +#' \item{weights}{\samp{nport x N} matrix of weights of efficient portfolios} #' #' @examples #' # construct the data Modified: pkg/IntroCompFinR/R/efficient.portfolio.R =================================================================== --- pkg/IntroCompFinR/R/efficient.portfolio.R 2015-02-19 19:06:05 UTC (rev 10) +++ pkg/IntroCompFinR/R/efficient.portfolio.R 2015-02-20 00:32:34 UTC (rev 11) @@ -3,23 +3,29 @@ #' @author Eric Zivot #' #' @description -#' Compute minimum variance portfolio subject to target return. +#' Compute minimum variance portfolio subject to target return either allowing all assets +#' to be sold short or not allowing any asset to be sold short. The returned object is +#' of class \samp{portfolio}. #' #' @details -#' A mean-variance efficient portfolio \eqn{x} that achieves the target expected return \eqn{\mu_0} +#' A mean-variance efficient portfolio \eqn{x} allowing short sales (negative weights) +#' that achieves the target expected return \eqn{\mu_0} #' solves the optimization problem: min \eqn{t(x)\Sigma x} s.t. \eqn{t(x)1=1} and -#' \eqn{t(x)\mu=\mu_0} +#' \eqn{t(x)\mu=\mu_0}, for which there is an analytic solution using matrix algebra. +#' If short sales are not allowed then the portfolio is computed numerically using the +#' function \code{solve.QP()} from the \samp{quadprog} package. #' -#' @param er N x 1 vector of expected returns -#' @param cov.mat N x N return covariance matrix +#' @param er \samp{N x 1} vector of expected returns +#' @param cov.mat \samp{N x N} return covariance matrix #' @param target.return scalar, target expected return -#' @param shorts logical, allow shorts is \code{TRUE} +#' @param shorts logical, if \code{TRUE} then short sales (negative portfolio weights) +#' are allowed. If \code{FALSE} then no asset is allowed to be sold short. #' #' @return #' \item{call}{captures function call} #' \item{er}{portfolio expected return} #' \item{sd}{portfolio standard deviation} -#' \item{weights}{N x 1 vector of portfolio weights} +#' \item{weights}{\samp{N x 1} vector of portfolio weights} #' #' @examples #' # construct the data Modified: pkg/IntroCompFinR/R/getPortfolio.R =================================================================== --- pkg/IntroCompFinR/R/getPortfolio.R 2015-02-19 19:06:05 UTC (rev 10) +++ pkg/IntroCompFinR/R/getPortfolio.R 2015-02-20 00:32:34 UTC (rev 11) @@ -3,21 +3,24 @@ #' @author Eric Zivot #' #' @description -#' Construct the portfolio with expected return vector and covariance matrix. +#' Create a portfolio object from expected return vector, covariance matrix, and weight vector. #' #' @details #' To specify a portfolio, an expected return vector and covariance matrix for the assets under -#' consideration as well as a vector of portfolio weights are needed. +#' consideration as well as a vector of portfolio weights are needed. The result of \code{getPortfolio} +#' is a \samp{portfolio} object, which is list with components for the portfolio expected return, +#' portfolio standard deviation, and portfolio weights. There are \code{print}, \code{summary} and \code{plot} +#' methods. #' -#' @param er N x 1 vector of expected returns -#' @param cov.mat N x N return covariance matrix -#' @param weights N x 1 vector of portfolio weights +#' @param er \samp{N x 1} vector of expected returns +#' @param cov.mat \samp{N x N} return covariance matrix +#' @param weights \samp{N x 1} vector of portfolio weights #' #' @return #' \item{call}{captures function call} #' \item{er}{portfolio expected return} #' \item{sd}{portfolio standard deviation} -#' \item{weights}{N x 1 vector of portfolio weights} +#' \item{weights}{\samp{N x 1} vector of portfolio weights} #' #' @examples #' # construct the data Modified: pkg/IntroCompFinR/R/globalMin.portfolio.R =================================================================== --- pkg/IntroCompFinR/R/globalMin.portfolio.R 2015-02-19 19:06:05 UTC (rev 10) +++ pkg/IntroCompFinR/R/globalMin.portfolio.R 2015-02-20 00:32:34 UTC (rev 11) @@ -3,21 +3,27 @@ #' @author Eric Zivot #' #' @description -#' Compute global minimum variance portfolio. +#' Compute global minimum variance portfolio given expected return vector and +#' covariance matrix. The portfolio can allow all assets to be shorted +#' or not allow any assets to be shorted. The returned object is of class \samp{portfolio}. #' #' @details -#' The global minimum variance portfolio (allowing for short sales) \eqn{m} solves the optimization -#' problem: min \eqn{t(m)\Sigma m} s.t. \eqn{t(m)1=1}. +#' The global minimum variance portfolio \eqn{m} allowing for short sales solves the optimization +#' problem: min \eqn{t(m)\Sigma m} s.t. \eqn{t(m)1=1} for which there is an analytic solution +#' using matrix algebra. If short sales are not allowed +#' then the portfolio is computed numerically using the function \code{solve.QP()} +#' from the \samp{quadprog} package. #' -#' @param er N x 1 vector of expected returns -#' @param cov.mat N x N return covariance matrix -#' @param shorts logical, allow shorts is \code{TRUE} +#' @param er \samp{N x 1} vector of expected returns +#' @param cov.mat \samp{N x N} return covariance matrix +#' @param shorts logical, if \code{TRUE} then short sales (negative portfolio weights) +#' are allowed. If \code{FALSE} then no asset is allowed to be sold short. #' #' @return #' \item{call}{captures function call} #' \item{er}{portfolio expected return} #' \item{sd}{portfolio standard deviation} -#' \item{weights}{N x 1 vector of portfolio weights} +#' \item{weights}{\samp{N x 1} vector of portfolio weights} #' #' @examples #' # construct the data Modified: pkg/IntroCompFinR/R/plot.Markowitz.R =================================================================== --- pkg/IntroCompFinR/R/plot.Markowitz.R 2015-02-19 19:06:05 UTC (rev 10) +++ pkg/IntroCompFinR/R/plot.Markowitz.R 2015-02-20 00:32:34 UTC (rev 11) @@ -3,10 +3,12 @@ #' @author Eric Zivot #' #' @description -#' Plot efficient frontier. +#' Plot efficient frontier. The efficient frontier is a plot of portfolio expected return vs. portfolio +#' standard deviation for a collection of mean-variance efficient portfolios - portfolios that minimize vriance +#' subject to a target expected return. #' #' @param object object of class Markowitz -#' @param plot.assets if \code{TRUE} then plot asset \code{sd} and \code{er} +#' @param plot.assets if \code{TRUE} then plot asset \code{sd} and \code{er} with asset name labels #' @param ... additional arguments passed to \code{plot()} #' #' @examples Modified: pkg/IntroCompFinR/R/print.Markowitz.R =================================================================== --- pkg/IntroCompFinR/R/print.Markowitz.R 2015-02-19 19:06:05 UTC (rev 10) +++ pkg/IntroCompFinR/R/print.Markowitz.R 2015-02-20 00:32:34 UTC (rev 11) @@ -3,7 +3,7 @@ #' @author Eric Zivot #' #' @description -#' Print efficient frontier +#' Print method for \samp{Markowitz} objects. #' #' @param object object of class Markowitz #' @param ... additional arguments passed to \code{print()} Modified: pkg/IntroCompFinR/R/print.portfolio.R =================================================================== --- pkg/IntroCompFinR/R/print.portfolio.R 2015-02-19 19:06:05 UTC (rev 10) +++ pkg/IntroCompFinR/R/print.portfolio.R 2015-02-20 00:32:34 UTC (rev 11) @@ -3,7 +3,7 @@ #' @author Eric Zivot #' #' @description -#' Print method of class portfolio. +#' Print method for objects of class \samp{portfolio}. #' #' @param object object of class portfolio #' @param ... additional arguments passed to \code{print()} Modified: pkg/IntroCompFinR/R/summary.Markowitz.R =================================================================== --- pkg/IntroCompFinR/R/summary.Markowitz.R 2015-02-19 19:06:05 UTC (rev 10) +++ pkg/IntroCompFinR/R/summary.Markowitz.R 2015-02-20 00:32:34 UTC (rev 11) @@ -3,7 +3,9 @@ #' @author Eric Zivot #' #' @description -#' Summary method of efficient frontier function. The weights of the portfolio will be shown. The +#' Summary method for objects of class \samp{Markowitz}. For all portfolios on the efficient frontier, +#' the expected return, standard deviation and asset weights are shown. If \code{risk.free} is given then +#' efficient portfolios that are combinations of the risk free asset and the tangency portfolio are computed. The #' class \code{summary.Markozitz} will be created. #' #' @param object object of class Markowitz Modified: pkg/IntroCompFinR/R/summary.portfolio.R =================================================================== --- pkg/IntroCompFinR/R/summary.portfolio.R 2015-02-19 19:06:05 UTC (rev 10) +++ pkg/IntroCompFinR/R/summary.portfolio.R 2015-02-20 00:32:34 UTC (rev 11) @@ -3,7 +3,9 @@ #' @author Eric Zivot #' #' @description -#' Summary method of class portfolio. +#' Summary method for objects of class \samp{portfolio}. The output is the same +#' as the \code{print}. If \code{risk.free} is specified then the portfolio Sharpe +#' ratio is also returned. #' #' @param object object of class portfolio #' @param risk.free numeric, risk free rate Modified: pkg/IntroCompFinR/R/tangency.portfolio.R =================================================================== --- pkg/IntroCompFinR/R/tangency.portfolio.R 2015-02-19 19:06:05 UTC (rev 10) +++ pkg/IntroCompFinR/R/tangency.portfolio.R 2015-02-20 00:32:34 UTC (rev 11) @@ -3,23 +3,27 @@ #' @author Eric Zivot #' #' @description -#' Compute tangency portfolio. +#' Compute tangency (maximum Sharpe ratio) portfolio. The portfolio can allow all assets to be shorted +#' or not allow any assets to be shorted. #' #' @details -#' The tangency portfolio t is the portfolio of risky assets with the highest Sharpe's slope and +#' The tangency portfolio \samp{t} is the portfolio of risky assets with the highest Sharpe's slope and #' solves the optimization problem: max \eqn{(t(t)\mu-r_f)/(t(t)\Sigma t^{1/2})} s.t. \eqn{t(t)1=1} -#' where \eqn{r_f} denotes the risk-free rate. +#' where \eqn{r_f} denotes the risk-free rate. If short sales are allowed then there is an analytic +#' solution using matrix algebra. If short sales are not allowed then the maximum sharpe ratio portfolio must +#' be computed numerically. #' -#' @param er N x 1 vector of expected returns -#' @param cov.mat N x N return covariance matrix +#' @param er \samp{N x 1} vector of expected returns +#' @param cov.mat \samp{N x N} return covariance matrix #' @param risk.free numeric, risk free rate -#' @param shorts logical, allow shorts is \code{TRUE} +#' @param shorts logical, if \code{TRUE} then short sales (negative portfolio weights) +#' are allowed. If \code{FALSE} then no asset is allowed to be sold short. #' #' @return #' \item{call}{captures function call} #' \item{er}{portfolio expected return} #' \item{sd}{portfolio standard deviation} -#' \item{weights}{N x 1 vector of portfolio weights} +#' \item{weights}{\samp{N x 1} vector of portfolio weights} #' #' @examples #' # construct the data Modified: pkg/IntroCompFinR/man/efficient.frontier.Rd =================================================================== --- pkg/IntroCompFinR/man/efficient.frontier.Rd 2015-02-19 19:06:05 UTC (rev 10) +++ pkg/IntroCompFinR/man/efficient.frontier.Rd 2015-02-20 00:32:34 UTC (rev 11) @@ -8,35 +8,43 @@ alpha.max = 1.5, shorts = TRUE) } \arguments{ -\item{er}{N x 1 vector of expected returns} +\item{er}{\samp{N x 1} vector of expected returns} -\item{cov.mat}{N x N return covariance matrix} +\item{cov.mat}{\samp{N x N} return covariance matrix} \item{nport}{scalar, number of efficient portfolios to compute} -\item{alpha.min}{minimum value of alpha, default is -.5} +\item{alpha.min}{minimum value of \samp{alpha}, default is \code{-.5}} -\item{alpha.max}{maximum value of alpha, defualt is 1.5} +\item{alpha.max}{maximum value of \samp{alpha}, default is \code{1.5}} -\item{shorts}{logical, allow shorts is \code{TRUE}} +\item{shorts}{logical, if \code{TRUE} then short sales (negative portfolio weights) +are allowed. If \code{FALSE} then no asset is allowed to be sold short} } \value{ \item{call}{captures function call} - \item{er}{nport x 1 vector of expected returns on efficient porfolios} - \item{sd}{nport x 1 vector of std deviations on efficient portfolios} - \item{weights}{nport x N matrix of weights on efficient portfolios} + \item{er}{\samp{nport x 1} vector of expected returns of efficient porfolios} + \item{sd}{\samp{nport x 1} vector of standard deviations of efficient portfolios} + \item{weights}{\samp{nport x N} matrix of weights of efficient portfolios} } \description{ -The function constructs the set of efficient portfolios using this method (see details) for a -collection of alpha values. +The function constructs the set of mean-variance efficient portfolios that either allow all assets to be +sold short or not allow any asset to be sold short. The returned object is of class \samp{Markowitz} for +which there are \code{print}, \code{summary} and \code{plot} methods. } \details{ -The the set of efficient portfolios of risky assets can be computed as a convex combination of +If short sales are allowed (negative weights) then the set of efficient portfolios of risky assets +can be computed as a convex combination of any two efficient portfolios. It is convenient to use the global minimum variance portfolio as one portfolio and an efficient portfolio with target expected return equal to the maximum expected return of the assets under consideration as the other portfolio. Call these portfolios -\eqn{m} and \eqn{x}, respectively. For any number alpha, another efficient -portfolio can be computed as \eqn{z=\alpha m+(1-\alpha)x} +\eqn{m} and \eqn{x}, respectively. Then for any number \samp{alpha}, another efficient +portfolio can be computed as \eqn{z=\alpha m+(1-\alpha)x}. If short sales are not allowed, then the set +of efficient portfolios is computed by repeated calls to the function \code{efficient.portfolio()}, +with \code{shorts=FALSE}, for a +grid of target expected returns starting at the expected return of the global minimum variance portfolio +(not allowing short sales) and ending at the expected return equal to the maximum expected return of +the assets under consideration. } \examples{ # construct the data Modified: pkg/IntroCompFinR/man/efficient.portfolio.Rd =================================================================== --- pkg/IntroCompFinR/man/efficient.portfolio.Rd 2015-02-19 19:06:05 UTC (rev 10) +++ pkg/IntroCompFinR/man/efficient.portfolio.Rd 2015-02-20 00:32:34 UTC (rev 11) @@ -7,27 +7,33 @@ efficient.portfolio(er, cov.mat, target.return, shorts = TRUE) } \arguments{ -\item{er}{N x 1 vector of expected returns} +\item{er}{\samp{N x 1} vector of expected returns} -\item{cov.mat}{N x N return covariance matrix} +\item{cov.mat}{\samp{N x N} return covariance matrix} \item{target.return}{scalar, target expected return} -\item{shorts}{logical, allow shorts is \code{TRUE}} +\item{shorts}{logical, if \code{TRUE} then short sales (negative portfolio weights) +are allowed. If \code{FALSE} then no asset is allowed to be sold short.} } \value{ \item{call}{captures function call} \item{er}{portfolio expected return} \item{sd}{portfolio standard deviation} - \item{weights}{N x 1 vector of portfolio weights} + \item{weights}{\samp{N x 1} vector of portfolio weights} } \description{ -Compute minimum variance portfolio subject to target return. +Compute minimum variance portfolio subject to target return either allowing all assets +to be sold short or not allowing any asset to be sold short. The returned object is +of class \samp{portfolio}. } \details{ -A mean-variance efficient portfolio \eqn{x} that achieves the target expected return \eqn{\mu_0} +A mean-variance efficient portfolio \eqn{x} allowing short sales (negative weights) +that achieves the target expected return \eqn{\mu_0} solves the optimization problem: min \eqn{t(x)\Sigma x} s.t. \eqn{t(x)1=1} and -\eqn{t(x)\mu=\mu_0} +\eqn{t(x)\mu=\mu_0}, for which there is an analytic solution using matrix algebra. +If short sales are not allowed then the portfolio is computed numerically using the +function \code{solve.QP()} from the \samp{quadprog} package. } \examples{ # construct the data Modified: pkg/IntroCompFinR/man/getPortfolio.Rd =================================================================== --- pkg/IntroCompFinR/man/getPortfolio.Rd 2015-02-19 19:06:05 UTC (rev 10) +++ pkg/IntroCompFinR/man/getPortfolio.Rd 2015-02-20 00:32:34 UTC (rev 11) @@ -7,24 +7,27 @@ getPortfolio(er, cov.mat, weights) } \arguments{ -\item{er}{N x 1 vector of expected returns} +\item{er}{\samp{N x 1} vector of expected returns} -\item{cov.mat}{N x N return covariance matrix} +\item{cov.mat}{\samp{N x N} return covariance matrix} -\item{weights}{N x 1 vector of portfolio weights} +\item{weights}{\samp{N x 1} vector of portfolio weights} } \value{ \item{call}{captures function call} \item{er}{portfolio expected return} \item{sd}{portfolio standard deviation} - \item{weights}{N x 1 vector of portfolio weights} + \item{weights}{\samp{N x 1} vector of portfolio weights} } \description{ -Construct the portfolio with expected return vector and covariance matrix. +Create a portfolio object from expected return vector, covariance matrix, and weight vector. } \details{ To specify a portfolio, an expected return vector and covariance matrix for the assets under -consideration as well as a vector of portfolio weights are needed. +consideration as well as a vector of portfolio weights are needed. The result of \code{getPortfolio} +is a \samp{portfolio} object, which is list with components for the portfolio expected return, +portfolio standard deviation, and portfolio weights. There are \code{print}, \code{summary} and \code{plot} +methods. } \examples{ # construct the data Modified: pkg/IntroCompFinR/man/globalMin.portfolio.Rd =================================================================== --- pkg/IntroCompFinR/man/globalMin.portfolio.Rd 2015-02-19 19:06:05 UTC (rev 10) +++ pkg/IntroCompFinR/man/globalMin.portfolio.Rd 2015-02-20 00:32:34 UTC (rev 11) @@ -7,24 +7,30 @@ globalMin.portfolio(er, cov.mat, shorts = TRUE) } \arguments{ -\item{er}{N x 1 vector of expected returns} +\item{er}{\samp{N x 1} vector of expected returns} -\item{cov.mat}{N x N return covariance matrix} +\item{cov.mat}{\samp{N x N} return covariance matrix} -\item{shorts}{logical, allow shorts is \code{TRUE}} +\item{shorts}{logical, if \code{TRUE} then short sales (negative portfolio weights) +are allowed. If \code{FALSE} then no asset is allowed to be sold short.} } \value{ \item{call}{captures function call} \item{er}{portfolio expected return} \item{sd}{portfolio standard deviation} - \item{weights}{N x 1 vector of portfolio weights} + \item{weights}{\samp{N x 1} vector of portfolio weights} } \description{ -Compute global minimum variance portfolio. +Compute global minimum variance portfolio given expected return vector and +covariance matrix. The portfolio can allow all assets to be shorted +or not allow any assets to be shorted. The returned object is of class \samp{portfolio}. } \details{ -The global minimum variance portfolio (allowing for short sales) \eqn{m} solves the optimization -problem: min \eqn{t(m)\Sigma m} s.t. \eqn{t(m)1=1}. +The global minimum variance portfolio \eqn{m} allowing for short sales solves the optimization +problem: min \eqn{t(m)\Sigma m} s.t. \eqn{t(m)1=1} for which there is an analytic solution +using matrix algebra. If short sales are not allowed +then the portfolio is computed numerically using the function \code{solve.QP()} +from the \samp{quadprog} package. } \examples{ # construct the data Modified: pkg/IntroCompFinR/man/plot.Markowitz.Rd =================================================================== --- pkg/IntroCompFinR/man/plot.Markowitz.Rd 2015-02-19 19:06:05 UTC (rev 10) +++ pkg/IntroCompFinR/man/plot.Markowitz.Rd 2015-02-20 00:32:34 UTC (rev 11) @@ -9,12 +9,14 @@ \arguments{ \item{object}{object of class Markowitz} -\item{plot.assets}{if \code{TRUE} then plot asset \code{sd} and \code{er}} +\item{plot.assets}{if \code{TRUE} then plot asset \code{sd} and \code{er} with asset name labels} \item{...}{additional arguments passed to \code{plot()}} } \description{ -Plot efficient frontier. +Plot efficient frontier. The efficient frontier is a plot of portfolio expected return vs. portfolio +standard deviation for a collection of mean-variance efficient portfolios - portfolios that minimize vriance +subject to a target expected return. } \examples{ # construct the data Modified: pkg/IntroCompFinR/man/print.Markowitz.Rd =================================================================== --- pkg/IntroCompFinR/man/print.Markowitz.Rd 2015-02-19 19:06:05 UTC (rev 10) +++ pkg/IntroCompFinR/man/print.Markowitz.Rd 2015-02-20 00:32:34 UTC (rev 11) @@ -12,7 +12,7 @@ \item{...}{additional arguments passed to \code{print()}} } \description{ -Print efficient frontier +Print method for \samp{Markowitz} objects. } \examples{ # construct the data Modified: pkg/IntroCompFinR/man/print.portfolio.Rd =================================================================== --- pkg/IntroCompFinR/man/print.portfolio.Rd 2015-02-19 19:06:05 UTC (rev 10) +++ pkg/IntroCompFinR/man/print.portfolio.Rd 2015-02-20 00:32:34 UTC (rev 11) @@ -12,7 +12,7 @@ \item{...}{additional arguments passed to \code{print()}} } \description{ -Print method of class portfolio. +Print method for objects of class \samp{portfolio}. } \examples{ # construct the data Modified: pkg/IntroCompFinR/man/summary.Markowitz.Rd =================================================================== --- pkg/IntroCompFinR/man/summary.Markowitz.Rd 2015-02-19 19:06:05 UTC (rev 10) +++ pkg/IntroCompFinR/man/summary.Markowitz.Rd 2015-02-20 00:32:34 UTC (rev 11) @@ -12,7 +12,9 @@ \item{risk.free}{numeric, risk free rate} } \description{ -Summary method of efficient frontier function. The weights of the portfolio will be shown. The +Summary method for objects of class \samp{Markowitz}. For all portfolios on the efficient frontier, +the expected return, standard deviation and asset weights are shown. If \code{risk.free} is given then +efficient portfolios that are combinations of the risk free asset and the tangency portfolio are computed. The class \code{summary.Markozitz} will be created. } \examples{ Modified: pkg/IntroCompFinR/man/summary.portfolio.Rd =================================================================== --- pkg/IntroCompFinR/man/summary.portfolio.Rd 2015-02-19 19:06:05 UTC (rev 10) +++ pkg/IntroCompFinR/man/summary.portfolio.Rd 2015-02-20 00:32:34 UTC (rev 11) @@ -14,7 +14,9 @@ \item{...}{additional arguments passed to \code{summary()}} } \description{ -Summary method of class portfolio. +Summary method for objects of class \samp{portfolio}. The output is the same +as the \code{print}. If \code{risk.free} is specified then the portfolio Sharpe +ratio is also returned. } \examples{ # construct the data Modified: pkg/IntroCompFinR/man/tangency.portfolio.Rd =================================================================== --- pkg/IntroCompFinR/man/tangency.portfolio.Rd 2015-02-19 19:06:05 UTC (rev 10) +++ pkg/IntroCompFinR/man/tangency.portfolio.Rd 2015-02-20 00:32:34 UTC (rev 11) @@ -7,27 +7,31 @@ tangency.portfolio(er, cov.mat, risk.free, shorts = TRUE) } \arguments{ -\item{er}{N x 1 vector of expected returns} +\item{er}{\samp{N x 1} vector of expected returns} -\item{cov.mat}{N x N return covariance matrix} +\item{cov.mat}{\samp{N x N} return covariance matrix} \item{risk.free}{numeric, risk free rate} -\item{shorts}{logical, allow shorts is \code{TRUE}} +\item{shorts}{logical, if \code{TRUE} then short sales (negative portfolio weights) +are allowed. If \code{FALSE} then no asset is allowed to be sold short.} } \value{ \item{call}{captures function call} \item{er}{portfolio expected return} \item{sd}{portfolio standard deviation} - \item{weights}{N x 1 vector of portfolio weights} + \item{weights}{\samp{N x 1} vector of portfolio weights} } \description{ -Compute tangency portfolio. +Compute tangency (maximum Sharpe ratio) portfolio. The portfolio can allow all assets to be shorted +or not allow any assets to be shorted. } \details{ -The tangency portfolio t is the portfolio of risky assets with the highest Sharpe's slope and +The tangency portfolio \samp{t} is the portfolio of risky assets with the highest Sharpe's slope and solves the optimization problem: max \eqn{(t(t)\mu-r_f)/(t(t)\Sigma t^{1/2})} s.t. \eqn{t(t)1=1} -where \eqn{r_f} denotes the risk-free rate. +where \eqn{r_f} denotes the risk-free rate. If short sales are allowed then there is an analytic +solution using matrix algebra. If short sales are not allowed then the maximum sharpe ratio portfolio must +be computed numerically. } \examples{ # construct the data Deleted: text.R =================================================================== --- text.R 2015-02-19 19:06:05 UTC (rev 10) +++ text.R 2015-02-20 00:32:34 UTC (rev 11) @@ -1 +0,0 @@ -print("Hello world!") \ No newline at end of file From noreply at r-forge.r-project.org Fri Feb 20 07:59:09 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 20 Feb 2015 07:59:09 +0100 (CET) Subject: [Introcompfinr-commits] r12 - in pkg/IntroCompFinR: R man Message-ID: <20150220065909.A04B2185763@r-forge.r-project.org> Author: bethanyyollin Date: 2015-02-20 07:59:09 +0100 (Fri, 20 Feb 2015) New Revision: 12 Modified: pkg/IntroCompFinR/R/efficient.frontier.R pkg/IntroCompFinR/R/efficient.portfolio.R pkg/IntroCompFinR/R/getPortfolio.R pkg/IntroCompFinR/R/globalMin.portfolio.R pkg/IntroCompFinR/R/plot.Markowitz.R pkg/IntroCompFinR/R/plot.portfolio.R pkg/IntroCompFinR/R/print.Markowitz.R pkg/IntroCompFinR/R/print.portfolio.R pkg/IntroCompFinR/R/summary.Markowitz.R pkg/IntroCompFinR/R/summary.portfolio.R pkg/IntroCompFinR/R/tangency.portfolio.R pkg/IntroCompFinR/man/efficient.frontier.Rd pkg/IntroCompFinR/man/efficient.portfolio.Rd pkg/IntroCompFinR/man/getPortfolio.Rd pkg/IntroCompFinR/man/globalMin.portfolio.Rd pkg/IntroCompFinR/man/plot.Markowitz.Rd pkg/IntroCompFinR/man/plot.portfolio.Rd pkg/IntroCompFinR/man/print.Markowitz.Rd pkg/IntroCompFinR/man/print.portfolio.Rd pkg/IntroCompFinR/man/summary.Markowitz.Rd pkg/IntroCompFinR/man/summary.portfolio.Rd pkg/IntroCompFinR/man/tangency.portfolio.Rd Log: Misc. improvements to documentation. Modified: pkg/IntroCompFinR/R/efficient.frontier.R =================================================================== --- pkg/IntroCompFinR/R/efficient.frontier.R 2015-02-20 00:32:34 UTC (rev 11) +++ pkg/IntroCompFinR/R/efficient.frontier.R 2015-02-20 06:59:09 UTC (rev 12) @@ -3,31 +3,30 @@ #' @author Eric Zivot #' #' @description -#' The function constructs the set of mean-variance efficient portfolios that either allow all assets to be -#' sold short or not allow any asset to be sold short. The returned object is of class \samp{Markowitz} for -#' which there are \code{print}, \code{summary} and \code{plot} methods. +#' The function constructs the set of mean-variance efficient portfolios that either allow all +#' assets to be sold short or not allow any asset to be sold short. The returned object is of class +#' \samp{Markowitz} for which there are \samp{print}, \samp{summary} and \samp{plot} methods. #' #' @details -#' If short sales are allowed (negative weights) then the set of efficient portfolios of risky assets -#' can be computed as a convex combination of -#' any two efficient portfolios. It is convenient to use the global minimum variance portfolio as -#' one portfolio and an efficient portfolio with target expected return equal to the maximum -#' expected return of the assets under consideration as the other portfolio. Call these portfolios -#' \eqn{m} and \eqn{x}, respectively. Then for any number \samp{alpha}, another efficient -#' portfolio can be computed as \eqn{z=\alpha m+(1-\alpha)x}. If short sales are not allowed, then the set -#' of efficient portfolios is computed by repeated calls to the function \code{efficient.portfolio()}, -#' with \code{shorts=FALSE}, for a -#' grid of target expected returns starting at the expected return of the global minimum variance portfolio -#' (not allowing short sales) and ending at the expected return equal to the maximum expected return of +#' If short sales are allowed (negative weights) then the set of efficient portfolios of risky +#' assets can be computed as a convex combination of any two efficient portfolios. It is convenient +#' to use the global minimum variance portfolio as one portfolio and an efficient portfolio with +#' target expected return equal to the maximum expected return of the assets under consideration as +#' the other portfolio. Call these portfolios \eqn{m} and \eqn{x}, respectively. Then for any number +#' \samp{alpha}, another efficient portfolio can be computed as \eqn{z=\alpha m+(1-\alpha)x}. If +#' short sales are not allowed, then the set of efficient portfolios is computed by repeated calls +#' to the function \samp{efficient.portfolio()}, with \samp{shorts=FALSE}, for a grid of target +#' expected returns starting at the expected return of the global minimum variance portfolio (not +#' allowing short sales) and ending at the expected return equal to the maximum expected return of #' the assets under consideration. #' #' @param er \samp{N x 1} vector of expected returns #' @param cov.mat \samp{N x N} return covariance matrix #' @param nport scalar, number of efficient portfolios to compute -#' @param alpha.min minimum value of \samp{alpha}, default is \code{-.5} -#' @param alpha.max maximum value of \samp{alpha}, default is \code{1.5} -#' @param shorts logical, if \code{TRUE} then short sales (negative portfolio weights) -#' are allowed. If \code{FALSE} then no asset is allowed to be sold short +#' @param alpha.min minimum value of \samp{alpha}, default is \samp{-.5} +#' @param alpha.max maximum value of \samp{alpha}, default is \samp{1.5} +#' @param shorts logical, if \samp{TRUE} then short sales (negative portfolio weights) +#' are allowed. If \samp{FALSE} then no asset is allowed to be sold short #' #' @return #' \item{call}{captures function call} Modified: pkg/IntroCompFinR/R/efficient.portfolio.R =================================================================== --- pkg/IntroCompFinR/R/efficient.portfolio.R 2015-02-20 00:32:34 UTC (rev 11) +++ pkg/IntroCompFinR/R/efficient.portfolio.R 2015-02-20 06:59:09 UTC (rev 12) @@ -3,23 +3,22 @@ #' @author Eric Zivot #' #' @description -#' Compute minimum variance portfolio subject to target return either allowing all assets -#' to be sold short or not allowing any asset to be sold short. The returned object is -#' of class \samp{portfolio}. +#' Compute minimum variance portfolio subject to target return either allowing all assets to be sold +#' short or not allowing any asset to be sold short. The returned object is of class +#' \samp{portfolio}. #' #' @details -#' A mean-variance efficient portfolio \eqn{x} allowing short sales (negative weights) -#' that achieves the target expected return \eqn{\mu_0} -#' solves the optimization problem: min \eqn{t(x)\Sigma x} s.t. \eqn{t(x)1=1} and -#' \eqn{t(x)\mu=\mu_0}, for which there is an analytic solution using matrix algebra. -#' If short sales are not allowed then the portfolio is computed numerically using the -#' function \code{solve.QP()} from the \samp{quadprog} package. +#' A mean-variance efficient portfolio \eqn{x} allowing short sales (negative weights) that achieves +#' the target expected return \eqn{\mu_0} solves the optimization problem: min \eqn{t(x)\Sigma x} +#' s.t. \eqn{t(x)1=1} and \eqn{t(x)\mu=\mu_0}, for which there is an analytic solution using matrix +#' algebra. If short sales are not allowed then the portfolio is computed numerically using the +#' function \samp{solve.QP()} from the \samp{quadprog} package. #' #' @param er \samp{N x 1} vector of expected returns #' @param cov.mat \samp{N x N} return covariance matrix #' @param target.return scalar, target expected return -#' @param shorts logical, if \code{TRUE} then short sales (negative portfolio weights) -#' are allowed. If \code{FALSE} then no asset is allowed to be sold short. +#' @param shorts logical, if \samp{TRUE} then short sales (negative portfolio weights) +#' are allowed. If \samp{FALSE} then no asset is allowed to be sold short. #' #' @return #' \item{call}{captures function call} Modified: pkg/IntroCompFinR/R/getPortfolio.R =================================================================== --- pkg/IntroCompFinR/R/getPortfolio.R 2015-02-20 00:32:34 UTC (rev 11) +++ pkg/IntroCompFinR/R/getPortfolio.R 2015-02-20 06:59:09 UTC (rev 12) @@ -6,11 +6,11 @@ #' Create a portfolio object from expected return vector, covariance matrix, and weight vector. #' #' @details -#' To specify a portfolio, an expected return vector and covariance matrix for the assets under -#' consideration as well as a vector of portfolio weights are needed. The result of \code{getPortfolio} -#' is a \samp{portfolio} object, which is list with components for the portfolio expected return, -#' portfolio standard deviation, and portfolio weights. There are \code{print}, \code{summary} and \code{plot} -#' methods. +#' To specify a portfolio, an expected return vector and covariance matrix for the assets under +#' consideration as well as a vector of portfolio weights are needed. The result of +#' \samp{getPortfolio} is a \samp{portfolio} object, which is list with components for the portfolio +#' expected return, portfolio standard deviation, and portfolio weights. There are \samp{print}, +#' \samp{summary} and \samp{plot} methods. #' #' @param er \samp{N x 1} vector of expected returns #' @param cov.mat \samp{N x N} return covariance matrix Modified: pkg/IntroCompFinR/R/globalMin.portfolio.R =================================================================== --- pkg/IntroCompFinR/R/globalMin.portfolio.R 2015-02-20 00:32:34 UTC (rev 11) +++ pkg/IntroCompFinR/R/globalMin.portfolio.R 2015-02-20 06:59:09 UTC (rev 12) @@ -3,21 +3,20 @@ #' @author Eric Zivot #' #' @description -#' Compute global minimum variance portfolio given expected return vector and -#' covariance matrix. The portfolio can allow all assets to be shorted -#' or not allow any assets to be shorted. The returned object is of class \samp{portfolio}. +#' Compute global minimum variance portfolio given expected return vector and covariance matrix. The +#' portfolio can allow all assets to be shorted or not allow any assets to be shorted. The returned +#' object is of class \samp{portfolio}. #' #' @details #' The global minimum variance portfolio \eqn{m} allowing for short sales solves the optimization -#' problem: min \eqn{t(m)\Sigma m} s.t. \eqn{t(m)1=1} for which there is an analytic solution -#' using matrix algebra. If short sales are not allowed -#' then the portfolio is computed numerically using the function \code{solve.QP()} -#' from the \samp{quadprog} package. +#' problem: min \eqn{t(m)\Sigma m} s.t. \eqn{t(m)1=1} for which there is an analytic solution using +#' matrix algebra. If short sales are not allowed then the portfolio is computed numerically using +#' the function \samp{solve.QP()} from the \samp{quadprog} package. #' #' @param er \samp{N x 1} vector of expected returns #' @param cov.mat \samp{N x N} return covariance matrix -#' @param shorts logical, if \code{TRUE} then short sales (negative portfolio weights) -#' are allowed. If \code{FALSE} then no asset is allowed to be sold short. +#' @param shorts logical, if \samp{TRUE} then short sales (negative portfolio weights) +#' are allowed. If \samp{FALSE} then no asset is allowed to be sold short. #' #' @return #' \item{call}{captures function call} Modified: pkg/IntroCompFinR/R/plot.Markowitz.R =================================================================== --- pkg/IntroCompFinR/R/plot.Markowitz.R 2015-02-20 00:32:34 UTC (rev 11) +++ pkg/IntroCompFinR/R/plot.Markowitz.R 2015-02-20 06:59:09 UTC (rev 12) @@ -3,13 +3,13 @@ #' @author Eric Zivot #' #' @description -#' Plot efficient frontier. The efficient frontier is a plot of portfolio expected return vs. portfolio -#' standard deviation for a collection of mean-variance efficient portfolios - portfolios that minimize vriance -#' subject to a target expected return. +#' Plot efficient frontier. The efficient frontier is a plot of portfolio expected return vs. +#' portfolio standard deviation for a collection of mean-variance efficient portfolios - portfolios +#' that minimize variance subject to a target expected return. #' #' @param object object of class Markowitz -#' @param plot.assets if \code{TRUE} then plot asset \code{sd} and \code{er} with asset name labels -#' @param ... additional arguments passed to \code{plot()} +#' @param plot.assets if \samp{TRUE} then plot asset \samp{sd} and \samp{er} with asset name labels +#' @param ... additional arguments passed to \samp{plot()} #' #' @examples #' # construct the data Modified: pkg/IntroCompFinR/R/plot.portfolio.R =================================================================== --- pkg/IntroCompFinR/R/plot.portfolio.R 2015-02-20 00:32:34 UTC (rev 11) +++ pkg/IntroCompFinR/R/plot.portfolio.R 2015-02-20 06:59:09 UTC (rev 12) @@ -3,10 +3,10 @@ #' @author Eric Zivot #' #' @description -#' The \code{plot()} method shows a bar chart of the portfolio weights. +#' The \samp{plot()} method shows a bar chart of the portfolio weights. #' #' @param object object of class portfolio -#' @param ... additional arguments passed to \code{barplot()} +#' @param ... additional arguments passed to \samp{barplot()} #' #' @examples #' # construct the data Modified: pkg/IntroCompFinR/R/print.Markowitz.R =================================================================== --- pkg/IntroCompFinR/R/print.Markowitz.R 2015-02-20 00:32:34 UTC (rev 11) +++ pkg/IntroCompFinR/R/print.Markowitz.R 2015-02-20 06:59:09 UTC (rev 12) @@ -6,7 +6,7 @@ #' Print method for \samp{Markowitz} objects. #' #' @param object object of class Markowitz -#' @param ... additional arguments passed to \code{print()} +#' @param ... additional arguments passed to \samp{print()} #' #' @examples #' # construct the data Modified: pkg/IntroCompFinR/R/print.portfolio.R =================================================================== --- pkg/IntroCompFinR/R/print.portfolio.R 2015-02-20 00:32:34 UTC (rev 11) +++ pkg/IntroCompFinR/R/print.portfolio.R 2015-02-20 06:59:09 UTC (rev 12) @@ -6,7 +6,7 @@ #' Print method for objects of class \samp{portfolio}. #' #' @param object object of class portfolio -#' @param ... additional arguments passed to \code{print()} +#' @param ... additional arguments passed to \samp{print()} #' #' @examples #' # construct the data Modified: pkg/IntroCompFinR/R/summary.Markowitz.R =================================================================== --- pkg/IntroCompFinR/R/summary.Markowitz.R 2015-02-20 00:32:34 UTC (rev 11) +++ pkg/IntroCompFinR/R/summary.Markowitz.R 2015-02-20 06:59:09 UTC (rev 12) @@ -3,10 +3,10 @@ #' @author Eric Zivot #' #' @description -#' Summary method for objects of class \samp{Markowitz}. For all portfolios on the efficient frontier, -#' the expected return, standard deviation and asset weights are shown. If \code{risk.free} is given then -#' efficient portfolios that are combinations of the risk free asset and the tangency portfolio are computed. The -#' class \code{summary.Markozitz} will be created. +#' Summary method for objects of class \samp{Markowitz}. For all portfolios on the efficient +#' frontier, the expected return, standard deviation and asset weights are shown. If +#' \samp{risk.free} is given then efficient portfolios that are combinations of the risk free asset +#' and the tangency portfolio are computed. The class \samp{summary.Markozitz} will be created. #' #' @param object object of class Markowitz #' @param risk.free numeric, risk free rate Modified: pkg/IntroCompFinR/R/summary.portfolio.R =================================================================== --- pkg/IntroCompFinR/R/summary.portfolio.R 2015-02-20 00:32:34 UTC (rev 11) +++ pkg/IntroCompFinR/R/summary.portfolio.R 2015-02-20 06:59:09 UTC (rev 12) @@ -3,13 +3,12 @@ #' @author Eric Zivot #' #' @description -#' Summary method for objects of class \samp{portfolio}. The output is the same -#' as the \code{print}. If \code{risk.free} is specified then the portfolio Sharpe -#' ratio is also returned. +#' Summary method for objects of class \samp{portfolio}. The output is the same as the \samp{print}. +#' If \samp{risk.free} is specified then the portfolio Sharpe ratio is also returned. #' #' @param object object of class portfolio #' @param risk.free numeric, risk free rate -#' @param ... additional arguments passed to \code{summary()} +#' @param ... additional arguments passed to \samp{summary()} #' #' @examples #' # construct the data Modified: pkg/IntroCompFinR/R/tangency.portfolio.R =================================================================== --- pkg/IntroCompFinR/R/tangency.portfolio.R 2015-02-20 00:32:34 UTC (rev 11) +++ pkg/IntroCompFinR/R/tangency.portfolio.R 2015-02-20 06:59:09 UTC (rev 12) @@ -3,21 +3,21 @@ #' @author Eric Zivot #' #' @description -#' Compute tangency (maximum Sharpe ratio) portfolio. The portfolio can allow all assets to be shorted -#' or not allow any assets to be shorted. +#' Compute tangency (maximum Sharpe ratio) portfolio. The portfolio can allow all assets to be +#' shorted or not allow any assets to be shorted. #' #' @details -#' The tangency portfolio \samp{t} is the portfolio of risky assets with the highest Sharpe's slope and -#' solves the optimization problem: max \eqn{(t(t)\mu-r_f)/(t(t)\Sigma t^{1/2})} s.t. \eqn{t(t)1=1} -#' where \eqn{r_f} denotes the risk-free rate. If short sales are allowed then there is an analytic -#' solution using matrix algebra. If short sales are not allowed then the maximum sharpe ratio portfolio must -#' be computed numerically. +#' The tangency portfolio \samp{t} is the portfolio of risky assets with the highest Sharpe's slope +#' and solves the optimization problem: max \eqn{(t(t)\mu-r_f)/(t(t)\Sigma t^{1/2})} s.t. +#' \eqn{t(t)1=1} where \eqn{r_f} denotes the risk-free rate. If short sales are allowed then there +#' is an analytic solution using matrix algebra. If short sales are not allowed then the maximum +#' Sharpe ratio portfolio must be computed numerically. #' #' @param er \samp{N x 1} vector of expected returns #' @param cov.mat \samp{N x N} return covariance matrix #' @param risk.free numeric, risk free rate -#' @param shorts logical, if \code{TRUE} then short sales (negative portfolio weights) -#' are allowed. If \code{FALSE} then no asset is allowed to be sold short. +#' @param shorts logical, if \samp{TRUE} then short sales (negative portfolio weights) +#' are allowed. If \samp{FALSE} then no asset is allowed to be sold short. #' #' @return #' \item{call}{captures function call} Modified: pkg/IntroCompFinR/man/efficient.frontier.Rd =================================================================== --- pkg/IntroCompFinR/man/efficient.frontier.Rd 2015-02-20 00:32:34 UTC (rev 11) +++ pkg/IntroCompFinR/man/efficient.frontier.Rd 2015-02-20 06:59:09 UTC (rev 12) @@ -14,12 +14,12 @@ \item{nport}{scalar, number of efficient portfolios to compute} -\item{alpha.min}{minimum value of \samp{alpha}, default is \code{-.5}} +\item{alpha.min}{minimum value of \samp{alpha}, default is \samp{-.5}} -\item{alpha.max}{maximum value of \samp{alpha}, default is \code{1.5}} +\item{alpha.max}{maximum value of \samp{alpha}, default is \samp{1.5}} -\item{shorts}{logical, if \code{TRUE} then short sales (negative portfolio weights) -are allowed. If \code{FALSE} then no asset is allowed to be sold short} +\item{shorts}{logical, if \samp{TRUE} then short sales (negative portfolio weights) +are allowed. If \samp{FALSE} then no asset is allowed to be sold short} } \value{ \item{call}{captures function call} @@ -28,22 +28,21 @@ \item{weights}{\samp{nport x N} matrix of weights of efficient portfolios} } \description{ -The function constructs the set of mean-variance efficient portfolios that either allow all assets to be -sold short or not allow any asset to be sold short. The returned object is of class \samp{Markowitz} for -which there are \code{print}, \code{summary} and \code{plot} methods. +The function constructs the set of mean-variance efficient portfolios that either allow all +assets to be sold short or not allow any asset to be sold short. The returned object is of class +\samp{Markowitz} for which there are \samp{print}, \samp{summary} and \samp{plot} methods. } \details{ -If short sales are allowed (negative weights) then the set of efficient portfolios of risky assets -can be computed as a convex combination of -any two efficient portfolios. It is convenient to use the global minimum variance portfolio as -one portfolio and an efficient portfolio with target expected return equal to the maximum -expected return of the assets under consideration as the other portfolio. Call these portfolios -\eqn{m} and \eqn{x}, respectively. Then for any number \samp{alpha}, another efficient -portfolio can be computed as \eqn{z=\alpha m+(1-\alpha)x}. If short sales are not allowed, then the set -of efficient portfolios is computed by repeated calls to the function \code{efficient.portfolio()}, -with \code{shorts=FALSE}, for a -grid of target expected returns starting at the expected return of the global minimum variance portfolio -(not allowing short sales) and ending at the expected return equal to the maximum expected return of +If short sales are allowed (negative weights) then the set of efficient portfolios of risky +assets can be computed as a convex combination of any two efficient portfolios. It is convenient +to use the global minimum variance portfolio as one portfolio and an efficient portfolio with +target expected return equal to the maximum expected return of the assets under consideration as +the other portfolio. Call these portfolios \eqn{m} and \eqn{x}, respectively. Then for any number +\samp{alpha}, another efficient portfolio can be computed as \eqn{z=\alpha m+(1-\alpha)x}. If +short sales are not allowed, then the set of efficient portfolios is computed by repeated calls +to the function \samp{efficient.portfolio()}, with \samp{shorts=FALSE}, for a grid of target +expected returns starting at the expected return of the global minimum variance portfolio (not +allowing short sales) and ending at the expected return equal to the maximum expected return of the assets under consideration. } \examples{ Modified: pkg/IntroCompFinR/man/efficient.portfolio.Rd =================================================================== --- pkg/IntroCompFinR/man/efficient.portfolio.Rd 2015-02-20 00:32:34 UTC (rev 11) +++ pkg/IntroCompFinR/man/efficient.portfolio.Rd 2015-02-20 06:59:09 UTC (rev 12) @@ -13,8 +13,8 @@ \item{target.return}{scalar, target expected return} -\item{shorts}{logical, if \code{TRUE} then short sales (negative portfolio weights) -are allowed. If \code{FALSE} then no asset is allowed to be sold short.} +\item{shorts}{logical, if \samp{TRUE} then short sales (negative portfolio weights) +are allowed. If \samp{FALSE} then no asset is allowed to be sold short.} } \value{ \item{call}{captures function call} @@ -23,17 +23,16 @@ \item{weights}{\samp{N x 1} vector of portfolio weights} } \description{ -Compute minimum variance portfolio subject to target return either allowing all assets -to be sold short or not allowing any asset to be sold short. The returned object is -of class \samp{portfolio}. +Compute minimum variance portfolio subject to target return either allowing all assets to be sold +short or not allowing any asset to be sold short. The returned object is of class +\samp{portfolio}. } \details{ -A mean-variance efficient portfolio \eqn{x} allowing short sales (negative weights) -that achieves the target expected return \eqn{\mu_0} -solves the optimization problem: min \eqn{t(x)\Sigma x} s.t. \eqn{t(x)1=1} and -\eqn{t(x)\mu=\mu_0}, for which there is an analytic solution using matrix algebra. -If short sales are not allowed then the portfolio is computed numerically using the -function \code{solve.QP()} from the \samp{quadprog} package. +A mean-variance efficient portfolio \eqn{x} allowing short sales (negative weights) that achieves +the target expected return \eqn{\mu_0} solves the optimization problem: min \eqn{t(x)\Sigma x} +s.t. \eqn{t(x)1=1} and \eqn{t(x)\mu=\mu_0}, for which there is an analytic solution using matrix +algebra. If short sales are not allowed then the portfolio is computed numerically using the +function \samp{solve.QP()} from the \samp{quadprog} package. } \examples{ # construct the data Modified: pkg/IntroCompFinR/man/getPortfolio.Rd =================================================================== --- pkg/IntroCompFinR/man/getPortfolio.Rd 2015-02-20 00:32:34 UTC (rev 11) +++ pkg/IntroCompFinR/man/getPortfolio.Rd 2015-02-20 06:59:09 UTC (rev 12) @@ -24,10 +24,10 @@ } \details{ To specify a portfolio, an expected return vector and covariance matrix for the assets under -consideration as well as a vector of portfolio weights are needed. The result of \code{getPortfolio} -is a \samp{portfolio} object, which is list with components for the portfolio expected return, -portfolio standard deviation, and portfolio weights. There are \code{print}, \code{summary} and \code{plot} -methods. +consideration as well as a vector of portfolio weights are needed. The result of +\samp{getPortfolio} is a \samp{portfolio} object, which is list with components for the portfolio +expected return, portfolio standard deviation, and portfolio weights. There are \samp{print}, +\samp{summary} and \samp{plot} methods. } \examples{ # construct the data Modified: pkg/IntroCompFinR/man/globalMin.portfolio.Rd =================================================================== --- pkg/IntroCompFinR/man/globalMin.portfolio.Rd 2015-02-20 00:32:34 UTC (rev 11) +++ pkg/IntroCompFinR/man/globalMin.portfolio.Rd 2015-02-20 06:59:09 UTC (rev 12) @@ -11,8 +11,8 @@ \item{cov.mat}{\samp{N x N} return covariance matrix} -\item{shorts}{logical, if \code{TRUE} then short sales (negative portfolio weights) -are allowed. If \code{FALSE} then no asset is allowed to be sold short.} +\item{shorts}{logical, if \samp{TRUE} then short sales (negative portfolio weights) +are allowed. If \samp{FALSE} then no asset is allowed to be sold short.} } \value{ \item{call}{captures function call} @@ -21,16 +21,15 @@ \item{weights}{\samp{N x 1} vector of portfolio weights} } \description{ -Compute global minimum variance portfolio given expected return vector and -covariance matrix. The portfolio can allow all assets to be shorted -or not allow any assets to be shorted. The returned object is of class \samp{portfolio}. +Compute global minimum variance portfolio given expected return vector and covariance matrix. The +portfolio can allow all assets to be shorted or not allow any assets to be shorted. The returned +object is of class \samp{portfolio}. } \details{ The global minimum variance portfolio \eqn{m} allowing for short sales solves the optimization -problem: min \eqn{t(m)\Sigma m} s.t. \eqn{t(m)1=1} for which there is an analytic solution -using matrix algebra. If short sales are not allowed -then the portfolio is computed numerically using the function \code{solve.QP()} -from the \samp{quadprog} package. +problem: min \eqn{t(m)\Sigma m} s.t. \eqn{t(m)1=1} for which there is an analytic solution using +matrix algebra. If short sales are not allowed then the portfolio is computed numerically using +the function \samp{solve.QP()} from the \samp{quadprog} package. } \examples{ # construct the data Modified: pkg/IntroCompFinR/man/plot.Markowitz.Rd =================================================================== --- pkg/IntroCompFinR/man/plot.Markowitz.Rd 2015-02-20 00:32:34 UTC (rev 11) +++ pkg/IntroCompFinR/man/plot.Markowitz.Rd 2015-02-20 06:59:09 UTC (rev 12) @@ -9,14 +9,14 @@ \arguments{ \item{object}{object of class Markowitz} -\item{plot.assets}{if \code{TRUE} then plot asset \code{sd} and \code{er} with asset name labels} +\item{plot.assets}{if \samp{TRUE} then plot asset \samp{sd} and \samp{er} with asset name labels} -\item{...}{additional arguments passed to \code{plot()}} +\item{...}{additional arguments passed to \samp{plot()}} } \description{ -Plot efficient frontier. The efficient frontier is a plot of portfolio expected return vs. portfolio -standard deviation for a collection of mean-variance efficient portfolios - portfolios that minimize vriance -subject to a target expected return. +Plot efficient frontier. The efficient frontier is a plot of portfolio expected return vs. +portfolio standard deviation for a collection of mean-variance efficient portfolios - portfolios +that minimize variance subject to a target expected return. } \examples{ # construct the data Modified: pkg/IntroCompFinR/man/plot.portfolio.Rd =================================================================== --- pkg/IntroCompFinR/man/plot.portfolio.Rd 2015-02-20 00:32:34 UTC (rev 11) +++ pkg/IntroCompFinR/man/plot.portfolio.Rd 2015-02-20 06:59:09 UTC (rev 12) @@ -9,10 +9,10 @@ \arguments{ \item{object}{object of class portfolio} -\item{...}{additional arguments passed to \code{barplot()}} +\item{...}{additional arguments passed to \samp{barplot()}} } \description{ -The \code{plot()} method shows a bar chart of the portfolio weights. +The \samp{plot()} method shows a bar chart of the portfolio weights. } \examples{ # construct the data Modified: pkg/IntroCompFinR/man/print.Markowitz.Rd =================================================================== --- pkg/IntroCompFinR/man/print.Markowitz.Rd 2015-02-20 00:32:34 UTC (rev 11) +++ pkg/IntroCompFinR/man/print.Markowitz.Rd 2015-02-20 06:59:09 UTC (rev 12) @@ -9,7 +9,7 @@ \arguments{ \item{object}{object of class Markowitz} -\item{...}{additional arguments passed to \code{print()}} +\item{...}{additional arguments passed to \samp{print()}} } \description{ Print method for \samp{Markowitz} objects. Modified: pkg/IntroCompFinR/man/print.portfolio.Rd =================================================================== --- pkg/IntroCompFinR/man/print.portfolio.Rd 2015-02-20 00:32:34 UTC (rev 11) +++ pkg/IntroCompFinR/man/print.portfolio.Rd 2015-02-20 06:59:09 UTC (rev 12) @@ -9,7 +9,7 @@ \arguments{ \item{object}{object of class portfolio} -\item{...}{additional arguments passed to \code{print()}} +\item{...}{additional arguments passed to \samp{print()}} } \description{ Print method for objects of class \samp{portfolio}. Modified: pkg/IntroCompFinR/man/summary.Markowitz.Rd =================================================================== --- pkg/IntroCompFinR/man/summary.Markowitz.Rd 2015-02-20 00:32:34 UTC (rev 11) +++ pkg/IntroCompFinR/man/summary.Markowitz.Rd 2015-02-20 06:59:09 UTC (rev 12) @@ -12,10 +12,10 @@ \item{risk.free}{numeric, risk free rate} } \description{ -Summary method for objects of class \samp{Markowitz}. For all portfolios on the efficient frontier, -the expected return, standard deviation and asset weights are shown. If \code{risk.free} is given then -efficient portfolios that are combinations of the risk free asset and the tangency portfolio are computed. The -class \code{summary.Markozitz} will be created. +Summary method for objects of class \samp{Markowitz}. For all portfolios on the efficient +frontier, the expected return, standard deviation and asset weights are shown. If +\samp{risk.free} is given then efficient portfolios that are combinations of the risk free asset +and the tangency portfolio are computed. The class \samp{summary.Markozitz} will be created. } \examples{ # construct the data Modified: pkg/IntroCompFinR/man/summary.portfolio.Rd =================================================================== --- pkg/IntroCompFinR/man/summary.portfolio.Rd 2015-02-20 00:32:34 UTC (rev 11) +++ pkg/IntroCompFinR/man/summary.portfolio.Rd 2015-02-20 06:59:09 UTC (rev 12) @@ -11,12 +11,11 @@ \item{risk.free}{numeric, risk free rate} -\item{...}{additional arguments passed to \code{summary()}} +\item{...}{additional arguments passed to \samp{summary()}} } \description{ -Summary method for objects of class \samp{portfolio}. The output is the same -as the \code{print}. If \code{risk.free} is specified then the portfolio Sharpe -ratio is also returned. +Summary method for objects of class \samp{portfolio}. The output is the same as the \samp{print}. +If \samp{risk.free} is specified then the portfolio Sharpe ratio is also returned. } \examples{ # construct the data Modified: pkg/IntroCompFinR/man/tangency.portfolio.Rd =================================================================== --- pkg/IntroCompFinR/man/tangency.portfolio.Rd 2015-02-20 00:32:34 UTC (rev 11) +++ pkg/IntroCompFinR/man/tangency.portfolio.Rd 2015-02-20 06:59:09 UTC (rev 12) @@ -13,8 +13,8 @@ \item{risk.free}{numeric, risk free rate} -\item{shorts}{logical, if \code{TRUE} then short sales (negative portfolio weights) -are allowed. If \code{FALSE} then no asset is allowed to be sold short.} +\item{shorts}{logical, if \samp{TRUE} then short sales (negative portfolio weights) +are allowed. If \samp{FALSE} then no asset is allowed to be sold short.} } \value{ \item{call}{captures function call} @@ -23,15 +23,15 @@ \item{weights}{\samp{N x 1} vector of portfolio weights} } \description{ -Compute tangency (maximum Sharpe ratio) portfolio. The portfolio can allow all assets to be shorted -or not allow any assets to be shorted. +Compute tangency (maximum Sharpe ratio) portfolio. The portfolio can allow all assets to be +shorted or not allow any assets to be shorted. } \details{ -The tangency portfolio \samp{t} is the portfolio of risky assets with the highest Sharpe's slope and -solves the optimization problem: max \eqn{(t(t)\mu-r_f)/(t(t)\Sigma t^{1/2})} s.t. \eqn{t(t)1=1} -where \eqn{r_f} denotes the risk-free rate. If short sales are allowed then there is an analytic -solution using matrix algebra. If short sales are not allowed then the maximum sharpe ratio portfolio must -be computed numerically. +The tangency portfolio \samp{t} is the portfolio of risky assets with the highest Sharpe's slope +and solves the optimization problem: max \eqn{(t(t)\mu-r_f)/(t(t)\Sigma t^{1/2})} s.t. +\eqn{t(t)1=1} where \eqn{r_f} denotes the risk-free rate. If short sales are allowed then there +is an analytic solution using matrix algebra. If short sales are not allowed then the maximum +Sharpe ratio portfolio must be computed numerically. } \examples{ # construct the data From noreply at r-forge.r-project.org Mon Feb 23 01:43:01 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 23 Feb 2015 01:43:01 +0100 (CET) Subject: [Introcompfinr-commits] r13 - in pkg/IntroCompFinR: . R data man Message-ID: <20150223004301.BAAD6184B75@r-forge.r-project.org> Author: bethanyyollin Date: 2015-02-23 01:43:00 +0100 (Mon, 23 Feb 2015) New Revision: 13 Added: pkg/IntroCompFinR/R/data.R pkg/IntroCompFinR/data/ pkg/IntroCompFinR/data/msftDailyPrices.rda pkg/IntroCompFinR/data/msftMonthlyPrices.rda pkg/IntroCompFinR/data/sbuxDailyPrices.rda pkg/IntroCompFinR/data/sbuxMonthlyPrices.rda pkg/IntroCompFinR/data/sp500DailyPrices.rda pkg/IntroCompFinR/data/sp500MonthlyPrices.rda pkg/IntroCompFinR/man/msftDailyPrices.Rd pkg/IntroCompFinR/man/msftMonthlyPrices.Rd pkg/IntroCompFinR/man/sbuxDailyPrices.Rd pkg/IntroCompFinR/man/sbuxMonthlyPrices.Rd pkg/IntroCompFinR/man/sp500DailyPrices.Rd pkg/IntroCompFinR/man/sp500MonthlyPrices.Rd Modified: pkg/IntroCompFinR/DESCRIPTION pkg/IntroCompFinR/R/efficient.portfolio.R pkg/IntroCompFinR/R/globalMin.portfolio.R pkg/IntroCompFinR/R/plot.Markowitz.R pkg/IntroCompFinR/R/plot.portfolio.R pkg/IntroCompFinR/R/print.Markowitz.R pkg/IntroCompFinR/R/print.portfolio.R pkg/IntroCompFinR/R/summary.Markowitz.R pkg/IntroCompFinR/R/tangency.portfolio.R pkg/IntroCompFinR/man/plot.Markowitz.Rd pkg/IntroCompFinR/man/plot.portfolio.Rd pkg/IntroCompFinR/man/print.Markowitz.Rd pkg/IntroCompFinR/man/print.portfolio.Rd pkg/IntroCompFinR/man/summary.Markowitz.Rd Log: Resolved S3 generic function inconsistencies. Added data and data documentation. Changed DESCRIPTION (lazy loading of data and imports). Modified: pkg/IntroCompFinR/DESCRIPTION =================================================================== --- pkg/IntroCompFinR/DESCRIPTION 2015-02-20 06:59:09 UTC (rev 12) +++ pkg/IntroCompFinR/DESCRIPTION 2015-02-23 00:43:00 UTC (rev 13) @@ -10,5 +10,7 @@ purpose. Students are expected to download the package and learn from the codes and examples. Moreover, the book coming soon is also based on this package. License: GPL-2 -Depends: R (>= 2.12.2),quadprog,tseries,zoo -LazyLoad: yes \ No newline at end of file +Depends: R (>= 2.12.2) +Imports: quadprog +LazyLoad: yes +LazyData: true \ No newline at end of file Added: pkg/IntroCompFinR/R/data.R =================================================================== --- pkg/IntroCompFinR/R/data.R (rev 0) +++ pkg/IntroCompFinR/R/data.R 2015-02-23 00:43:00 UTC (rev 13) @@ -0,0 +1,71 @@ +#' Daily adjusted closing price for Microsoft +#' +#' A \samp{xts} object of daily adjusted closing price for Microsoft from 1993-01-04 to 2014-12-31. +#' +#' @format A \samp{xts} object on 1993-01-04 to 2014-12-31 containing: +#' \describe{ +#' \item{MFST}{adjusted closing price in USD} +#' } +#' Indexed by objects of class: [Date] TZ: UTC. +#' @source Yahoo! Finance: \url{http://finance.yahoo.com/q/hp?s=MSFT+Historical+Prices} +"msftDailyPrices" + +#' Monthly adjusted closing price for Microsoft +#' +#' A \samp{xts} object of monthly adjusted closing price for Microsoft from Jan-1993 to Dec-2014. +#' +#' @format A \samp{xts} object on Jan-1993 to Dec-2014 containing: +#' \describe{ +#' \item{MFST}{adjusted closing price in USD} +#' } +#' Indexed by objects of class: [Date] TZ: UTC. +#' @source Yahoo! Finance: \url{http://finance.yahoo.com/q/hp?s=MSFT+Historical+Prices} +"msftMonthlyPrices" + +#' Daily adjusted closing price for Starbucks +#' +#' A \samp{xts} object of daily adjusted closing price for Starbucks from 1993-01-04 to 2014-12-31. +#' +#' @format A \samp{xts} object on 1993-01-04 to 2014-12-31 containing: +#' \describe{ +#' \item{SBUX}{adjusted closing price in USD} +#' } +#' Indexed by objects of class: [Date] TZ: UTC. +#' @source Yahoo! Finance: \url{http://finance.yahoo.com/q/hp?s=SBUX+Historical+Prices} +"sbuxDailyPrices" + +#' Monthly adjusted closing price for Starbucks +#' +#' A \samp{xts} object of monthly adjusted closing price for Starbucks from Jan-1993 to Dec-2014. +#' +#' @format A \samp{xts} object on Jan-1993 to Dec-2014 containing: +#' \describe{ +#' \item{SBUX}{adjusted closing price in USD} +#' } +#' Indexed by objects of class: [Date] TZ: UTC. +#' @source Yahoo! Finance: \url{http://finance.yahoo.com/q/hp?s=SBUX+Historical+Prices} +"sbuxMonthlyPrices" + +#' Daily adjusted closing price for S&P 500 +#' +#' A \samp{xts} object of daily adjusted closing price for S&P 500 from 1993-01-04 to 2014-12-31. +#' +#' @format A \samp{xts} object on 1993-01-04 to 2014-12-31 containing: +#' \describe{ +#' \item{SP500}{adjusted closing price in USD} +#' } +#' Indexed by objects of class: [Date] TZ: UTC. +#' @source Yahoo! Finance: \url{http://finance.yahoo.com/q/hp?s=\%5EGSPC+Historical+Prices} +"sp500DailyPrices" + +#' Monthly adjusted closing price for S&P 500 +#' +#' A \samp{xts} object of daily adjusted closing price for S&P 500 from Jan-1993 to Dec-2014. +#' +#' @format A \samp{xts} object on Jan-1993 to Dec-2014 containing: +#' \describe{ +#' \item{SP500}{adjusted closing price in USD} +#' } +#' Indexed by objects of class: [Date] TZ: UTC. +#' @source Yahoo! Finance: \url{http://finance.yahoo.com/q/hp?s=\%5EGSPC+Historical+Prices} +"sp500MonthlyPrices" \ No newline at end of file Modified: pkg/IntroCompFinR/R/efficient.portfolio.R =================================================================== --- pkg/IntroCompFinR/R/efficient.portfolio.R 2015-02-20 06:59:09 UTC (rev 12) +++ pkg/IntroCompFinR/R/efficient.portfolio.R 2015-02-23 00:43:00 UTC (rev 13) @@ -88,7 +88,7 @@ dvec <- rep.int(0, N) Amat <- cbind(rep(1,N), er, diag(1,N)) bvec <- c(1, target.return, rep(0,N)) - result <- solve.QP(Dmat=Dmat,dvec=dvec,Amat=Amat,bvec=bvec,meq=2) + result <- quadprog::solve.QP(Dmat=Dmat,dvec=dvec,Amat=Amat,bvec=bvec,meq=2) w <- round(result$solution, 6) } else { stop("shorts needs to be logical. For no-shorts, shorts=FALSE.") Modified: pkg/IntroCompFinR/R/globalMin.portfolio.R =================================================================== --- pkg/IntroCompFinR/R/globalMin.portfolio.R 2015-02-20 06:59:09 UTC (rev 12) +++ pkg/IntroCompFinR/R/globalMin.portfolio.R 2015-02-23 00:43:00 UTC (rev 13) @@ -83,7 +83,7 @@ dvec <- rep.int(0, N) Amat <- cbind(rep(1,N), diag(1,N)) bvec <- c(1, rep(0,N)) - result <- solve.QP(Dmat=Dmat,dvec=dvec,Amat=Amat,bvec=bvec,meq=1) + result <- quadprog::solve.QP(Dmat=Dmat,dvec=dvec,Amat=Amat,bvec=bvec,meq=1) w.gmin <- round(result$solution, 6) } else { stop("shorts needs to be logical. For no-shorts, shorts=FALSE.") Modified: pkg/IntroCompFinR/R/plot.Markowitz.R =================================================================== --- pkg/IntroCompFinR/R/plot.Markowitz.R 2015-02-20 06:59:09 UTC (rev 12) +++ pkg/IntroCompFinR/R/plot.Markowitz.R 2015-02-23 00:43:00 UTC (rev 13) @@ -7,7 +7,7 @@ #' portfolio standard deviation for a collection of mean-variance efficient portfolios - portfolios #' that minimize variance subject to a target expected return. #' -#' @param object object of class Markowitz +#' @param x object of class Markowitz #' @param plot.assets if \samp{TRUE} then plot asset \samp{sd} and \samp{er} with asset name labels #' @param ... additional arguments passed to \samp{plot()} #' @@ -45,22 +45,22 @@ #' @export plot.Markowitz plot.Markowitz <- -function(object, plot.assets=FALSE, ...) +function(x, plot.assets=FALSE, ...) { if (!plot.assets) { - y.lim=c(0,max(object$er)) - x.lim=c(0,max(object$sd)) - plot(object$sd,object$er,type="b",xlim=x.lim, ylim=y.lim, + y.lim=c(0,max(x$er)) + x.lim=c(0,max(x$sd)) + plot(x$sd,x$er,type="b",xlim=x.lim, ylim=y.lim, xlab="Portfolio SD", ylab="Portfolio ER", main="Efficient Frontier", ...) } else { - call = object$call + call = x$call mu.vals = eval(call$er) sd.vals = sqrt( diag( eval(call$cov.mat) ) ) - y.lim = range(c(0,mu.vals,object$er)) - x.lim = range(c(0,sd.vals,object$sd)) - plot(object$sd,object$er,type="b", xlim=x.lim, ylim=y.lim, + y.lim = range(c(0,mu.vals,x$er)) + x.lim = range(c(0,sd.vals,x$sd)) + plot(x$sd,x$er,type="b", xlim=x.lim, ylim=y.lim, xlab="Portfolio SD", ylab="Portfolio ER", main="Efficient Frontier", ...) text(sd.vals, mu.vals, labels=names(mu.vals)) Modified: pkg/IntroCompFinR/R/plot.portfolio.R =================================================================== --- pkg/IntroCompFinR/R/plot.portfolio.R 2015-02-20 06:59:09 UTC (rev 12) +++ pkg/IntroCompFinR/R/plot.portfolio.R 2015-02-23 00:43:00 UTC (rev 13) @@ -5,7 +5,7 @@ #' @description #' The \samp{plot()} method shows a bar chart of the portfolio weights. #' -#' @param object object of class portfolio +#' @param x object of class portfolio #' @param ... additional arguments passed to \samp{barplot()} #' #' @examples @@ -28,10 +28,10 @@ #' @export plot.portfolio plot.portfolio <- -function(object, ...) +function(x, ...) { - asset.names <- names(object$weights) - barplot(object$weights, names=asset.names, + asset.names <- names(x$weights) + barplot(x$weights, names=asset.names, xlab="Assets", ylab="Weight", main="Portfolio Weights", ...) invisible() } \ No newline at end of file Modified: pkg/IntroCompFinR/R/print.Markowitz.R =================================================================== --- pkg/IntroCompFinR/R/print.Markowitz.R 2015-02-20 06:59:09 UTC (rev 12) +++ pkg/IntroCompFinR/R/print.Markowitz.R 2015-02-23 00:43:00 UTC (rev 13) @@ -5,7 +5,7 @@ #' @description #' Print method for \samp{Markowitz} objects. #' -#' @param object object of class Markowitz +#' @param x object of class Markowitz #' @param ... additional arguments passed to \samp{print()} #' #' @examples @@ -34,13 +34,13 @@ #' @export print.Markowitz print.Markowitz <- -function(object, ...) +function(x, ...) { cat("Call:\n") - print(object$call) - xx <- rbind(object$er,object$sd) + print(x$call) + xx <- rbind(x$er,x$sd) dimnames(xx)[[1]] <- c("ER","SD") cat("\nFrontier portfolios' expected returns and standard deviations\n") print(round(xx,4), ...) - invisible(object) + invisible(x) } \ No newline at end of file Modified: pkg/IntroCompFinR/R/print.portfolio.R =================================================================== --- pkg/IntroCompFinR/R/print.portfolio.R 2015-02-20 06:59:09 UTC (rev 12) +++ pkg/IntroCompFinR/R/print.portfolio.R 2015-02-23 00:43:00 UTC (rev 13) @@ -5,7 +5,7 @@ #' @description #' Print method for objects of class \samp{portfolio}. #' -#' @param object object of class portfolio +#' @param x object of class portfolio #' @param ... additional arguments passed to \samp{print()} #' #' @examples @@ -28,13 +28,13 @@ #' @export print.portfolio print.portfolio <- -function(object, ...) +function(x, ...) { cat("Call:\n") - print(object$call, ...) - cat("\nPortfolio expected return: ", format(object$er, ...), "\n") - cat("Portfolio standard deviation: ", format(object$sd, ...), "\n") + print(x$call, ...) + cat("\nPortfolio expected return: ", format(x$er, ...), "\n") + cat("Portfolio standard deviation: ", format(x$sd, ...), "\n") cat("Portfolio weights:\n") - print(round(object$weights,4), ...) - invisible(object) + print(round(x$weights,4), ...) + invisible(x) } \ No newline at end of file Modified: pkg/IntroCompFinR/R/summary.Markowitz.R =================================================================== --- pkg/IntroCompFinR/R/summary.Markowitz.R 2015-02-20 06:59:09 UTC (rev 12) +++ pkg/IntroCompFinR/R/summary.Markowitz.R 2015-02-23 00:43:00 UTC (rev 13) @@ -10,6 +10,7 @@ #' #' @param object object of class Markowitz #' @param risk.free numeric, risk free rate +#' @param ... additional arguments passed to \samp{summary()} #' #' @examples #' # construct the data @@ -37,7 +38,7 @@ #' @export summary.Markowitz summary.Markowitz <- -function(object, risk.free=NULL) +function(object, risk.free=NULL, ...) { call <- object$call asset.names <- colnames(object$weights) Modified: pkg/IntroCompFinR/R/tangency.portfolio.R =================================================================== --- pkg/IntroCompFinR/R/tangency.portfolio.R 2015-02-20 06:59:09 UTC (rev 12) +++ pkg/IntroCompFinR/R/tangency.portfolio.R 2015-02-23 00:43:00 UTC (rev 13) @@ -91,7 +91,7 @@ er.excess <- er - risk.free Amat <- cbind(er.excess, diag(1,N)) bvec <- c(1, rep(0,N)) - result <- solve.QP(Dmat=Dmat,dvec=dvec,Amat=Amat,bvec=bvec,meq=1) + result <- quadprog::solve.QP(Dmat=Dmat,dvec=dvec,Amat=Amat,bvec=bvec,meq=1) w.t <- round(result$solution/sum(result$solution), 6) } else { stop("Shorts needs to be logical. For no-shorts, shorts=FALSE.") Added: pkg/IntroCompFinR/data/msftDailyPrices.rda =================================================================== (Binary files differ) Property changes on: pkg/IntroCompFinR/data/msftDailyPrices.rda ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: pkg/IntroCompFinR/data/msftMonthlyPrices.rda =================================================================== (Binary files differ) Property changes on: pkg/IntroCompFinR/data/msftMonthlyPrices.rda ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: pkg/IntroCompFinR/data/sbuxDailyPrices.rda =================================================================== (Binary files differ) Property changes on: pkg/IntroCompFinR/data/sbuxDailyPrices.rda ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: pkg/IntroCompFinR/data/sbuxMonthlyPrices.rda =================================================================== (Binary files differ) Property changes on: pkg/IntroCompFinR/data/sbuxMonthlyPrices.rda ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: pkg/IntroCompFinR/data/sp500DailyPrices.rda =================================================================== (Binary files differ) Property changes on: pkg/IntroCompFinR/data/sp500DailyPrices.rda ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: pkg/IntroCompFinR/data/sp500MonthlyPrices.rda =================================================================== (Binary files differ) Property changes on: pkg/IntroCompFinR/data/sp500MonthlyPrices.rda ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: pkg/IntroCompFinR/man/msftDailyPrices.Rd =================================================================== --- pkg/IntroCompFinR/man/msftDailyPrices.Rd (rev 0) +++ pkg/IntroCompFinR/man/msftDailyPrices.Rd 2015-02-23 00:43:00 UTC (rev 13) @@ -0,0 +1,22 @@ +% Generated by roxygen2 (4.1.0): do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\name{msftDailyPrices} +\alias{msftDailyPrices} +\title{Daily adjusted closing price for Microsoft} +\format{A \samp{xts} object on 1993-01-04 to 2014-12-31 containing: +\describe{ + \item{MFST}{adjusted closing price in USD} +} +Indexed by objects of class: [Date] TZ: UTC.} +\source{ +Yahoo! Finance: \url{http://finance.yahoo.com/q/hp?s=MSFT+Historical+Prices} +} +\usage{ +msftDailyPrices +} +\description{ +A \samp{xts} object of daily adjusted closing price for Microsoft from 1993-01-04 to 2014-12-31. +} +\keyword{datasets} + Added: pkg/IntroCompFinR/man/msftMonthlyPrices.Rd =================================================================== --- pkg/IntroCompFinR/man/msftMonthlyPrices.Rd (rev 0) +++ pkg/IntroCompFinR/man/msftMonthlyPrices.Rd 2015-02-23 00:43:00 UTC (rev 13) @@ -0,0 +1,22 @@ +% Generated by roxygen2 (4.1.0): do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\name{msftMonthlyPrices} +\alias{msftMonthlyPrices} +\title{Monthly adjusted closing price for Microsoft} +\format{A \samp{xts} object on Jan-1993 to Dec-2014 containing: +\describe{ + \item{MFST}{adjusted closing price in USD} +} +Indexed by objects of class: [Date] TZ: UTC.} +\source{ +Yahoo! Finance: \url{http://finance.yahoo.com/q/hp?s=MSFT+Historical+Prices} +} +\usage{ +msftMonthlyPrices +} +\description{ +A \samp{xts} object of monthly adjusted closing price for Microsoft from Jan-1993 to Dec-2014. +} +\keyword{datasets} + Modified: pkg/IntroCompFinR/man/plot.Markowitz.Rd =================================================================== --- pkg/IntroCompFinR/man/plot.Markowitz.Rd 2015-02-20 06:59:09 UTC (rev 12) +++ pkg/IntroCompFinR/man/plot.Markowitz.Rd 2015-02-23 00:43:00 UTC (rev 13) @@ -4,10 +4,10 @@ \alias{plot.Markowitz} \title{Plot method of class Markowitz} \usage{ -\method{plot}{Markowitz}(object, plot.assets = FALSE, ...) +\method{plot}{Markowitz}(x, plot.assets = FALSE, ...) } \arguments{ -\item{object}{object of class Markowitz} +\item{x}{object of class Markowitz} \item{plot.assets}{if \samp{TRUE} then plot asset \samp{sd} and \samp{er} with asset name labels} Modified: pkg/IntroCompFinR/man/plot.portfolio.Rd =================================================================== --- pkg/IntroCompFinR/man/plot.portfolio.Rd 2015-02-20 06:59:09 UTC (rev 12) +++ pkg/IntroCompFinR/man/plot.portfolio.Rd 2015-02-23 00:43:00 UTC (rev 13) @@ -4,10 +4,10 @@ \alias{plot.portfolio} \title{Plot method of class portfolio} \usage{ -\method{plot}{portfolio}(object, ...) +\method{plot}{portfolio}(x, ...) } \arguments{ -\item{object}{object of class portfolio} +\item{x}{object of class portfolio} \item{...}{additional arguments passed to \samp{barplot()}} } Modified: pkg/IntroCompFinR/man/print.Markowitz.Rd =================================================================== --- pkg/IntroCompFinR/man/print.Markowitz.Rd 2015-02-20 06:59:09 UTC (rev 12) +++ pkg/IntroCompFinR/man/print.Markowitz.Rd 2015-02-23 00:43:00 UTC (rev 13) @@ -4,10 +4,10 @@ \alias{print.Markowitz} \title{Print efficient frontier} \usage{ -\method{print}{Markowitz}(object, ...) +\method{print}{Markowitz}(x, ...) } \arguments{ -\item{object}{object of class Markowitz} +\item{x}{object of class Markowitz} \item{...}{additional arguments passed to \samp{print()}} } Modified: pkg/IntroCompFinR/man/print.portfolio.Rd =================================================================== --- pkg/IntroCompFinR/man/print.portfolio.Rd 2015-02-20 06:59:09 UTC (rev 12) +++ pkg/IntroCompFinR/man/print.portfolio.Rd 2015-02-23 00:43:00 UTC (rev 13) @@ -4,10 +4,10 @@ \alias{print.portfolio} \title{Print method of class portfolio} \usage{ -\method{print}{portfolio}(object, ...) +\method{print}{portfolio}(x, ...) } \arguments{ -\item{object}{object of class portfolio} +\item{x}{object of class portfolio} \item{...}{additional arguments passed to \samp{print()}} } Added: pkg/IntroCompFinR/man/sbuxDailyPrices.Rd =================================================================== --- pkg/IntroCompFinR/man/sbuxDailyPrices.Rd (rev 0) +++ pkg/IntroCompFinR/man/sbuxDailyPrices.Rd 2015-02-23 00:43:00 UTC (rev 13) @@ -0,0 +1,22 @@ +% Generated by roxygen2 (4.1.0): do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\name{sbuxDailyPrices} +\alias{sbuxDailyPrices} +\title{Daily adjusted closing price for Starbucks} +\format{A \samp{xts} object on 1993-01-04 to 2014-12-31 containing: +\describe{ + \item{SBUX}{adjusted closing price in USD} +} +Indexed by objects of class: [Date] TZ: UTC.} +\source{ +Yahoo! Finance: \url{http://finance.yahoo.com/q/hp?s=SBUX+Historical+Prices} +} +\usage{ +sbuxDailyPrices +} +\description{ +A \samp{xts} object of daily adjusted closing price for Starbucks from 1993-01-04 to 2014-12-31. +} +\keyword{datasets} + Added: pkg/IntroCompFinR/man/sbuxMonthlyPrices.Rd =================================================================== --- pkg/IntroCompFinR/man/sbuxMonthlyPrices.Rd (rev 0) +++ pkg/IntroCompFinR/man/sbuxMonthlyPrices.Rd 2015-02-23 00:43:00 UTC (rev 13) @@ -0,0 +1,22 @@ +% Generated by roxygen2 (4.1.0): do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\name{sbuxMonthlyPrices} +\alias{sbuxMonthlyPrices} +\title{Monthly adjusted closing price for Starbucks} +\format{A \samp{xts} object on Jan-1993 to Dec-2014 containing: +\describe{ + \item{SBUX}{adjusted closing price in USD} +} +Indexed by objects of class: [Date] TZ: UTC.} +\source{ +Yahoo! Finance: \url{http://finance.yahoo.com/q/hp?s=SBUX+Historical+Prices} +} +\usage{ +sbuxMonthlyPrices +} +\description{ +A \samp{xts} object of monthly adjusted closing price for Starbucks from Jan-1993 to Dec-2014. +} +\keyword{datasets} + Added: pkg/IntroCompFinR/man/sp500DailyPrices.Rd =================================================================== --- pkg/IntroCompFinR/man/sp500DailyPrices.Rd (rev 0) +++ pkg/IntroCompFinR/man/sp500DailyPrices.Rd 2015-02-23 00:43:00 UTC (rev 13) @@ -0,0 +1,22 @@ +% Generated by roxygen2 (4.1.0): do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\name{sp500DailyPrices} +\alias{sp500DailyPrices} +\title{Daily adjusted closing price for S&P 500} +\format{A \samp{xts} object on 1993-01-04 to 2014-12-31 containing: +\describe{ + \item{SP500}{adjusted closing price in USD} +} +Indexed by objects of class: [Date] TZ: UTC.} +\source{ +Yahoo! Finance: \url{http://finance.yahoo.com/q/hp?s=\%5EGSPC+Historical+Prices} +} +\usage{ +sp500DailyPrices +} +\description{ +A \samp{xts} object of daily adjusted closing price for S&P 500 from 1993-01-04 to 2014-12-31. +} +\keyword{datasets} + Added: pkg/IntroCompFinR/man/sp500MonthlyPrices.Rd =================================================================== --- pkg/IntroCompFinR/man/sp500MonthlyPrices.Rd (rev 0) +++ pkg/IntroCompFinR/man/sp500MonthlyPrices.Rd 2015-02-23 00:43:00 UTC (rev 13) @@ -0,0 +1,22 @@ +% Generated by roxygen2 (4.1.0): do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\name{sp500MonthlyPrices} +\alias{sp500MonthlyPrices} +\title{Monthly adjusted closing price for S&P 500} +\format{A \samp{xts} object on Jan-1993 to Dec-2014 containing: +\describe{ + \item{SP500}{adjusted closing price in USD} +} +Indexed by objects of class: [Date] TZ: UTC.} +\source{ +Yahoo! Finance: \url{http://finance.yahoo.com/q/hp?s=\%5EGSPC+Historical+Prices} +} +\usage{ +sp500MonthlyPrices +} +\description{ +A \samp{xts} object of daily adjusted closing price for S&P 500 from Jan-1993 to Dec-2014. +} +\keyword{datasets} + Modified: pkg/IntroCompFinR/man/summary.Markowitz.Rd =================================================================== --- pkg/IntroCompFinR/man/summary.Markowitz.Rd 2015-02-20 06:59:09 UTC (rev 12) +++ pkg/IntroCompFinR/man/summary.Markowitz.Rd 2015-02-23 00:43:00 UTC (rev 13) @@ -4,12 +4,14 @@ \alias{summary.Markowitz} \title{Summary method of class Markowitz} \usage{ -\method{summary}{Markowitz}(object, risk.free = NULL) +\method{summary}{Markowitz}(object, risk.free = NULL, ...) } \arguments{ \item{object}{object of class Markowitz} \item{risk.free}{numeric, risk free rate} + +\item{...}{additional arguments passed to \samp{summary()}} } \description{ Summary method for objects of class \samp{Markowitz}. For all portfolios on the efficient