[Returnanalytics-commits] r3448 - in pkg/PortfolioAnalytics: . R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun Jun 29 19:42:14 CEST 2014
Author: rossbennett34
Date: 2014-06-29 19:42:14 +0200 (Sun, 29 Jun 2014)
New Revision: 3448
Added:
pkg/PortfolioAnalytics/man/EntropyProg.Rd
pkg/PortfolioAnalytics/man/meucci.moments.Rd
pkg/PortfolioAnalytics/man/meucci.ranking.Rd
Modified:
pkg/PortfolioAnalytics/NAMESPACE
pkg/PortfolioAnalytics/R/EntropyProg.R
pkg/PortfolioAnalytics/R/meucci_moments.R
pkg/PortfolioAnalytics/R/meucci_ranking.R
Log:
Adding man files and minor fixes for the meucci functions
Modified: pkg/PortfolioAnalytics/NAMESPACE
===================================================================
--- pkg/PortfolioAnalytics/NAMESPACE 2014-06-29 16:18:42 UTC (rev 3447)
+++ pkg/PortfolioAnalytics/NAMESPACE 2014-06-29 17:42:14 UTC (rev 3448)
@@ -69,6 +69,7 @@
S3method(summary,portfolio)
S3method(update,constraint)
export(CCCgarch.MM)
+export(EntropyProg)
export(HHI)
export(add.constraint)
export(add.objective)
@@ -118,6 +119,8 @@
export(leverage_exposure_constraint)
export(meanetl.efficient.frontier)
export(meanvar.efficient.frontier)
+export(meucci.moments)
+export(meucci.ranking)
export(minmax_objective)
export(mult.portfolio.spec)
export(objective)
Modified: pkg/PortfolioAnalytics/R/EntropyProg.R
===================================================================
--- pkg/PortfolioAnalytics/R/EntropyProg.R 2014-06-29 16:18:42 UTC (rev 3447)
+++ pkg/PortfolioAnalytics/R/EntropyProg.R 2014-06-29 17:42:14 UTC (rev 3448)
@@ -75,11 +75,11 @@
# set up print arguments for verbose
if(verbose){
+ check_derivatives_print = "all"
+ print_level = 2
+ } else {
check_derivatives_print = "none"
print_level = 0
- } else {
- check_derivatives_print = "all"
- print_level = 2
}
if ( !K_ ) # equality constraints only
Modified: pkg/PortfolioAnalytics/R/meucci_moments.R
===================================================================
--- pkg/PortfolioAnalytics/R/meucci_moments.R 2014-06-29 16:18:42 UTC (rev 3447)
+++ pkg/PortfolioAnalytics/R/meucci_moments.R 2014-06-29 17:42:14 UTC (rev 3448)
@@ -5,7 +5,7 @@
#' Compute the first and second moments using the Fully Flexible Views
#' framework as described in A. Meucci - "Fully Flexible Views: Theory and Practice".
#'
-#' @param R xts of asset returns
+#' @param R xts object of asset returns
#' @param p vector of posterior probabilities
#' @return a list with the first and second moments
#' \itemize{
@@ -17,12 +17,12 @@
#' @author Ross Bennett
#' @export
meucci.moments <- function(R, p){
- R <- coredata(R)
+ R = coredata(R)
# expected return vector
- mu <- t(R) %*% posterior_probs
+ mu = t(R) %*% p
# covariance matrix
- Scnd_Mom = t(R) %*% (R * (posterior_probs %*% matrix( 1, 1, ncol(R))))
+ Scnd_Mom = t(R) %*% (R * (p %*% matrix( 1, 1, ncol(R))))
Scnd_Mom = ( Scnd_Mom + t(Scnd_Mom) ) / 2
sigma = Scnd_Mom - mu %*% t(mu)
list(mu=mu, sigma=sigma)
Modified: pkg/PortfolioAnalytics/R/meucci_ranking.R
===================================================================
--- pkg/PortfolioAnalytics/R/meucci_ranking.R 2014-06-29 16:18:42 UTC (rev 3447)
+++ pkg/PortfolioAnalytics/R/meucci_ranking.R 2014-06-29 17:42:14 UTC (rev 3448)
@@ -21,7 +21,7 @@
#' @references
#' A. Meucci, "Fully Flexible Views: Theory and Practice" \url{http://www.symmys.com/node/158}
#' See Meucci script for "RankingInformation/ViewRanking.m"
-#' @example
+#' @examples
#' data(edhec)
#' R <- edhec[,1:4]
#' p <- rep(1 / nrow(R), nrow(R))
@@ -38,7 +38,7 @@
# Equality constraints
# constrain probabilities to sum to one across all scenarios...
# Aeq = ones( 1 , J )
- Aeq = matrix(rep(1, J), nrow=J)
+ Aeq = matrix(rep(1, J), ncol=J)
beq = matrix(1, 1)
# Inequality constraints
@@ -49,7 +49,7 @@
b = matrix(rep(0, nrow(A)), ncol=1)
# ...compute posterior probabilities
- p_ = EntropyProg( p , A , b , Aeq , beq )
+ p_ = EntropyProg( p , A , b , Aeq , beq )$p_
# compute the moments
out <- meucci.moments(R, p_)
Added: pkg/PortfolioAnalytics/man/EntropyProg.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/EntropyProg.Rd (rev 0)
+++ pkg/PortfolioAnalytics/man/EntropyProg.Rd 2014-06-29 17:42:14 UTC (rev 3448)
@@ -0,0 +1,68 @@
+% Generated by roxygen2 (4.0.1): do not edit by hand
+\name{EntropyProg}
+\alias{EntropyProg}
+\title{Entropy pooling program for blending views on scenarios with a prior scenario-probability distribution}
+\usage{
+EntropyProg(p, A = NULL, b = NULL, Aeq, beq, verbose = FALSE)
+}
+\arguments{
+\item{p}{a vector of initial probabilities based on prior (reference model, empirical distribution, etc.). Sum of 'p' must be 1}
+
+\item{Aeq}{matrix consisting of equality constraints (paired with argument 'beq'). Denoted as 'H' in the Meucci paper. (denoted as 'H' in the "Meucci - Flexible Views Theory & Practice" paper formlua 86 on page 22)}
+
+\item{beq}{vector corresponding to the matrix of equality constraints (paired with argument 'Aeq'). Denoted as 'h' in the Meucci paper}
+
+\item{A}{matrix consisting of inequality constraints (paired with argument 'b'). Denoted as 'F' in the Meucci paper}
+
+\item{b}{vector consisting of inequality constraints (paired with matrix A). Denoted as 'f' in the Meucci paper}
+
+\item{verbose}{If TRUE, prints out additional information. Default FALSE.
+
+' \deqn{ \tilde{p} \equiv argmin_{Fx \leq f, Hx \equiv h} \big\{ \sum_1^J x_{j} \big(ln \big( x_{j} \big) - ln \big( p_{j} \big) \big) \big\}
+\\ \ell \big(x, \lambda, \nu \big) \equiv x' \big(ln \big(x\big) - ln \big(p\big) \big) + \lambda' \big(Fx - f\big) + \nu' \big(Hx - h\big)}}
+}
+\value{
+a list with
+\itemize{
+ \item{\code{p_}:}{ revised probabilities based on entropy pooling}
+ \item{\code{optimizationPerformance}:}{ a list with status of optimization,
+ value, number of iterations, and sum of probabilities}
+}
+}
+\description{
+Entropy program will change the initial predictive distribution 'p' to a new set 'p_' that satisfies
+specified moment conditions but changes other propoerties of the new distribution the least by
+minimizing the relative entropy between the two distributions. Theoretical note: Relative Entropy (Kullback-Leibler information criterion KLIC) is an
+asymmetric measure.
+}
+\details{
+We retrieve a new set of probabilities for the joint-scenarios using the Entropy pooling method
+Of the many choices of 'p' that satisfy the views, we choose 'p' that minimize the entropy or distance of the new probability
+distribution to the prior joint-scenario probabilities.
+
+We use Kullback-Leibler divergence or relative entropy dist(p,q): Sum across all scenarios [ p-t * ln( p-t / q-t ) ]
+Therefore we define solution as p* = argmin (choice of p ) [ sum across all scenarios: p-t * ln( p-t / q-t) ],
+such that 'p' satisfies views. The views modify the prior in a cohrent manner (minimizing distortion)
+We forumulate the stress tests of the baseline scenarios as linear constraints on yet-to-be defined probabilities
+Note that the numerical optimization acts on a very limited number of variables equal
+to the number of views. It does not act directly on the very large number of variables
+of interest, namely the probabilities of the Monte Carlo scenarios. This feature guarantees
+the numerical feasability of entropy optimization.
+
+Note that new probabilities are generated in much the same way that the state-price density modifies
+objective probabilities of pay-offs to risk-neutral probabilities in contingent-claims asset pricing
+
+Compute posterior (=change of measure) with Entropy Pooling, as described in
+}
+\author{
+Ram Ahluwalia \email{ram at wingedfootcapital.com}
+}
+\references{
+A. Meucci - "Fully Flexible Views: Theory and Practice". See page 22 for illustration of numerical implementation
+Symmys site containing original MATLAB source code \url{http://www.symmys.com}
+NLOPT open-source optimization site containing background on algorithms \url{http://ab-initio.mit.edu/wiki/index.php/NLopt}
+We use the information-theoretic estimator of Kitamur and Stutzer (1997).
+Reversing 'p' and 'p_' leads to the empirical likelihood" estimator of Qin and Lawless (1994).
+See Robertson et al, "Forecasting Using Relative Entropy" (2002) for more theory
+}
+
Added: pkg/PortfolioAnalytics/man/meucci.moments.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/meucci.moments.Rd (rev 0)
+++ pkg/PortfolioAnalytics/man/meucci.moments.Rd 2014-06-29 17:42:14 UTC (rev 3448)
@@ -0,0 +1,30 @@
+% Generated by roxygen2 (4.0.1): do not edit by hand
+\name{meucci.moments}
+\alias{meucci.moments}
+\title{Compute moments}
+\usage{
+meucci.moments(R, p)
+}
+\arguments{
+\item{R}{xts object of asset returns}
+
+\item{p}{vector of posterior probabilities}
+}
+\value{
+a list with the first and second moments
+\itemize{
+ \item{\code{mu}: }{vector of expected returns}
+ \item{\code{sigma}: }{covariance matrix}
+}
+}
+\description{
+Compute the first and second moments using the Fully Flexible Views
+framework as described in A. Meucci - "Fully Flexible Views: Theory and Practice".
+}
+\author{
+Ross Bennett
+}
+\references{
+A. Meucci - "Fully Flexible Views: Theory and Practice".
+}
+
Added: pkg/PortfolioAnalytics/man/meucci.ranking.Rd
===================================================================
--- pkg/PortfolioAnalytics/man/meucci.ranking.Rd (rev 0)
+++ pkg/PortfolioAnalytics/man/meucci.ranking.Rd 2014-06-29 17:42:14 UTC (rev 3448)
@@ -0,0 +1,42 @@
+% Generated by roxygen2 (4.0.1): do not edit by hand
+\name{meucci.ranking}
+\alias{meucci.ranking}
+\title{Asset Ranking}
+\usage{
+meucci.ranking(R, p, order)
+}
+\arguments{
+\item{R}{xts object of asset returns}
+
+\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]}.}
+}
+\value{
+The estimated moments based on ranking views
+}
+\description{
+Express views on the relative expected asset returns as in A. Meucci,
+"Fully Flexible Views: Theory and Practice" and compute the first
+and second moments.
+}
+\note{
+This function is based on the \code{ViewRanking} function written by
+Ram Ahluwalia in the Meucci package.
+}
+\examples{
+data(edhec)
+R <- edhec[,1:4]
+p <- rep(1 / nrow(R), nrow(R))
+meucci.ranking(R, p, c(2, 3, 1, 4))
+}
+\references{
+A. Meucci, "Fully Flexible Views: Theory and Practice" \url{http://www.symmys.com/node/158}
+See Meucci script for "RankingInformation/ViewRanking.m"
+}
+\seealso{
+\code{\link{meucci.moments}}
+}
+
More information about the Returnanalytics-commits
mailing list