12#' Compute moments3#'4#' Compute the first and second moments using the Fully Flexible Views5#' framework as described in A. Meucci - "Fully Flexible Views: Theory and Practice".6#'7#' @param R xts object of asset returns8#' @param posterior_p vector of posterior probabilities9#' @return a list with the first and second moments10#' \describe{11#' \item{\code{mu}: }{vector of expected returns}12#' \item{\code{sigma}: }{covariance matrix}13#' }14#' @references15#' A. Meucci - "Fully Flexible Views: Theory and Practice".16#' @author Ross Bennett17#' @export18meucci.moments <- function(R, posterior_p){19R = coredata(R)20# expected return vector21mu = t(R) %*% posterior_p2223# covariance matrix24Scnd_Mom = t(R) %*% (R * (posterior_p %*% matrix( 1, 1, ncol(R))))25Scnd_Mom = ( Scnd_Mom + t(Scnd_Mom) ) / 226sigma = Scnd_Mom - mu %*% t(mu)27list(mu=mu, sigma=sigma)28}293031