[Introcompfinr-commits] r7 - / pkg/IntroCompFinR pkg/IntroCompFinR/R pkg/IntroCompFinR/man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Feb 17 00:06:00 CET 2015


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 <ezivot at uw.edu>
-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


More information about the Introcompfinr-commits mailing list