[Returnanalytics-commits] r3136 - in pkg/Meucci: . R demo man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Sep 18 13:40:27 CEST 2013


Author: xavierv
Date: 2013-09-18 13:40:27 +0200 (Wed, 18 Sep 2013)
New Revision: 3136

Modified:
   pkg/Meucci/R/CentralAndStandardizedStatistics.R
   pkg/Meucci/R/FitExpectationMaximization.R
   pkg/Meucci/R/LognormalMoments2Parameters.R
   pkg/Meucci/R/MleRecursionForStudentT.R
   pkg/Meucci/R/PlotMarginalsNormalInverseWishart.R
   pkg/Meucci/R/QuantileMixture.R
   pkg/Meucci/TODO
   pkg/Meucci/demo/S_EigenvalueDispersion.R
   pkg/Meucci/demo/S_EstimateExpectedValueEvaluation.R
   pkg/Meucci/demo/S_EstimateMomentsComboEvaluation.R
   pkg/Meucci/demo/S_EstimateQuantileEvaluation.R
   pkg/Meucci/demo/S_Estimator.R
   pkg/Meucci/demo/S_ExpectationMaximizationHighYield.R
   pkg/Meucci/demo/S_FitSwapToStudentT.R
   pkg/Meucci/demo/S_GenerateMixtureSample.R
   pkg/Meucci/demo/S_MaximumLikelihood.R
   pkg/Meucci/demo/S_PasturMarchenko.R
   pkg/Meucci/demo/S_SemiCircular.R
   pkg/Meucci/demo/S_ShrinkageEstimators.R
   pkg/Meucci/demo/S_TStatApprox.R
   pkg/Meucci/man/CentralAndStandardizedStatistics.Rd
   pkg/Meucci/man/FitExpectationMaximization.Rd
   pkg/Meucci/man/LognormalMoments2Parameters.Rd
   pkg/Meucci/man/MleRecursionForStudentT.Rd
   pkg/Meucci/man/PlotMarginalsNormalInverseWishart.Rd
   pkg/Meucci/man/QuantileMixture.Rd
Log:
 - updated documentation for chapter 4 demo scripts and its functions

Modified: pkg/Meucci/R/CentralAndStandardizedStatistics.R
===================================================================
--- pkg/Meucci/R/CentralAndStandardizedStatistics.R	2013-09-18 09:35:43 UTC (rev 3135)
+++ pkg/Meucci/R/CentralAndStandardizedStatistics.R	2013-09-18 11:40:27 UTC (rev 3136)
@@ -7,18 +7,18 @@
 #'  and from them the standarized statistics \deqn{ \mu_{X},\sigma_{X},sk_{X},ku_{X},\gamma_{X}^{(5)}, \ldots ,\gamma_{X}^{(n)} .}
 #'  where \deqn{\gamma_{X}^{(n)} \equiv E \{(X - \mu_{X})^{n}\}/\sigma_{X}^{n},\quad n\geq3 .} 
 #'
-#'	@param    X  : [vector] (J x 1) draws from the distribution
-#'	@param    N  : [scalar] highest degree for the central moment
+#'	@param    X   [vector] (J x 1) draws from the distribution
+#'	@param    N   [scalar] highest degree for the central moment
 #'
-#'	@return   ga : [vector] (1 x N) standardized statistics up to order N
-#'	@return   mu : [vector] (1 x N) central moments up to order N
+#'	@return   ga  [vector] (1 x N) standardized statistics up to order N
+#'	@return   mu  [vector] (1 x N) central moments up to order N
 #'
 #' @references
 #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170},
 #' "E 97 - Projection of skewness, kurtosis, and all standardized summary statistics".
 #' See Meucci's script for "CentralAndStandardizedStatistics.m"
 #'
-#' Kendall, M., Stuart, A., 1969. The Advanced Theory of Statistics, Volume, 3rd Edition. Griffin.
+#' Kendall, M., Stuart, A. - "The Advanced Theory of Statistics", 1969. Volume, 3rd Edition. Griffin.
 #'
 #' A. Meucci - "Annualization and general projection of skweness, kurtosis, and all summary statistics",
 #' GARP Risk Professional August 2010, 55-56. \url{http://symmys.com/node/136}.

Modified: pkg/Meucci/R/FitExpectationMaximization.R
===================================================================
--- pkg/Meucci/R/FitExpectationMaximization.R	2013-09-18 09:35:43 UTC (rev 3135)
+++ pkg/Meucci/R/FitExpectationMaximization.R	2013-09-18 11:40:27 UTC (rev 3136)
@@ -1,5 +1,7 @@
-#' Expectation-Maximization (EM) algorithm to recover missing observations in a time series ,
-#' as described in  A. Meucci, "Risk and Asset Allocation", Springer, 2005.
+#' @title Expectation-Maximization (EM) algorithm to recover missing observations in a time series.
+#'
+#' @description Expectation-Maximization (EM) algorithm to recover missing observations in a time series ,
+#'  as described in  A. Meucci, "Risk and Asset Allocation", Springer, 2005, section 4.6.2 "Missing data".
 #'  
 #'  @param   X         : [matrix] (T x N) of data
 #'  
@@ -9,9 +11,15 @@
 #'  @return  CountLoop : [scalar] number of iterations of the algorithm
 #'
 #' @references
