[Returnanalytics-commits] r2217 - in pkg/PerformanceAnalytics/sandbox/Meucci: . R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Jul 28 01:41:28 CEST 2012


Author: braverock
Date: 2012-07-28 01:41:27 +0200 (Sat, 28 Jul 2012)
New Revision: 2217

Added:
   pkg/PerformanceAnalytics/sandbox/Meucci/NAMESPACE
Modified:
   pkg/PerformanceAnalytics/sandbox/Meucci/DESCRIPTION
   pkg/PerformanceAnalytics/sandbox/Meucci/R/CmaCopula.R
   pkg/PerformanceAnalytics/sandbox/Meucci/R/EntropyProg.R
   pkg/PerformanceAnalytics/sandbox/Meucci/R/HermiteGrid.R
   pkg/PerformanceAnalytics/sandbox/Meucci/R/InvariantProjection.R
   pkg/PerformanceAnalytics/sandbox/Meucci/R/RankingInformation.R
   pkg/PerformanceAnalytics/sandbox/Meucci/R/logToArithmeticCovariance.R
   pkg/PerformanceAnalytics/sandbox/Meucci/man/EntropyProg.Rd
Log:
- updates to get closer to passing R CMD check


Modified: pkg/PerformanceAnalytics/sandbox/Meucci/DESCRIPTION
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Meucci/DESCRIPTION	2012-07-27 21:10:24 UTC (rev 2216)
+++ pkg/PerformanceAnalytics/sandbox/Meucci/DESCRIPTION	2012-07-27 23:41:27 UTC (rev 2217)
@@ -1,23 +1,35 @@
-Package: Meucci
-Type: Package
-Title: Econometric tools for performance and risk analysis.
-Version: 0.1
-Date: $Date: 2012-06-06 15:18:48 -0500 (Wed, 06 Jun 2012) $
-Author: Ram Ahluwalia, Manan Shah
-Maintainer: Brian G. Peterson <brian at braverock.com>
-Description: stub for Meucci
-Depends: R (>= 2.14.0), zoo, xts (>= 0.8), matlab, ggplot2, MASS, pracma, Hmisc, Matrix, nloptr, limSolve,moments, quadprog
-License: GPL
-URL: http://r-forge.r-project.org/projects/returnanalytics/
-Copyright: (c) 2004-2012
-Collate:
-    'CmaCopula.R'
-    'DetectOutliersviaMVE.R'
-    'EntropyProg.R'
-    'FullyFlexibleBayesNets.R'
-    'HermiteGrid.R'
-    'InvariantProjection.R'
-    'logToArithmeticCovariance.R'
-    'Prior2Posterior.R'
-    'RankingInformation.R'
-    'RobustBayesianAllocation.R'
+Package: Meucci
+Type: Package
+Title: Econometric tools for performance and risk analysis.
+Version: 0.1
+Date: $Date: 2012-06-06 15:18:48 -0500 (Wed, 06 Jun 2012) $
+Author: Ram Ahluwalia, Manan Shah
+Maintainer: Brian G. Peterson <brian at braverock.com>
+Description: stub for Meucci
+Depends:
+    R (>= 2.14.0),
+    zoo,
+    xts (>= 0.8),
+    matlab,
+    ggplot2,
+    MASS,
+    pracma,
+    Hmisc,
+    Matrix,
+    nloptr,
+    limSolve,moments,
+    quadprog
+License: GPL
+URL: http://r-forge.r-project.org/projects/returnanalytics/
+Copyright: (c) 2004-2012
+Collate:
+    'CmaCopula.R'
+    'DetectOutliersviaMVE.R'
+    'EntropyProg.R'
+    'FullyFlexibleBayesNets.R'
+    'HermiteGrid.R'
+    'InvariantProjection.R'
+    'logToArithmeticCovariance.R'
+    'Prior2Posterior.R'
+    'RankingInformation.R'
+    'RobustBayesianAllocation.R'

