[Returnanalytics-commits] r3455 - in pkg/PortfolioAnalytics: . R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jul 1 21:45:57 CEST 2014


Author: rossbennett34
Date: 2014-07-01 21:45:57 +0200 (Tue, 01 Jul 2014)
New Revision: 3455

Added:
   pkg/PortfolioAnalytics/R/ac_ranking.R
   pkg/PortfolioAnalytics/man/ac.ranking.Rd
Modified:
   pkg/PortfolioAnalytics/NAMESPACE
   pkg/PortfolioAnalytics/R/meucci_ranking.R
   pkg/PortfolioAnalytics/man/meucci.ranking.Rd
Log:
Add functions for ranking views based on Almgren and Chriss paper. Fixed a typo in meucci.ranking function.

Modified: pkg/PortfolioAnalytics/NAMESPACE
===================================================================
--- pkg/PortfolioAnalytics/NAMESPACE	2014-07-01 17:27:29 UTC (rev 3454)
+++ pkg/PortfolioAnalytics/NAMESPACE	2014-07-01 19:45:57 UTC (rev 3455)
@@ -71,6 +71,7 @@
 export(CCCgarch.MM)
 export(EntropyProg)
 export(HHI)
+export(ac.ranking)
 export(add.constraint)
 export(add.objective)
 export(add.objective_v1)

Added: pkg/PortfolioAnalytics/R/ac_ranking.R
===================================================================
--- pkg/PortfolioAnalytics/R/ac_ranking.R	                        (rev 0)
+++ pkg/PortfolioAnalytics/R/ac_ranking.R	2014-07-01 19:45:57 UTC (rev 3455)
@@ -0,0 +1,76 @@
+
+#' Asset Ranking
+#' 
+#' Compute the first moment from a single complete sort
+#' 
+#' This function computes the estimated centroid vector from a single complete
+#' sort using the analytical approximation as described in R. Almgren and 
+#' N. Chriss, "Portfolios from Sorts". The centroid is estimated and then 
+#' scaled such that it is on a scale similar to the asset returns. By default,
+#' the centroid vector is scaled according to the median of the asset mean 
+#' returns.
+#' 
+#' @param R xts object of asset returns
+#' @param order a vector of indexes of the relative ranking of expected asset 
+#' returns in ascending order. For example, \code{order = c(2, 3, 1, 4)} means 
+#' that the expected returns of \code{R[,2] < R[,3], < R[,1] < R[,4]}.
+#' @param \dots any other passthrough parameters
+#' 
+#' @return The estimated first moments based on ranking views
+#'  
+#' @references 
+#' R. Almgren and N. Chriss, "Portfolios from Sorts" 
+#' \url{http://papers.ssrn.com/sol3/papers.cfm?abstract_id=720041}
+#' 
+#' @examples
+#' data(edhec)
+#' R <- edhec[,1:4]
+#' ac.ranking(R, c(2, 3, 1, 4))
+#' @export
+ac.ranking  <- function(R, order, ...){
+  if(length(order) != ncol(R)) stop("The length of the order vector must equal the number of assets")
+  nassets <- ncol(R)
+  if(hasArg(max.value)) {
+    max.value <- match.call(expand.dots=TRUE)$max.value
+  } else {
+    max.value <- median(colMeans(R))
+  }
+  # Compute the scaled centroid
+  c_hat <- scale.range(centroid(nassets), max.value)
+  
+  # Here we reorder the vector such that the highest centroid value is assigned
+  # to the asset index with the highest expected return and so on and so forth
+  # until the smallest centroid value is assigned to the asset index with the 
+  # lowest expected return. The asset index with the lowest expected return
+  # is order[1]
+  out <- vector("numeric", nassets)
+  out[rev(order)] <- c_hat
+  return(out)
+}
+
+# compute the centroid for a single complete sort
+centroid <- function(n){
+  # Analytical solution to the centroid for single complete sort
+  # http://papers.ssrn.com/sol3/papers.cfm?abstract_id=720041
+  A <- 0.4424
+  B <- 0.1185
+  beta <- 0.21
+  alpha <- A - B * n^(-beta)
+  j <- seq(from=1, to=n, by=1)
+  c_hat <- qnorm((n + 1 - j - alpha) / (n - 2 * alpha + 1))
+  c_hat
+}
+
+# If we used the unscaled centroid vector in the optimization, the optimal
+# portfolio would be correct but anything that uses moments$mu will not make
+# sense
+
+# What is a valid value for max.value?
+# - by default we use the median of the asset mean returns
+scale.range <- function(x, max.value){
+  new.max <- 0.05
+  new.min <- -new.max
+  old.range <- max(x) - min(x)
+  new.range <- new.max - new.min
+  ((x - min(x)) * new.range) / old.range + new.min
+}

