1#' Asset Ranking2#'3#' Express views on the relative expected asset returns as in A. Meucci,4#' "Fully Flexible Views: Theory and Practice" and compute the first5#' and second moments.6#'7#' @note This function is based on the \code{ViewRanking} function written by8#' Ram Ahluwalia in the Meucci package.9#'10#' @param R xts object of asset returns11#' @param p a vector of the prior probability values12#' @param order a vector of indexes of the relative ranking of expected asset13#' returns in ascending order. For example, \code{order = c(2, 3, 1, 4)} means14#' that the expected returns of \code{R[,2] < R[,3], < R[,1] < R[,4]}.15#'16#' @return The estimated moments based on ranking views17#'18#' @seealso \code{\link{meucci.moments}}19#'20#' @references21#' A. Meucci, "Fully Flexible Views: Theory and Practice" \url{https://www.arpm.co/articles/fully-flexible-views-theory-and-practice/}22#' See Meucci script for "RankingInformation/ViewRanking.m"23#' @examples24#' data(edhec)25#' R <- edhec[,1:4]26#' p <- rep(1 / nrow(R), nrow(R))27#' meucci.ranking(R, p, c(2, 3, 1, 4))28#' @export29meucci.ranking <- function(R, p, order){30R = coredata(R)3132J = nrow( R )33N = ncol( R )3435k = length( order )3637# Equality constraints38# constrain probabilities to sum to one across all scenarios...39# Aeq = ones( 1 , J )40Aeq = matrix(rep(1, J), ncol=J)41beq = matrix(1, 1)4243# Inequality constraints44# ...constrain the expectations... A*x <= 045# Expectation is assigned to each scenario46V = R[ , order[1:(k-1)] ] - R[ , order[2:k] ]47A = t( V )48b = matrix(rep(0, nrow(A)), ncol=1)4950# ...compute posterior probabilities51p_ = EntropyProg( p , A , b , Aeq , beq )$p_5253# compute the moments54out <- meucci.moments(R, p_)5556return( out )57}585960