Added: pkg/PerformanceAnalytics/sandbox/Meucci/NAMESPACE
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Meucci/NAMESPACE	                        (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/Meucci/NAMESPACE	2012-07-27 23:41:27 UTC (rev 2217)
@@ -0,0 +1,28 @@
+export(Central2Raw)
+export(CMAcombination)
+export(CMAseparation)
+export(ComputeMoments)
+export(ComputeMVE)
+export(CondProbViews)
+export(Cumul2Raw)
+export(DetectOutliersViaMVE)
+export(EntropyProg)
+export(GenerateLogNormalDistribution)
+export(hermitePolynomial)
+export(integrateSubIntervals)
+export(linreturn)
+export(MvnRnd)
+export(NoisyObservations)
+export(normalizeProb)
+export(PanicCopula)
+export(PartialConfidencePosterior)
+export(PlotDistributions)
+export(Raw2Central)
+export(Raw2Cumul)
+export(RejectOutlier)
+export(RIEfficientFrontier)
+export(robustBayesianPortfolioOptimization)
+export(std)
+export(subIntervals)
+export(SummStats)
+export(Tweak)

Modified: pkg/PerformanceAnalytics/sandbox/Meucci/R/CmaCopula.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Meucci/R/CmaCopula.R	2012-07-27 21:10:24 UTC (rev 2216)
+++ pkg/PerformanceAnalytics/sandbox/Meucci/R/CmaCopula.R	2012-07-27 23:41:27 UTC (rev 2217)
@@ -18,6 +18,7 @@
 #' \url{http://www.symmys.com}
 #' TODO: Add Schur decomposition. Right now function is only sampling from mvrnorm so sample moments do no match population moments
 #' I have sample code commented out below to implement this correctly but I require a function that returns the unitaryMatrix from a Schur decomposition
+#' @export
 MvnRnd = function( M , S , J )
 {
   library(MASS)
@@ -71,6 +72,7 @@
 #' @references 
 #' Meucci A., "New Breed of Copulas for Risk and Portfolio  Management", Risk, September 2011
 #' Most recent version of article and code available at \url{http://www.symmys.com/node/335}
+#' @export
 CMAseparation = function( X , p ) 
 {
 # @example     test = cbind( seq( 102 , 1 , -2 ) , seq( 100 , 500 , 8 ) )
@@ -137,6 +139,7 @@
 #' @references 
 #' Meucci A., "New Breed of Copulas for Risk and Portfolio  Management", Risk, September 2011
 #' Most recent version of article and code available at \url{http://www.symmys.com/node/335}
+#' @export
 CMAcombination = function( x , u , U ) 
 # @example     test = cbind( seq( 102 , 1 , -2 ) , seq( 100 , 500 , 8 ) )
 # @example     prob = rep(.02 , 51 )
@@ -183,10 +186,10 @@
 #'          varianceReturn      the variance of the portfolio returns
 #' @examples
 #' PanicCopula( N = 20 , J = 50000 , r_c = .3 , r = .99 , b = .02 , sig = .2 , sigma )
-#' @export
 #' @author Ram Ahluwalia \email{rahluwalia@@gmail.com}
 #' @references 
 #' \url{http://www.symmys.com}
+#' @export
 PanicCopula = function( N = 20 , J = 50000 , r_c = .3 , r = .99 , b = .02 , sig = .2 , sigma )
 {
   # generate panic distribution

Modified: pkg/PerformanceAnalytics/sandbox/Meucci/R/EntropyProg.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Meucci/R/EntropyProg.R	2012-07-27 21:10:24 UTC (rev 2216)
+++ pkg/PerformanceAnalytics/sandbox/Meucci/R/EntropyProg.R	2012-07-27 23:41:27 UTC (rev 2217)
@@ -27,12 +27,11 @@
 #' @param  A        matrix consisting of inequality constraints (paired with argument 'b'). Denoted as 'F' in the Meucci paper
 #' @param  b        vector consisting of inequality constraints (paired with matrix A). Denoted as 'f' in the Meucci paper
 #'
+#' ' \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)}
 #' @return a list with 
 #'      p_                       revised probabilities based on entropy pooling
 #'      optimizationPerformance  a list with status of optimization, value, number of iterations and sum of probabilities.
-#' @export
-#' \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)}
 #' @author Ram Ahluwalia \email{ram@@wingedfootcapital.com}
 #' @references 
 #' A. Meucci - "Fully Flexible Views: Theory and Practice". See page 22 for illustration of numerical implementation
@@ -41,6 +40,7 @@
 #' 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
+#'  @export
 EntropyProg = function( p , A , b , Aeq , beq )
 {
     library( nloptr )    

Modified: pkg/PerformanceAnalytics/sandbox/Meucci/R/HermiteGrid.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Meucci/R/HermiteGrid.R	2012-07-27 21:10:24 UTC (rev 2216)
+++ pkg/PerformanceAnalytics/sandbox/Meucci/R/HermiteGrid.R	2012-07-27 23:41:27 UTC (rev 2217)
@@ -5,6 +5,7 @@
 #' @return normalizedp  a numeric value containing the normalized probability value
 #'
 #' @author Ram Ahluwalia \email{ram@@wingedfootcapital.com}
+#' @export
 normalizeProb = function( p )
 {
   tol = 1e-20
@@ -28,6 +29,7 @@
 #' A. Meucci - "Fully Flexible Extreme Views" - See formula (17)
 #' \url{http://ssrn.com/abstract=1542083}
 #' @author Ram Ahluwalia \email{ram@@wingedfootcapital.com}
+#' @export
 subIntervals = function( x )
 {
   n = nrow( x )
@@ -52,6 +54,7 @@
 #' @return p    a vector containing the cdf evaluated for each of the subintervals
 #'
 #' @author Ram Ahluwalia \email{ram@@wingedfootcapital.com}
+#' @export
 integrateSubIntervals = function( x , cdf )
 {
   bounds = subIntervals( x )
@@ -71,6 +74,7 @@
 #' A. Meucci - "Fully Flexible Extreme Views" - See formula (20)
 #' \url{http://ssrn.com/abstract=1542083}
 #' @author Ram Ahluwalia \email{ram@@wingedfootcapital.com}
+#' @export
 hermitePolynomial = function( n )
 {
   # convert last object to matrix

Modified: pkg/PerformanceAnalytics/sandbox/Meucci/R/InvariantProjection.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Meucci/R/InvariantProjection.R	2012-07-27 21:10:24 UTC (rev 2216)
+++ pkg/PerformanceAnalytics/sandbox/Meucci/R/InvariantProjection.R	2012-07-27 23:41:27 UTC (rev 2217)
@@ -15,6 +15,7 @@
 #' @references
 #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management". See page 9
 #' Symmys site containing original MATLAB source code \url{http://www.symmys.com}
+#' @export
 Raw2Central = function( mu_ )
 {
   N = length( mu_ )
@@ -52,6 +53,7 @@
 #' @references
 #' A. Meucci - "Annualization and General Projection of Skewness, Kurtosis and All Summary Statistics" - formula (24)
 #' Symmys site containing original MATLAB source code \url{http://www.symmys.com/node/136}
+#' @export
 Cumul2Raw = function( ka )
 {
   N = length( ka )
@@ -85,6 +87,7 @@
 #' @references
 #' A. Meucci - "Annualization and General Projection of Skewness, Kurtosis and All Summary Statistics" - formula (21)
 #' Symmys site containing original MATLAB source code \url{http://www.symmys.com/node/136}
+#' @export
 Raw2Cumul = function( mu_ )
 {
   N = length( mu_ )
@@ -116,7 +119,7 @@
 #' @references 
 #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management". See page 10.
 #' Symmys site containing original MATLAB source code \url{http://www.symmys.com}
-
+#' @export
 Central2Raw = function( mu )
 {
   N = length( mu )
@@ -148,6 +151,7 @@
 #' @return   mu   central moments
 #' @export
 #' @author Ram Ahluwalia \email{rahluwalia@@gmail.com}
+#' @export
 SummStats = function( X , N )
 {
   suppressWarnings( library( matlab ) ) # otherwise, stops with "Error: (converted from warning) package 'matlab' was built under R version 2.13.2"
@@ -190,6 +194,7 @@
 #'
 #' @return  X    a numeric vector with i.i.d. lognormal samples based on parameters J, a, m, and s where X = a + exp( m + s * Z )
 #' @author Ram Ahluwalia \email{rahluwalia@@gmail.com}
+#' @export
 GenerateLogNormalDistribution = function( J, a, m, s )
 {
   Z = rnorm( J / 2 , 0 , 1 ) # create J/2 draws from the standard normal 

Modified: pkg/PerformanceAnalytics/sandbox/Meucci/R/RankingInformation.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Meucci/R/RankingInformation.R	2012-07-27 21:10:24 UTC (rev 2216)
+++ pkg/PerformanceAnalytics/sandbox/Meucci/R/RankingInformation.R	2012-07-27 23:41:27 UTC (rev 2217)
@@ -62,6 +62,7 @@
 #'             w          the NumPortf x N matrix of compositions (security weights) for each portfolio along the efficient frontier
 #'             e          the NumPortf x 1 matrix of expected returns for each portfolio along the efficient frontier
 #'             s          the NumPortf x 1 matrix of standard deviation of returns for each portfolio along the efficient frontier
+#' @export
 RIEfficientFrontier = function( X , p , Options)
 {    
   library( matlab )

Modified: pkg/PerformanceAnalytics/sandbox/Meucci/R/logToArithmeticCovariance.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Meucci/R/logToArithmeticCovariance.R	2012-07-27 21:10:24 UTC (rev 2216)
+++ pkg/PerformanceAnalytics/sandbox/Meucci/R/logToArithmeticCovariance.R	2012-07-27 23:41:27 UTC (rev 2217)
@@ -13,6 +13,7 @@
 #' @references
 #' # formula (7) and (8) on page 5 of Appendix to "Meucci - A Common Pitfall in Mean-Variance Estimation"
 #' \url{http://www.wilmott.com/pdfs/011119_meucci.pdf}
+#' @export
 linreturn <- function( mu , sigma )
 {   
     # each element of M represents the linear returns for the corresponding log-returns element in mu

Modified: pkg/PerformanceAnalytics/sandbox/Meucci/man/EntropyProg.Rd
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Meucci/man/EntropyProg.Rd	2012-07-27 21:10:24 UTC (rev 2216)
+++ pkg/PerformanceAnalytics/sandbox/Meucci/man/EntropyProg.Rd	2012-07-27 23:41:27 UTC (rev 2217)
@@ -1,88 +1,95 @@
-\name{EntropyProg}
-\alias{EntropyProg}
-\title{Entropy pooling program for blending views on scenarios with a prior scenario-probability distribution}
-\usage{
-  EntropyProg(p, A, b, Aeq, beq)
-}
-\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}
-}
-\value{
-  a list with p_ revised probabilities based on entropy
-  pooling 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
-}
-
+\name{EntropyProg}
+\alias{EntropyProg}
+\title{Entropy pooling program for blending views on scenarios with a prior scenario-probability distribution}
+\usage{
+  EntropyProg(p, A, b, Aeq, beq)
+}
+\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
+
+  ' \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 p_ revised probabilities based on entropy
+  pooling 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
+}
+



More information about the Returnanalytics-commits mailing list