Modified: pkg/PortfolioAnalytics/R/meucci_ranking.R
===================================================================
--- pkg/PortfolioAnalytics/R/meucci_ranking.R	2014-07-01 17:27:29 UTC (rev 3454)
+++ pkg/PortfolioAnalytics/R/meucci_ranking.R	2014-07-01 19:45:57 UTC (rev 3455)
@@ -10,9 +10,9 @@
 #' 
 #' @param R xts object of asset returns
 #' @param p a vector of the prior probability values
-#' @param order a vector of indexes of the relative of expected asset returns in
-#' ascending order. For example, \code{order = c(2, 3, 1, 4)} means that the 
-#' expected returns of \code{R[,2] < R[,3], < R[,1] < R[,4]}.
+#' @param order a vector of indexes of the relative ranking of expected asset 
+#' returns in ascending order. For example, \code{order = c(2, 3, 1, 4)} means 
+#' that the expected returns of \code{R[,2] < R[,3], < R[,1] < R[,4]}.
 #' 
 #' @return The estimated moments based on ranking views
 #' 

Added: pkg/PortfolioAnalytics/man/ac.ranking.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/ac.ranking.Rd	                        (rev 0)
+++ pkg/PortfolioAnalytics/man/ac.ranking.Rd	2014-07-01 19:45:57 UTC (rev 3455)
@@ -0,0 +1,40 @@
+% Generated by roxygen2 (4.0.1): do not edit by hand
+\name{ac.ranking}
+\alias{ac.ranking}
+\title{Asset Ranking}
+\usage{
+ac.ranking(R, order, ...)
+}
+\arguments{
+\item{R}{xts object of asset returns}
+
+\item{order}{a vector of indexes of the relative ranking of expected asset
+returns in ascending order. For example, \code{order = c(2, 3, 1, 4)} means
+that the expected returns of \code{R[,2] < R[,3], < R[,1] < R[,4]}.}
+
+\item{\dots}{any other passthrough parameters}
+}
+\value{
+The estimated first moments based on ranking views
+}
+\description{
+Compute the first moment from a single complete sort
+}
+\details{
+This function computes the estimated centroid vector from a single complete
+sort using the analytical approximation as described in R. Almgren and
+N. Chriss, "Portfolios from Sorts". The centroid is estimated and then
+scaled such that it is on a scale similar to the asset returns. By default,
+the centroid vector is scaled according to the median of the asset mean
+returns.
+}
+\examples{
+data(edhec)
+R <- edhec[,1:4]
+ac.ranking(R, c(2, 3, 1, 4))
+}
+\references{
+R. Almgren and N. Chriss, "Portfolios from Sorts"
+\url{http://papers.ssrn.com/sol3/papers.cfm?abstract_id=720041}
+}
+

Modified: pkg/PortfolioAnalytics/man/meucci.ranking.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/meucci.ranking.Rd	2014-07-01 17:27:29 UTC (rev 3454)
+++ pkg/PortfolioAnalytics/man/meucci.ranking.Rd	2014-07-01 19:45:57 UTC (rev 3455)
@@ -10,9 +10,9 @@
 
 \item{p}{a vector of the prior probability values}
 
-\item{order}{a vector of indexes of the relative of expected asset returns in
-ascending order. For example, \code{order = c(2, 3, 1, 4)} means that the
-expected returns of \code{R[,2] < R[,3], < R[,1] < R[,4]}.}
+\item{order}{a vector of indexes of the relative ranking of expected asset
+returns in ascending order. For example, \code{order = c(2, 3, 1, 4)} means
+that the expected returns of \code{R[,2] < R[,3], < R[,1] < R[,4]}.}
 }
 \value{
 The estimated moments based on ranking views



More information about the Returnanalytics-commits mailing list