Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
braverock
GitHub Repository: braverock/portfolioanalytics
Path: blob/master/R/meucci_ranking.R
1433 views
1
2
#' Asset Ranking
3
#'
4
#' Express views on the relative expected asset returns as in A. Meucci,
5
#' "Fully Flexible Views: Theory and Practice" and compute the first
6
#' and second moments.
7
#'
8
#' @note This function is based on the \code{ViewRanking} function written by
9
#' Ram Ahluwalia in the Meucci package.
10
#'
11
#' @param R xts object of asset returns
12
#' @param p a vector of the prior probability values
13
#' @param order a vector of indexes of the relative ranking of expected asset
14
#' returns in ascending order. For example, \code{order = c(2, 3, 1, 4)} means
15
#' that the expected returns of \code{R[,2] < R[,3], < R[,1] < R[,4]}.
16
#'
17
#' @return The estimated moments based on ranking views
18
#'
19
#' @seealso \code{\link{meucci.moments}}
20
#'
21
#' @references
22
#' A. Meucci, "Fully Flexible Views: Theory and Practice" \url{https://www.arpm.co/articles/fully-flexible-views-theory-and-practice/}
23
#' See Meucci script for "RankingInformation/ViewRanking.m"
24
#' @examples
25
#' data(edhec)
26
#' R <- edhec[,1:4]
27
#' p <- rep(1 / nrow(R), nrow(R))
28
#' meucci.ranking(R, p, c(2, 3, 1, 4))
29
#' @export
30
meucci.ranking <- function(R, p, order){
31
R = coredata(R)
32
33
J = nrow( R )
34
N = ncol( R )
35
36
k = length( order )
37
38
# Equality constraints
39
# constrain probabilities to sum to one across all scenarios...
40
# Aeq = ones( 1 , J )
41
Aeq = matrix(rep(1, J), ncol=J)
42
beq = matrix(1, 1)
43
44
# Inequality constraints
45
# ...constrain the expectations... A*x <= 0
46
# Expectation is assigned to each scenario
47
V = R[ , order[1:(k-1)] ] - R[ , order[2:k] ]
48
A = t( V )
49
b = matrix(rep(0, nrow(A)), ncol=1)
50
51
# ...compute posterior probabilities
52
p_ = EntropyProg( p , A , b , Aeq , beq )$p_
53
54
# compute the moments
55
out <- meucci.moments(R, p_)
56
57
return( out )
58
}
59
60