-#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}.
+#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170},
+#' "E 177 - Expectation-Maximization algorithm for missing data: formulas"
 #' See Meucci's script for "FitExpectationMaximization.m"
 #'
+#' Dempster, A. P. and Laird, M. N. and Rubin, D. B. - "Maximum Likelihood from Incomplete Data Via the EM Algorithm", 
+#' Journal of the Royal Statistical Society, 1977 vol 39 pag. 1-22.
+#'
+#' Bilmes, J. A.- "A Gentle Tutorial of the EM Algorithm and its Application to Parameter Estimation for Gaussian Mixture
+#' and Hidden Markov Models", 1998.
 #' @author Xavier Valls \email{flamejat@@gmail.com}
 #' @export
 

Modified: pkg/Meucci/R/LognormalMoments2Parameters.R
===================================================================
--- pkg/Meucci/R/LognormalMoments2Parameters.R	2013-09-18 09:35:43 UTC (rev 3135)
+++ pkg/Meucci/R/LognormalMoments2Parameters.R	2013-09-18 11:40:27 UTC (rev 3136)
@@ -16,7 +16,7 @@
 #'  @note	Inverts the formulas (1.98)-(1.99) in "Risk and Asset Allocation", Springer, 2005.
 #'
 #' @references
-#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, "E 25- Simulation of a lognormal random variable".
+#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}, "E 25 - Simulation of a lognormal random variable".
 #'
 #' See Meucci's script for "LognormalMoments2Parameters.m"
 #'

Modified: pkg/Meucci/R/MleRecursionForStudentT.R
===================================================================
--- pkg/Meucci/R/MleRecursionForStudentT.R	2013-09-18 09:35:43 UTC (rev 3135)
+++ pkg/Meucci/R/MleRecursionForStudentT.R	2013-09-18 11:40:27 UTC (rev 3136)
@@ -1,6 +1,14 @@
-#' Compute recursively the ML estimators of location and scatter of a multivariate Student t distribution with 
-#' given degrees of freedom, as described in  A. Meucci, "Risk and Asset Allocation", Springer, 2005.
-#'  
+#' @title Compute recursively the ML estimators of location and scatter of a multivariate Student t distribution with 
+#' given degrees of freedom.
+#' 
+#' @description Compute recursively the ML estimators of location and scatter of a multivariate Student t distribution with 
+#' given degrees of freedom, as described in  A. Meucci, "Risk and Asset Allocation", Springer, 2005, section 4.3 - "Maximum likelihood estimators"
+#' 
+#' Returns \deqn{ \widehat{\mu} = \sum\limits_{t= 1}^{T} \frac{w_{t}}{\sum\limits_{s= 1}^{T}w_{s}} x_{t} ,} 
+#' \deqn{\widehat{\Sigma} = \frac{1}{T}\sum\limits_{t= 1}^{T}w_{t}(x_{t}-\widehat{\mu})(x_{t}-\widehat{\mu})^\prime} 
+#' 
+#' where, adapted to the Sudent T distribution, \deqn{ w_{t}\equiv \frac{\nu+N}{\nu+(x_{t}-\widehat{\mu})^\prime \widehat{\Sigma}^{-1}(  x-\widehat{\mu})  }}
+#'
 #'  @param   x         : [matrix] (T x N) observations
 #'  @param   Nu        : [scalar] degrees of freedom parameter
 #'  @param   Tolerance : [scalar] tolerance parameter. Default: 10^(-10)
@@ -9,7 +17,9 @@
 #'  @return  Sigma     : [matrix] (N x N) covariance
 #'
 #' @references
-#' \url{http://}
+#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170},
+#' "E 188 - Maximum likelihood estimation of a multivariate Student t distribution".
+#'
 #' See Meucci's script for "MleRecursionForStudentT.m"
 #'
 #' @author Xavier Valls \email{flamejat@@gmail.com}
@@ -24,8 +34,8 @@
     Ones_T = matrix( 1, T, 1 ); # fixed for fast matrix operation 
 
     # initialize variables
-    w = matrix( 1, T, 1 );
-    Mu = matrix( 0, N, 1 );
+    w     = matrix( 1, T, 1 );
+    Mu    = matrix( 0, N, 1 );
     Sigma = matrix( 0, N, N );
 
     Error = 10^6;
