[Returnanalytics-commits] r2185 - in pkg/MPO: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Jul 20 01:48:18 CEST 2012


Author: jamesleehobbs
Date: 2012-07-20 01:48:18 +0200 (Fri, 20 Jul 2012)
New Revision: 2185

Added:
   pkg/MPO/man/TransCostFrontier.Rd
   pkg/MPO/man/TransactionCostOpt.Rd
   pkg/MPO/man/TurnoverFrontier.Rd
Modified:
   pkg/MPO/R/TransactionCostOpt.R
   pkg/MPO/R/TurnoverOpt.R
   pkg/MPO/man/TurnoverOpt.Rd
Log:
-documentation

Modified: pkg/MPO/R/TransactionCostOpt.R
===================================================================
--- pkg/MPO/R/TransactionCostOpt.R	2012-07-19 19:12:28 UTC (rev 2184)
+++ pkg/MPO/R/TransactionCostOpt.R	2012-07-19 23:48:18 UTC (rev 2185)
@@ -1,11 +1,4 @@
-library(xts)
-library(quadprog)
-library(corpcor)
 
-
-
-
-#generic quadratic utility maximization
 UtilityMaximization <- function(returns,lambda,long.only = FALSE){
   nassets <- ncol(returns)
   cov.mat <- cov(returns)
@@ -36,9 +29,26 @@
 }
 
 
