#' @title Optimal Portfolio Weights and Performance Values1#'2#' @description Converts output of `optimize.portfolio` to a list of the3#' portfolio weights, mean, volatility and Sharpe Ratio.4#'5#' @param opt List output of `optimize.portfolio`6#' @param returns Multivariate xts object of portfolio assets returns7#' @param digits Integer number of significant digits with default NULL8#' @param annualize Logical with default TRUE9#' @param frequency Returns frequency: "monthly", "weekly" or "daily"10#' @param rf Numeric value with default 0.011#'12#' @details This function uses the weights returned by optimize.portfolio,13#' along with the portfolio assets returns, and a risk-free rate, to14#' to compute the portfolio mean return, volatility, and Sharpe Ratio.15#'16#' @return A list containing the portfolio numeric weights, mean value,17#' volatility and Sharpe Ratio.18#'19#' @author R. Douglas Martin20#' @export21#'22#' @examples23#' args(opt.outputMvo)24opt.outputMvo <- function(opt, returns, digits = NULL, annualize = TRUE,25frequency = "monthly", rf = 0.0)26{27if(class(returns)[1] == "xts"){28returns <- coredata(returns)29}30Wgts <- opt$weights31sigmasq <- as.numeric(t(Wgts) %*% var(returns) %*% Wgts)32StdDev <- sqrt(sigmasq)33mu.ret <- apply(returns, 2, mean)34Mean <- as.numeric(t(Wgts) %*% mu.ret)35SR <- (Mean - rf)/StdDev36a <- 1; b <- 137if(annualize){38if(frequency == "monthly"){39a <- 12; b <- sqrt(12)40} else if(frequency == "weekly"){41a <- 52; b <- sqrt(52)42} else {43a <- 260; b <- sqrt(260)44}45}46Mean <- a*Mean47StdDev <- b*StdDev48SR <- b*SR4950output <- list(Wgts = Wgts, Mean = Mean, StdDev = StdDev, SR = SR)51if (!is.null(digits)) {52output <- lapply(output, round, digits)53}54output55}565758###############################################################################59# R (https://r-project.org/) Numeric Methods for Optimization of Portfolios60#61# Copyright (c) 2004-2023 R. Douglas Martin62#63# This library is distributed under the terms of the GNU Public License (GPL)64# for full details see the file COPYING65#66# $Id$67#68###############################################################################6970