@@ -34,20 +44,20 @@
     {
         
         # update
-        Mu_Old = Mu;
+        Mu_Old    = Mu;
         Sigma_Old = Sigma;
         
         # Step 1
-        W = w %*% Ones_N;
+        W  = w %*% Ones_N;
         Mu = matrix( apply(  W * x, 2, sum  ) ) / sum( w );
         
-        x_c = x - Ones_T %*% t(Mu);
+        x_c   = x - Ones_T %*% t(Mu);
         Sigma = t( W * x_c ) %*% x_c / T;
 
         # Step 2
         InvS = solve(Sigma);
-        Ma2 = apply( ( x_c %*% InvS ) * x_c, 1, sum );
-        w = ( Nu + N) / ( Nu + Ma2 );
+        Ma2  = apply( ( x_c %*% InvS ) * x_c, 1, sum );
+        w    = ( Nu + N) / ( Nu + Ma2 );
 
         # convergence
         Error = sum( diag( (Sigma - Sigma_Old) ^2) ) / N + t(Mu - Mu_Old) %*% ( Mu - Mu_Old ) / N;    

Modified: pkg/Meucci/R/PlotMarginalsNormalInverseWishart.R
===================================================================
--- pkg/Meucci/R/PlotMarginalsNormalInverseWishart.R	2013-09-18 09:35:43 UTC (rev 3135)
+++ pkg/Meucci/R/PlotMarginalsNormalInverseWishart.R	2013-09-18 11:40:27 UTC (rev 3136)
@@ -17,7 +17,7 @@
 #'
 #' @references
 #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}.
-#' See Meucci's script for "QuantileMixture.m"
+#' See Meucci's script for "PlotMarginalsNormalInverseWishart.m"
 #'
 #' @author Xavier Valls \email{flamejat@@gmail.com}
 #' @export

Modified: pkg/Meucci/R/QuantileMixture.R
===================================================================
--- pkg/Meucci/R/QuantileMixture.R	2013-09-18 09:35:43 UTC (rev 3135)
+++ pkg/Meucci/R/QuantileMixture.R	2013-09-18 11:40:27 UTC (rev 3136)
@@ -1,21 +1,24 @@
-
-#' Computes the quantile of a mixture distirbution by linear interpolation/extrapolation of the cdf.the confidence 
+#' @title Computes the quantile of a mixture distribution by linear interpolation/extrapolation of the cdf.
+#'
+#' @description Computes the quantile of a mixture distribution by linear interpolation/extrapolation of the cdf. The confidence 
 #' level p can be vector. If this vector is uniformly distributed on [0,1] the sample Q is distributed as the mixture.
-#' Described in A. Meucci "Risk and Asset Allocation", Springer, 2005
+#' Described in A. Meucci "Risk and Asset Allocation", Springer, 2005.
 #'
-#'  @param	p   : [scalar] in [0,1], probability
-#'	@param	a   : [scalar] in (0,1), mixing probability
-#'  @param	m_Y : [scalar] mean of normal component
-#'  @param  s_Y : [scalar] standard deviation of normal component
-#'  @param  m_Z : [scalar] first parameters of the log-normal component
-#'  @param  s_Z : [scalar] second parameter of the log-normal component
+#'  @param	p    [scalar] in [0,1], probability
+#'	@param	a    [scalar] in (0,1), mixing probability
+#'  @param	m_Y  [scalar] mean of normal component
+#'  @param  s_Y  [scalar] standard deviation of normal component
+#'  @param  m_Z  [scalar] first parameters of the log-normal component
+#'  @param  s_Z  [scalar] second parameter of the log-normal component
 #'  
-#'  @return	Q   : [scalar] quantile
+#'  @return	Q    [scalar] quantile
 #'
 #' @references
-#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}.
-#' See Meucci's script for "QuantileMixture.m"
+#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170},
+#' "E 184 - Estimation of a quantile of a mixture I".
 #'
+#'See Meucci's script for "QuantileMixture.m"
+#'
 #' @author Xavier Valls \email{flamejat@@gmail.com}
 #' @export
 
@@ -26,13 +29,14 @@
 
 	# compute second moment
 	Ex2 = a * (m_Y^2 + s_Y^2) + (1 - a) * exp( 2 * m_Z + 2 * s_Z * s_Z);
-	s = sqrt( Ex2 - m * m );
+	s   = sqrt( Ex2 - m * m );
 
 	# compute cdf on suitable range
 	X = m + 6 * s * seq( -1, 1, 0.001 );
 	F = a * pnorm( X,  m_Y, s_Y) + (1 - a) * plnorm(X, m_Z, s_Z);
 	X = X[!duplicated(F)];
 	F = unique(F);
+
 	# compute quantile by interpolation
 	Q = interp1( F, X, p, method = "linear");
 

Modified: pkg/Meucci/TODO
===================================================================
--- pkg/Meucci/TODO	2013-09-18 09:35:43 UTC (rev 3135)
+++ pkg/Meucci/TODO	2013-09-18 11:40:27 UTC (rev 3136)
@@ -13,3 +13,4 @@
 	- find the exercises and sections they come from
 	- write down the equations
 * Not Sure if EntropyProg returns what it should with empty matrices as arguments for the constraints
+* Write text version of the formulas in the documentation
\ No newline at end of file

Modified: pkg/Meucci/demo/S_EigenvalueDispersion.R
===================================================================
--- pkg/Meucci/demo/S_EigenvalueDispersion.R	2013-09-18 09:35:43 UTC (rev 3135)
+++ pkg/Meucci/demo/S_EigenvalueDispersion.R	2013-09-18 11:40:27 UTC (rev 3136)
@@ -2,7 +2,9 @@
 #' "Risk and Asset Allocation", Springer, 2005,  Chapter 4.
 #'
 #' @references
-#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}.
+#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170},
+#' "E 168 - Sample covariance and eigenvalue dispersion".
+#'
 #' See Meucci's script for "S_EigenValueDispersion.m"
 #'
 #' @author Xavier Valls \email{flamejat@@gmail.com}
@@ -10,15 +12,15 @@
 ##################################################################################################################
 ### Inputs
 
-N = 50;
+N    = 50;
+nSim = 50;
 SampleLenght = seq( N , 10 * N, N)
-nSim = 50;
 
 ##################################################################################################################
 ### Generate mesh and surface
 
-Mu = matrix( 0, N, 1 );
-Sigma= diag( 1, N );
+Mu    = matrix( 0, N, 1 );
+Sigma = diag( 1, N );
 
 # compute true eigenvalues
 Eigen = eigen(Sigma);
@@ -27,7 +29,7 @@
 EVal  = diag( Eigen$Values[ Index, Index ]);
 
 # compute eigenvalues of sample estimator
-nSampleLenght = length( SampleLenght );
+nSampleLenght  = length( SampleLenght );
 Store_EVal_Hat = matrix( NaN, nSampleLenght, N ); # preallocation for speed
 for( i in 1 : nSampleLenght )
  {  

Modified: pkg/Meucci/demo/S_EstimateExpectedValueEvaluation.R
===================================================================
--- pkg/Meucci/demo/S_EstimateExpectedValueEvaluation.R	2013-09-18 09:35:43 UTC (rev 3135)
+++ pkg/Meucci/demo/S_EstimateExpectedValueEvaluation.R	2013-09-18 11:40:27 UTC (rev 3136)
@@ -2,7 +2,9 @@
 #' and inefficiency, as described in A. Meucci, "Risk and Asset Allocation", Springer, 2005,  Chapter 4.
 #'
 #' @references
-#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}.
+#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170},
+#' "E 182 - Moment-based functional of a mixture III ".
+#'
 #' See Meucci's script for "S_EigenValueDispersion.R"
 #'
 #' @author Xavier Valls \email{flamejat@@gmail.com}

Modified: pkg/Meucci/demo/S_EstimateMomentsComboEvaluation.R
===================================================================
--- pkg/Meucci/demo/S_EstimateMomentsComboEvaluation.R	2013-09-18 09:35:43 UTC (rev 3135)
+++ pkg/Meucci/demo/S_EstimateMomentsComboEvaluation.R	2013-09-18 11:40:27 UTC (rev 3136)
@@ -1,8 +1,10 @@
-#'This script familiarizes the user with the evaluation of an estimator:replicability, loss, error, 
-#'bias and inefficiency as described in A. Meucci,"Risk and Asset Allocation", Springer, 2005,  Chapter 4.
+#' This script familiarizes the user with the evaluation of an estimator:replicability, loss, error, 
+#' bias and inefficiency as described in A. Meucci,"Risk and Asset Allocation", Springer, 2005,  Chapter 4.
 #'
 #' @references
-#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}.
+#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170},
+#' "E 181 - Moment-based functional of a mixture II ".
+#'
 #' See Meucci's script for "S_EstimateMomentsComboEvaluation.m"
 #'
 #' @author Xavier Valls \email{flamejat@@gmail.com}
@@ -25,8 +27,8 @@
 print(G_fX);
 
 # series generated by "nature": do not know the distribution
-P = runif(T);
-i_T = t( matrix (QuantileMixture( P, a, m_Y, s_Y, m_Z, s_Z ) ) );
+P   = runif(T);
+i_T = t( matrix ( QuantileMixture( P, a, m_Y, s_Y, m_Z, s_Z ) ) );
 
 G_Hat_a = function(X) (X[ , 1] - X[ , ncol(X) ]) * X[ , 2 ] * X[ , 2 ];
 G_Hat_b = function(X) apply( X, 1, mean);
@@ -50,7 +52,8 @@
 
 # randomize series generated by "nature" to check replicability
 nSim = 10000;
-I_T = matrix( NaN, nSim, T);
+I_T  = matrix( NaN, nSim, T);
+
 for( t in 1 : T )
 {
     P = matrix( runif(nSim), nSim, 1);
@@ -62,20 +65,20 @@
 Gc = G_Hat_c(I_T);        # tentative estimator of unknown functional
 Gd = G_Hat_d(I_T);        # tentative estimator of unknown functional
 
-Loss_Ga = (Ga-G_fX)^2;
-Loss_Gb = (Gb-G_fX)^2;
-Loss_Gc = (Gc-G_fX)^2;
-Loss_Gd = (Gd-G_fX)^2;
+Loss_Ga  = (Ga-G_fX)^2;
+Loss_Gb  = (Gb-G_fX)^2;
+Loss_Gc  = (Gc-G_fX)^2;
+Loss_Gd  = (Gd-G_fX)^2;
 
-Err_Ga = sqrt(mean(Loss_Ga));
-Err_Gb = sqrt(mean(Loss_Gb));
-Err_Gc = sqrt(mean(Loss_Gc));
-Err_Gd = sqrt(mean(Loss_Gd));
+Err_Ga   = sqrt(mean(Loss_Ga));
+Err_Gb   = sqrt(mean(Loss_Gb));
+Err_Gc   = sqrt(mean(Loss_Gc));
+Err_Gd   = sqrt(mean(Loss_Gd));
 
-Bias_Ga = abs(mean(Ga)-G_fX);
-Bias_Gb = abs(mean(Gb)-G_fX);
-Bias_Gc = abs(mean(Gc)-G_fX);
-Bias_Gd = abs(mean(Gd)-G_fX);
+Bias_Ga  = abs(mean(Ga)-G_fX);
+Bias_Gb  = abs(mean(Gb)-G_fX);
+Bias_Gc  = abs(mean(Gc)-G_fX);
+Bias_Gd  = abs(mean(Gd)-G_fX);
 
 Ineff_Ga = sd(Ga);
 Ineff_Gb = sd(Gb);
@@ -125,11 +128,14 @@
 for( j in 1 : length(m_s) )
 {
     m_Y = m_s[ j ];
+    
     # functional of the distribution to be estimated
     G_fX = a * ( m_Y ^ 2 + s_Y^2 - m_Y ) + ( 1 - a ) *(  exp( 2 * m_Z + 2 * s_Z^2 ) - exp( m_Z + 0.5 * s_Z^2 )  );
+
     # randomize series generated by "nature" to check replicability
     nSim = 10000;
-    I_T = matrix( NaN, nSim, T);
+    I_T  = matrix( NaN, nSim, T);
+
     for( t in 1 : T )
     {
         P = matrix( runif(nSim) );
@@ -141,20 +147,20 @@
     Gc = G_Hat_c(I_T);       
     Gd = G_Hat_d(I_T);        
 
-    Loss_Ga = (Ga-G_fX)^2;
-    Loss_Gb = (Gb-G_fX)^2;
-    Loss_Gc = (Gc-G_fX)^2;
-    Loss_Gd = (Gd-G_fX)^2;
+    Loss_Ga  = (Ga-G_fX)^2;
+    Loss_Gb  = (Gb-G_fX)^2;
+    Loss_Gc  = (Gc-G_fX)^2;
+    Loss_Gd  = (Gd-G_fX)^2;
 
-    Err_Ga = sqrt(mean(Loss_Ga));
-    Err_Gb = sqrt(mean(Loss_Gb));
-    Err_Gc = sqrt(mean(Loss_Gc));
-    Err_Gd = sqrt(mean(Loss_Gd));
+    Err_Ga   = sqrt(mean(Loss_Ga));
+    Err_Gb   = sqrt(mean(Loss_Gb));
+    Err_Gc   = sqrt(mean(Loss_Gc));
+    Err_Gd   = sqrt(mean(Loss_Gd));
 
-    Bias_Ga = abs(mean(Ga)-G_fX);
-    Bias_Gb = abs(mean(Gb)-G_fX);
-    Bias_Gc = abs(mean(Gc)-G_fX);
-    Bias_Gd = abs(mean(Gd)-G_fX);
+    Bias_Ga  = abs(mean(Ga)-G_fX);
+    Bias_Gb  = abs(mean(Gb)-G_fX);
+    Bias_Gc  = abs(mean(Gc)-G_fX);
+    Bias_Gd  = abs(mean(Gd)-G_fX);
 
     Ineff_Ga = sd(Ga);
     Ineff_Gb = sd(Gb);
@@ -162,15 +168,15 @@
     Ineff_Gd = sd(Gd);
 
     #store results
-    Err_Gasq = cbind( Err_Gasq, Err_Ga^2 ); ##ok<*AGROW>
-    Err_Gbsq = cbind( Err_Gbsq, Err_Gb^2 );
-    Err_Gcsq = cbind( Err_Gcsq, Err_Gc^2 );
-    Err_Gdsq = cbind( Err_Gdsq, Err_Gd^2 );
+    Err_Gasq   = cbind( Err_Gasq, Err_Ga^2 ); 
+    Err_Gbsq   = cbind( Err_Gbsq, Err_Gb^2 );
+    Err_Gcsq   = cbind( Err_Gcsq, Err_Gc^2 );
+    Err_Gdsq   = cbind( Err_Gdsq, Err_Gd^2 );
     
-    Bias_Gasq = cbind(Bias_Gasq, Bias_Ga^2 ); 
-    Bias_Gbsq = cbind(Bias_Gbsq, Bias_Gb^2 ); 
-    Bias_Gcsq = cbind(Bias_Gcsq, Bias_Gc^2 ); 
-    Bias_Gdsq = cbind(Bias_Gdsq, Bias_Gd^2 ); 
+    Bias_Gasq  = cbind(Bias_Gasq, Bias_Ga^2 ); 
+    Bias_Gbsq  = cbind(Bias_Gbsq, Bias_Gb^2 ); 
+    Bias_Gcsq  = cbind(Bias_Gcsq, Bias_Gc^2 ); 
+    Bias_Gdsq  = cbind(Bias_Gdsq, Bias_Gd^2 ); 
     
     Ineff_Gasq = cbind( Ineff_Gasq, Ineff_Ga^2 ); 
     Ineff_Gbsq = cbind( Ineff_Gbsq, Ineff_Gb^2 ); 

Modified: pkg/Meucci/demo/S_EstimateQuantileEvaluation.R
===================================================================
--- pkg/Meucci/demo/S_EstimateQuantileEvaluation.R	2013-09-18 09:35:43 UTC (rev 3135)
+++ pkg/Meucci/demo/S_EstimateQuantileEvaluation.R	2013-09-18 11:40:27 UTC (rev 3136)
@@ -1,7 +1,10 @@
 #'This script familiarizes the user with the evaluation of an estimator:replicability, loss, error, 
 #'bias and inefficiency as described in A. Meucci,"Risk and Asset Allocation", Springer, 2005,  Chapter 4.
 #'
-#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}.
+#' @references
+#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170},
+#' "E 183 - Moment-based functional of a mixture IV".
+#'
 #' See Meucci's script for "S_EstimateQuantileEvaluation.m"
 #'
 #' @author Xavier Valls \email{flamejat@@gmail.com}
@@ -24,7 +27,7 @@
 print( G_fX );
 
 # series generated by "nature": do not know the distribution
-P = runif( T );
+P   = runif( T );
 i_T = QuantileMixture( P, a, m_Y, s_Y, m_Z, s_Z );
 
 G_Hat_e = function(X) apply( X, 1, median );
@@ -43,26 +46,26 @@
 
 # randomize series generated by "nature" to check replicability
 nSim = 10000;
-I_T = c();
+I_T  = c();
 
 for( t in 1:T )
 {
-    P = runif(nSim);
+    P     = runif(nSim);
     Simul = QuantileMixture(P,a,m_Y,s_Y,m_Z,s_Z);
-    I_T = cbind( I_T, Simul );
+    I_T   = cbind( I_T, Simul );
 }
 
 Ge = G_Hat_e( I_T );        # tentative estimator of unknown functional
 Gb = G_Hat_b( I_T );        # tentative estimator of unknown functional
 
-Loss_Ge = ( Ge - G_fX ) ^ 2;
-Loss_Gb = ( Gb - G_fX ) ^ 2;
+Loss_Ge  = ( Ge - G_fX ) ^ 2;
+Loss_Gb  = ( Gb - G_fX ) ^ 2;
 
-Err_Ge = sqrt( mean( Loss_Ge));
-Err_Gb = sqrt( mean( Loss_Gb));
+Err_Ge   = sqrt( mean( Loss_Ge));
+Err_Gb   = sqrt( mean( Loss_Gb));
 
-Bias_Ge = abs(mean(Ge)-G_fX);
-Bias_Gb = abs(mean(Gb)-G_fX);
+Bias_Ge  = abs(mean(Ge)-G_fX);
+Bias_Gb  = abs(mean(Gb)-G_fX);
 
 Ineff_Ge = sd(Ge);
 Ineff_Gb = sd(Gb);
@@ -98,38 +101,38 @@
 
     # randomize series generated by "nature" to check replicability
     nSim = 10000;
-    I_T = NULL;
+    I_T  = NULL;
     for( t in 1 : T )
     {
-        P = runif(nSim);
+        P     = runif(nSim);
         Simul = QuantileMixture(P, a, m_Y, s_Y, m_Z, s_Z);
-        I_T = cbind( I_T, Simul );
+        I_T   = cbind( I_T, Simul );
     }
 
     Ge = G_Hat_e( I_T );        # tentative estimator of unknown functional
     Gb = G_Hat_b( I_T );        # tentative estimator of unknown functional
 
-    Loss_Ge = ( Ge - G_fX ) ^ 2;
-    Loss_Gb = ( Gb - G_fX ) ^ 2;
+    Loss_Ge  = ( Ge - G_fX ) ^ 2;
+    Loss_Gb  = ( Gb - G_fX ) ^ 2;
 
-    Err_Ge = sqrt( mean( Loss_Ge ) );
-    Err_Gb = sqrt( mean( Loss_Gb ) );
+    Err_Ge   = sqrt( mean( Loss_Ge ) );
+    Err_Gb   = sqrt( mean( Loss_Gb ) );
 
-    Bias_Ge = abs( mean( Ge ) - G_fX );
-    Bias_Gb = abs( mean( Gb ) - G_fX );
+    Bias_Ge  = abs( mean( Ge ) - G_fX );
+    Bias_Gb  = abs( mean( Gb ) - G_fX );
 
     Ineff_Ge = std( Ge );
     Ineff_Gb = std( Gb );
 
     #store results
-    Err_Gesq = cbind( Err_Gesq, Err_Ge ^ 2); ##ok<*AGROW>
-    Err_Gbsq = cbind(Err_Gbsq, Err_Gb^2);
+    Err_Gesq   = cbind( Err_Gesq, Err_Ge^2 ); 
+    Err_Gbsq   = cbind( Err_Gbsq, Err_Gb^2 );
     
-    Bias_Gesq = cbind( Bias_Gesq, Bias_Ge^2 ); 
-    Bias_Gbsq = cbind( Bias_Gbsq, Bias_Gb^2 ); 
+    Bias_Gesq  = cbind( Bias_Gesq, Bias_Ge^2 ); 
+    Bias_Gbsq  = cbind( Bias_Gbsq, Bias_Gb^2 ); 
     
-    Ineff_Gesq = cbind( Ineff_Gesq, Ineff_Ge ^ 2 ); 
-    Ineff_Gbsq = cbind( Ineff_Gbsq, Ineff_Gb ^ 2 ); 
+    Ineff_Gesq = cbind( Ineff_Gesq, Ineff_Ge^2 ); 
+    Ineff_Gbsq = cbind( Ineff_Gbsq, Ineff_Gb^2 ); 
 }
 
 ###################################################################################################################

Modified: pkg/Meucci/demo/S_Estimator.R
===================================================================
--- pkg/Meucci/demo/S_Estimator.R	2013-09-18 09:35:43 UTC (rev 3135)
+++ pkg/Meucci/demo/S_Estimator.R	2013-09-18 11:40:27 UTC (rev 3136)
@@ -2,9 +2,10 @@
 #', as described in A. Meucci, "Risk and Asset Allocation", Springer, 2005,  Chapter 4.
 #'
 #' @references
-#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}.
-#' See Meucci's script for "S_EigenValueprintersion.R"
+#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170},
 #'
+#' See Meucci's script for "S_Estimator.R"
+#'
 #' @author Xavier Valls \email{flamejat@@gmail.com}
 
 ##################################################################################################################

Modified: pkg/Meucci/demo/S_ExpectationMaximizationHighYield.R
===================================================================
--- pkg/Meucci/demo/S_ExpectationMaximizationHighYield.R	2013-09-18 09:35:43 UTC (rev 3135)
+++ pkg/Meucci/demo/S_ExpectationMaximizationHighYield.R	2013-09-18 11:40:27 UTC (rev 3136)
@@ -3,7 +3,9 @@
 #' "Risk and Asset Allocation", Springer, 2005,  Chapter 4.
 #'
 #' @references
-#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}.
+#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170},
+#' "E 178 - Expectation-Maximization algorithm for missing data: example".
+#
 #' See Meucci's script for "S_ExpectationMaximizationHighYield.m"
 #'
 #' @author Xavier Valls \email{flamejat@@gmail.com}

Modified: pkg/Meucci/demo/S_FitSwapToStudentT.R
===================================================================
--- pkg/Meucci/demo/S_FitSwapToStudentT.R	2013-09-18 09:35:43 UTC (rev 3135)
+++ pkg/Meucci/demo/S_FitSwapToStudentT.R	2013-09-18 11:40:27 UTC (rev 3136)
@@ -2,7 +2,9 @@
 #' Student t distribution, as described in A. Meucci, "Risk and Asset Allocation", Springer, 2005,  Chapter 4.
 #'
 #' @references
-#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}.
+#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170},
+#' "E 188 - Maximum likelihood estimation of a multivariate Student t distribution".
+#'
 #' See Meucci's script for "S_FitSwapToStudentT.m"
 #'
 #' TO DO: Change colors from TwoDimEllipsoid in each iteration

Modified: pkg/Meucci/demo/S_GenerateMixtureSample.R
===================================================================
--- pkg/Meucci/demo/S_GenerateMixtureSample.R	2013-09-18 09:35:43 UTC (rev 3135)
+++ pkg/Meucci/demo/S_GenerateMixtureSample.R	2013-09-18 11:40:27 UTC (rev 3136)
@@ -2,7 +2,9 @@
 #' Springer, 2005,  Chapter 4.
 #'
 #' @references
-#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}.
+#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170},
+#' "E 184 - Estimation of a quantile of a mixture I".
+#'
 #' See Meucci's script for "S_GenerateMixtureSample.m"
 #'
 #' @author Xavier Valls \email{flamejat@@gmail.com}### 
@@ -15,7 +17,7 @@
 m_Z = 0;
 s_Z = 0.15;
 
-T = 52;
+T   = 52;
 
 ##################################################################################################################
 ### Computations

Modified: pkg/Meucci/demo/S_MaximumLikelihood.R
===================================================================
--- pkg/Meucci/demo/S_MaximumLikelihood.R	2013-09-18 09:35:43 UTC (rev 3135)
+++ pkg/Meucci/demo/S_MaximumLikelihood.R	2013-09-18 11:40:27 UTC (rev 3136)
@@ -2,7 +2,9 @@
 #' "Risk and Asset Allocation", Springer, 2005,  Chapter 4.
 #'
 #' @references
-#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}.
+#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170},
+#' "E 186 - Maximum likelihood estimation".
+#'
 #' See Meucci's script for "S_MaximumLikelihood.m"
 #'
 #' @author Xavier Valls \email{flamejat@@gmail.com}

Modified: pkg/Meucci/demo/S_PasturMarchenko.R
===================================================================
--- pkg/Meucci/demo/S_PasturMarchenko.R	2013-09-18 09:35:43 UTC (rev 3135)
+++ pkg/Meucci/demo/S_PasturMarchenko.R	2013-09-18 11:40:27 UTC (rev 3136)
@@ -2,7 +2,9 @@
 #' "Risk and Asset Allocation", Springer, 2005,  Chapter 4.
 #'
 #' @references
-#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}.
+#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170},
+#' "E 190 - Random matrix theory: Marchenko-Pastur limit".
+#'	
 #' See Meucci's script for "S_PasturMarchenko.m"
 #'
 

Modified: pkg/Meucci/demo/S_SemiCircular.R
===================================================================
--- pkg/Meucci/demo/S_SemiCircular.R	2013-09-18 09:35:43 UTC (rev 3135)
+++ pkg/Meucci/demo/S_SemiCircular.R	2013-09-18 11:40:27 UTC (rev 3136)
@@ -2,9 +2,10 @@
 #' "Risk and Asset Allocation", Springer, 2005,  Chapter 4.
 #'
 #' @references
-#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}.
+#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170},
+#' "E 189 - Random matrix theory: semi-circular law".
+#'
 #' See Meucci's script for "S_SemiCircular.m"
-#'
 
 ##################################################################################################################
 ### Inputs
@@ -13,9 +14,9 @@
 ##################################################################################################################
 ### Empirical eigenvalues
 
-#X=rnorm(N);                # normal
-#X=( runif(N)-0.5 ) * sqrt(12);   # uniform
-X = log( matrix( runif(N^2), N, N )) + 1;           # exponential
+#X = rnorm( N );                           # normal
+#X = ( runif(N)-0.5 ) * sqrt(12);   	   # uniform
+X = log( matrix( runif(N^2), N, N )) + 1;  # exponential
 
 Y = (X + t(X) ) / ( 2 * sqrt( 2 * N ));    # symmetrize and rescale
 E = t(eigen(Y)$values);
@@ -35,6 +36,5 @@
 ##################################################################################################################
 ### Plots
 dev.new();
-#bar(t_, h);
-plot(t_, h, type = "h", lwd = 5);
-lines(t, g, col = "red", lwd = 3);
+plot( t_, h, type = "h" , lwd = 5 );
+lines( t, g, col = "red", lwd = 3 );

Modified: pkg/Meucci/demo/S_ShrinkageEstimators.R
===================================================================
--- pkg/Meucci/demo/S_ShrinkageEstimators.R	2013-09-18 09:35:43 UTC (rev 3135)
+++ pkg/Meucci/demo/S_ShrinkageEstimators.R	2013-09-18 11:40:27 UTC (rev 3136)
@@ -2,7 +2,9 @@
 #'  as described in A. Meucci, "Risk and Asset Allocation", Springer, 2005,  Chapter 4.
 #'
 #' @references
-#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}.
+#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170},
+#' "E 166 - Shrinkage estimator of location".
+#'
 #' See Meucci's script for "S_ShrinkageEstimators.m"
 #'
 

Modified: pkg/Meucci/demo/S_TStatApprox.R
===================================================================
--- pkg/Meucci/demo/S_TStatApprox.R	2013-09-18 09:35:43 UTC (rev 3135)
+++ pkg/Meucci/demo/S_TStatApprox.R	2013-09-18 11:40:27 UTC (rev 3136)
@@ -13,7 +13,9 @@
 #'  @return  F       : [vector] ( J x 1 ) 
 #'
 #' @references
-#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}.
+#' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170},
+#' "E 193 - Simulation of the distribution of statistics of regression parameters".
+#'
 #' See Meucci's script for "GenerateInvariants.m"
 #'
 #' @author Xavier Valls \email{flamejat@@gmail.com}

Modified: pkg/Meucci/man/CentralAndStandardizedStatistics.Rd
===================================================================
--- pkg/Meucci/man/CentralAndStandardizedStatistics.Rd	2013-09-18 09:35:43 UTC (rev 3135)
+++ pkg/Meucci/man/CentralAndStandardizedStatistics.Rd	2013-09-18 11:40:27 UTC (rev 3136)
@@ -5,16 +5,14 @@
   CentralAndStandardizedStatistics(X, N)
 }
 \arguments{
-  \item{X}{: [vector] (J x 1) draws from the distribution}
+  \item{X}{[vector] (J x 1) draws from the distribution}
 
-  \item{N}{: [scalar] highest degree for the central
-  moment}
+  \item{N}{[scalar] highest degree for the central moment}
 }
 \value{
-  ga : [vector] (1 x N) standardized statistics up to order
-  N
+  ga [vector] (1 x N) standardized statistics up to order N
 
-  mu : [vector] (1 x N) central moments up to order N
+  mu [vector] (1 x N) central moments up to order N
 }
 \description{
   Compute central and standardized statistics, as described
@@ -38,8 +36,8 @@
   summary statistics". See Meucci's script for
   "CentralAndStandardizedStatistics.m"
 
-  Kendall, M., Stuart, A., 1969. The Advanced Theory of
-  Statistics, Volume, 3rd Edition. Griffin.
+  Kendall, M., Stuart, A. - "The Advanced Theory of
+  Statistics", 1969. Volume, 3rd Edition. Griffin.
 
   A. Meucci - "Annualization and general projection of
   skweness, kurtosis, and all summary statistics", GARP

Modified: pkg/Meucci/man/FitExpectationMaximization.Rd
===================================================================
--- pkg/Meucci/man/FitExpectationMaximization.Rd	2013-09-18 09:35:43 UTC (rev 3135)
+++ pkg/Meucci/man/FitExpectationMaximization.Rd	2013-09-18 11:40:27 UTC (rev 3136)
@@ -1,7 +1,6 @@
 \name{FitExpectationMaximization}
 \alias{FitExpectationMaximization}
-\title{Expectation-Maximization (EM) algorithm to recover missing observations in a time series ,
-as described in  A. Meucci, "Risk and Asset Allocation", Springer, 2005.}
+\title{Expectation-Maximization (EM) algorithm to recover missing observations in a time series.}
 \usage{
   FitExpectationMaximization(X)
 }
@@ -21,14 +20,26 @@
 \description{
   Expectation-Maximization (EM) algorithm to recover
   missing observations in a time series , as described in
-  A. Meucci, "Risk and Asset Allocation", Springer, 2005.
+  A. Meucci, "Risk and Asset Allocation", Springer, 2005,
+  section 4.6.2 "Missing data".
 }
 \author{
   Xavier Valls \email{flamejat at gmail.com}
 }
 \references{
   A. Meucci - "Exercises in Advanced Risk and Portfolio
-  Management" \url{http://symmys.com/node/170}. See
-  Meucci's script for "FitExpectationMaximization.m"
+  Management" \url{http://symmys.com/node/170}, "E 177 -
+  Expectation-Maximization algorithm for missing data:
+  formulas" See Meucci's script for
+  "FitExpectationMaximization.m"
+
+  Dempster, A. P. and Laird, M. N. and Rubin, D. B. -
+  "Maximum Likelihood from Incomplete Data Via the EM
+  Algorithm", Journal of the Royal Statistical Society,
+  1977 vol 39 pag. 1-22.
+
+  Bilmes, J. A.- "A Gentle Tutorial of the EM Algorithm and
+  its Application to Parameter Estimation for Gaussian
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/returnanalytics -r 3136


More information about the Returnanalytics-commits mailing list