-#lambda - risk aversion paramter
-#c - proportional transaction cost
-#TODO - fix long only constraint
+#' Quadratic Portfolio Optimization with transaction costs
+#' 
+#' 2 step utility maximization including tranasaction costs as a penalty
+#' 
+#' @param returns an xts, vector, matrix, data frame, timeSeries or zoo object of
+#' asset returns
+#' @param lambda a risk aversion parameter
+#' @param w.initial initial vector of portfolio weights.  Length of the vector
+#' must be equal to ncol(returns)
+#' @param c transaction costs.  Must be a single value or a vector of length
+#' equal to ncol(returns)
+#' @param long.only optional long only constraint.  Defaults to FALSE
+#' @return returns a list with portfolio weights, return, and variance
+#' @author James Hobbs
+#' @seealso \code{\link{TransCostFrontier}}
+#' 
+#'    data(Returns) 
+#'     opt <- TransactionCostOpt(large.cap.returns,w.initial=rep(1/100,100), 
+#'     lambda=1,c=.0005) 
+#' @export
 TransactionCostOpt <- function(returns,lambda,w.initial,c,long.only = FALSE){
   nassets <- ncol(returns)
   if(length(c)==1){
@@ -58,7 +68,6 @@
   sign.vec[diff<0] <- -1
   c <- c*sign.vec
   
-  #TODO fix this part
   #step 2: optimize with fixed c from step 1
   #this solution will be good as long as no buys or sells flip
   cov.mat <- cov(returns)
@@ -92,7 +101,31 @@
 }
 
 
-#TODO add documentation
+#' Transaction cost penalized portfolio efficient frontier
+#' 
+#' Calculates an efficient frontier of portfolios using transaction costs
+#' as a penalty.
+#' 
+#' @param returns an xts, vector, matrix, data frame, timeSeries or zoo object of
+#' asset returns
+#' @param min.lambda minimum feasible risk aversion parameter to use in optimization
+#' @param max.lambda maximum feasible risk aversion parameter to use in optimization
+#' @param w.initial initial vector of portfolio weights.  Length of the vector
+#' must be equal to ncol(returns)
+#' @param c transaction costs.  Must be a single value or a vector of length
+#' equal to ncol(returns)
+#' @param long.only optional long only constraint.  Defaults to FALSE
+#' @return returns a matrix, with the first column of mean return
+#' second column of portfolio standard deviation, and subsequent columns of
+#' asset weights
+#' @author James Hobbs
+#' @seealso \code{\link{TransactionCostOpt}}
+#' 
+#'  data(Returns) 
+#'    efront <- TransCostFrontier(large.cap.returns,npoints=50,min.lambda=5, 
+#'    max.lambda=1000,w.initial=rep(1/100,100),c=0.0005) 
+#'    plot(x=efront[,"SD"],y=efront[,"MU"],type="l") 
+#'  @export
 TransCostFrontier <- function(returns,npoints = 10, min.lambda, max.lambda,
                               w.initial,c,long.only = FALSE)
 {

Modified: pkg/MPO/R/TurnoverOpt.R
===================================================================
--- pkg/MPO/R/TurnoverOpt.R	2012-07-19 19:12:28 UTC (rev 2184)
+++ pkg/MPO/R/TurnoverOpt.R	2012-07-19 23:48:18 UTC (rev 2185)
@@ -3,7 +3,6 @@
 #' Calculate portfolio weights, variance, and mean return, given a set of 
 #' returns and a constraint on overall turnover
 #' 
-
 #' 
 #' @param returns an xts, vector, matrix, data frame, timeSeries or zoo object of
 #' asset returns
@@ -12,15 +11,19 @@
 #' must be equal to ncol(returns)
 #' @param turnover constraint on turnover from intial weights
 #' @param long.only optional long only constraint.  Defaults to FALSE
+#' @return returns a list with initial weights, buys, sells, and
+#' the aggregate of all three.  Also returns the portfolio's expected
+#' return and variance
 #' @author James Hobbs
+#' @seealso \code{\link{TurnoverFrontier}}
 #' @seealso \code{\link{solve.QP}} 
 #' 
-#' data(Returns)
-#'     opt <- TurnoverOpt(large.cap.returns,mu.target=0.01,
-#'      w.initial = rep(1/100,100),turnover=5)
-#'   		opt$w.total
-#' 			opt$port.var
-#'      opt$port.mu
+#' data(Returns) 
+#'     opt <- TurnoverOpt(large.cap.returns,mu.target=0.01, 
+#'      w.initial = rep(1/100,100),turnover=5) 
+#'   		opt$w.total 
+#' 			opt$port.var 
+#'      opt$port.mu 
 #' @export
 TurnoverOpt <- function(returns,mu.target,w.initial,turnover, long.only = FALSE){
   nassets <- ncol(returns)
@@ -83,7 +86,30 @@
 
 
 
-#TODO add documentation
+#' Turnover constrained portfolio frontier
+#' 
+#' Calculates an efficient frontier of portfolios with a 
+#' constraint on overall turnover
+#' 
+#' @param returns an xts, vector, matrix, data frame, timeSeries or zoo object of
+#' asset returns
+#' @param minmu min feasible target portfolio return to use in optimization
+#' @param maxmu max feasible target portfolio return to use in optimization
+#' @param w.initial initial vector of portfolio weights.  Length of the vector
+#' must be equal to ncol(returns)
+#' @param turnover constraint on turnover from intial weights
+#' @param long.only optional long only constraint.  Defaults to FALSE
+#' @return returns a matrix, with the first column of mean return
+#' second column of portfolio standard deviation, and subsequent columns of
+#' asset weights
+#' @author James Hobbs
+#' @seealso \code{\link{TurnoverOpt}}
+#' 
+#' data(Returns) 
+#'  efront <- TurnoverFrontier(large.cap.returns,npoints=50,minmu=0.001, 
+#'  maxmu=.05, w.initial=rep(1/100,100),turnover=5) 
+#'  plot(x=efront[,"SD"],y=efront[,"MU"],type="l") 
+#' @export
 TurnoverFrontier <- function(returns,npoints = 10, minmu, maxmu,
                              w.initial,turnover,long.only = FALSE)
 {

Added: pkg/MPO/man/TransCostFrontier.Rd
===================================================================
--- pkg/MPO/man/TransCostFrontier.Rd	                        (rev 0)
+++ pkg/MPO/man/TransCostFrontier.Rd	2012-07-19 23:48:18 UTC (rev 2185)
@@ -0,0 +1,47 @@
+\name{TransCostFrontier}
+\alias{TransCostFrontier}
+\title{Transaction cost penalized portfolio efficient frontier}
+\usage{
+  TransCostFrontier(returns, npoints = 10, min.lambda,
+    max.lambda, w.initial, c, long.only = FALSE)
+}
+\arguments{
+  \item{returns}{an xts, vector, matrix, data frame,
+  timeSeries or zoo object of asset returns}
+
+  \item{min.lambda}{minimum feasible risk aversion
+  parameter to use in optimization}
+
+  \item{max.lambda}{maximum feasible risk aversion
+  parameter to use in optimization}
+
+  \item{w.initial}{initial vector of portfolio weights.
+  Length of the vector must be equal to ncol(returns)}
+
+  \item{c}{transaction costs.  Must be a single value or a
+  vector of length equal to ncol(returns)}
+
+  \item{long.only}{optional long only constraint.  Defaults
+  to FALSE}
+}
+\value{
+  returns a matrix, with the first column of mean return
+  second column of portfolio standard deviation, and
+  subsequent columns of asset weights
+}
+\description{
+  Calculates an efficient frontier of portfolios using
+  transaction costs as a penalty.
+}
+\author{
+  James Hobbs
+}
+\seealso{
+  \code{\link{TransactionCostOpt}}
+
+  data(Returns) efront <-
+  TransCostFrontier(large.cap.returns,npoints=50,min.lambda=5,
+  max.lambda=1000,w.initial=rep(1/100,100),c=0.0005)
+  plot(x=efront[,"SD"],y=efront[,"MU"],type="l")
+}
+

Added: pkg/MPO/man/TransactionCostOpt.Rd
===================================================================
--- pkg/MPO/man/TransactionCostOpt.Rd	                        (rev 0)
+++ pkg/MPO/man/TransactionCostOpt.Rd	2012-07-19 23:48:18 UTC (rev 2185)
@@ -0,0 +1,41 @@
+\name{TransactionCostOpt}
+\alias{TransactionCostOpt}
+\title{Quadratic Portfolio Optimization with transaction costs}
+\usage{
+  TransactionCostOpt(returns, lambda, w.initial, c,
+    long.only = FALSE)
+}
+\arguments{
+  \item{returns}{an xts, vector, matrix, data frame,
+  timeSeries or zoo object of asset returns}
+
+  \item{lambda}{a risk aversion parameter}
+
+  \item{w.initial}{initial vector of portfolio weights.
+  Length of the vector must be equal to ncol(returns)}
+
+  \item{c}{transaction costs.  Must be a single value or a
+  vector of length equal to ncol(returns)}
+
+  \item{long.only}{optional long only constraint.  Defaults
+  to FALSE}
+}
+\value{
+  returns a list with portfolio weights, return, and
+  variance
+}
+\description{
+  2 step utility maximization including tranasaction costs
+  as a penalty
+}
+\author{
+  James Hobbs
+}
+\seealso{
+  \code{\link{TransCostFrontier}}
+
+  data(Returns) opt <-
+  TransactionCostOpt(large.cap.returns,w.initial=rep(1/100,100),
+  lambda=1,c=.0005)
+}
+

Added: pkg/MPO/man/TurnoverFrontier.Rd
===================================================================
--- pkg/MPO/man/TurnoverFrontier.Rd	                        (rev 0)
+++ pkg/MPO/man/TurnoverFrontier.Rd	2012-07-19 23:48:18 UTC (rev 2185)
@@ -0,0 +1,47 @@
+\name{TurnoverFrontier}
+\alias{TurnoverFrontier}
+\title{Turnover constrained portfolio frontier}
+\usage{
+  TurnoverFrontier(returns, npoints = 10, minmu, maxmu,
+    w.initial, turnover, long.only = FALSE)
+}
+\arguments{
+  \item{returns}{an xts, vector, matrix, data frame,
+  timeSeries or zoo object of asset returns}
+
+  \item{minmu}{min feasible target portfolio return to use
+  in optimization}
+
+  \item{maxmu}{max feasible target portfolio return to use
+  in optimization}
+
+  \item{w.initial}{initial vector of portfolio weights.
+  Length of the vector must be equal to ncol(returns)}
+
+  \item{turnover}{constraint on turnover from intial
+  weights}
+
+  \item{long.only}{optional long only constraint.  Defaults
+  to FALSE}
+}
+\value{
+  returns a matrix, with the first column of mean return
+  second column of portfolio standard deviation, and
+  subsequent columns of asset weights
+}
+\description{
+  Calculates an efficient frontier of portfolios with a
+  constraint on overall turnover
+}
+\author{
+  James Hobbs
+}
+\seealso{
+  \code{\link{TurnoverOpt}}
+
+  data(Returns) efront <-
+  TurnoverFrontier(large.cap.returns,npoints=50,minmu=0.001,
+  maxmu=.05, w.initial=rep(1/100,100),turnover=5)
+  plot(x=efront[,"SD"],y=efront[,"MU"],type="l")
+}
+

Modified: pkg/MPO/man/TurnoverOpt.Rd
===================================================================
--- pkg/MPO/man/TurnoverOpt.Rd	2012-07-19 19:12:28 UTC (rev 2184)
+++ pkg/MPO/man/TurnoverOpt.Rd	2012-07-19 23:48:18 UTC (rev 2185)
@@ -20,6 +20,11 @@
   \item{long.only}{optional long only constraint.  Defaults
   to FALSE}
 }
+\value{
+  returns a list with initial weights, buys, sells, and the
+  aggregate of all three.  Also returns the portfolio's
+  expected return and variance
+}
 \description{
   Calculate portfolio weights, variance, and mean return,
   given a set of returns and a constraint on overall
@@ -29,6 +34,8 @@
   James Hobbs
 }
 \seealso{
+  \code{\link{TurnoverFrontier}}
+
   \code{\link{solve.QP}}
 
   data(Returns) opt <-



More information about the Returnanalytics-commits mailing list