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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Sep 19 11:43:24 CEST 2013


Author: xavierv
Date: 2013-09-19 11:43:24 +0200 (Thu, 19 Sep 2013)
New Revision: 3142

Modified:
   pkg/Meucci/R/RandNormalInverseWishart.R
   pkg/Meucci/demo/S_AnalyzeNormalInverseWishart.R
   pkg/Meucci/demo/S_CorrelationPriorUniform.R
   pkg/Meucci/demo/S_MarkovChainMonteCarlo.R
   pkg/Meucci/man/RandNormalInverseWishart.Rd
Log:
 - updated documentation for chapter 7 demo scripts and its functions

Modified: pkg/Meucci/R/RandNormalInverseWishart.R
===================================================================
--- pkg/Meucci/R/RandNormalInverseWishart.R	2013-09-19 08:29:50 UTC (rev 3141)
+++ pkg/Meucci/R/RandNormalInverseWishart.R	2013-09-19 09:43:24 UTC (rev 3142)
@@ -1,20 +1,21 @@
-
-#' Generates a multivariate i.i.d. sample of lenght J from the normal-inverse-Wishart distribution, as described in 
+#' @title Generates a multivariate i.i.d. sample of lenght J from the normal-inverse-Wishart distribution.
+#'
+#' @description Generates a multivariate i.i.d. sample of lenght J from the normal-inverse-Wishart distribution, as described in 
 #' A. Meucci "Risk and Asset Allocation", Springer, 2005.
 #'
-#'  @param  Mu_0     : [vector]
-#'  @param  T_0      : [scalar]
-#'  @param  Sigma_0  : [matrix]
-#'  @param  nu_0     : [scalar]
-#'  @param  J        : [scalar]
+#'  @param  Mu_0      [vector]  location parameter.
+#'  @param  T_0       [scalar]  number of observations.
+#'  @param  Sigma_0   [matrix]  scatter parameter.
+#'  @param  nu_0      [scalar]  degrees of freedom. 
+#'  @param  J         [scalar]  number of simulations to compute.
 #'  
-#'  @return Mu       : [vector]
-#'  @return Sigma    : [matrix]
-#'  @return InvSigma : [matrix]
+#'  @return Mu        [vector] location parameter from the normal-inverse-Wishart distribution.
+#'  @return Sigma     [matrix] dispersion parameter from the normal-inverse-Wishart distribution.
+#'  @return InvSigma  [matrix] inverse of the dispersion parameter from the normal-inverse-Wishart distribution.
 #'
-#'  @note
-#'  Mu|Sigma   ~ N(Mu_0,Sigma/T_0)
-#'  inv(Sigma) ~ W(Nu_0,inv(Sigma_0)/Nu_0)
+#'  @note 
+#'  \deqn{\mu\| \Sigma \sim N(\mu_{0}, \frac{\Sigma}{T_{0}}) }{Mu|Sigma   ~ N(Mu_0,Sigma/T_0)}
+#'  \deqn{\Sigma^{-1} \sim W(\nu_{0},\frac{\Sigma_{0}^{-1}}{\nu_{0}})}{inv(Sigma) ~ W(Nu_0,inv(Sigma_0)/Nu_0)}
 #'
 #' @references
 #' A. Meucci - "Exercises in Advanced Risk and Portfolio Management" \url{http://symmys.com/node/170}.

Modified: pkg/Meucci/demo/S_AnalyzeNormalInverseWishart.R
===================================================================
--- pkg/Meucci/demo/S_AnalyzeNormalInverseWishart.R	2013-09-19 08:29:50 UTC (rev 3141)
+++ pkg/Meucci/demo/S_AnalyzeNormalInverseWishart.R	2013-09-19 09:43:24 UTC (rev 3142)
@@ -4,7 +4,9 @@
 #' Described in A. Meucci,"Risk and Asset Allocation",Springer, 2005, Chapter 7.
 #'
 #' @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 282 - Bayesian: normal-inverse-Wishart posterior".
+#'
 #' See Meucci's script for "S_AnalyzeNormalInverseWishart.m"
 #
 #' @author Xavier Valls \email{flamejat@@gmail.com}

Modified: pkg/Meucci/demo/S_CorrelationPriorUniform.R
===================================================================
--- pkg/Meucci/demo/S_CorrelationPriorUniform.R	2013-09-19 08:29:50 UTC (rev 3141)
+++ pkg/Meucci/demo/S_CorrelationPriorUniform.R	2013-09-19 09:43:24 UTC (rev 3142)
@@ -3,7 +3,9 @@
 #'  Chapter 7.
 #'
 #' @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 281 - Bayesian: prior on correlation".
+#'
 #' See Meucci's script for "S_CorrelationPriorUniform.m"
 #
 #' @author Xavier Valls \email{flamejat@@gmail.com}
@@ -18,13 +20,13 @@
 ### Compute correlations in all scenarios
 CorrsAsTensor = array(0, dim = c(J,N,N) );
 Eigs = NULL;
-j = 1;
+j    = 1;
 
 while( j < J )
 {
-    C = 2 * matrix( runif(K), 1, K ) - 1;
+    C    = 2 * matrix( runif(K), 1, K ) - 1;
     Corr = diag( 1, N );
-    k = 0;
+    k    = 0;
     for( n in 1 : ( N - 1 ) )
     {
         for( m in ( n + 1 ) : N )
@@ -58,7 +60,7 @@
 #####################################################################################################################
 ### Plots
 # univariate marginals
-K = nrow( CorrsAsEntries );
+K     = nrow( CorrsAsEntries );
 Nbins = round( 5 * log( J ) );
 for( k in 1 : K )
 {

Modified: pkg/Meucci/demo/S_MarkovChainMonteCarlo.R
===================================================================
--- pkg/Meucci/demo/S_MarkovChainMonteCarlo.R	2013-09-19 08:29:50 UTC (rev 3141)
+++ pkg/Meucci/demo/S_MarkovChainMonteCarlo.R	2013-09-19 09:43:24 UTC (rev 3142)
@@ -2,7 +2,9 @@
 #' Springer, 2005,  Chapter 7.
 #'
 #' @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 280 - Markov chain Monte Carlo".
+#'
 #' See Meucci's script for "S_MarkovChainMonteCarlo.m"
 #
 #' @author Xavier Valls \email{flamejat@@gmail.com}
@@ -19,9 +21,10 @@
 ##################################################################################################################
 ### Set up MH algorithm
 nSim = 10000;
-xt = matrix( NaN, nSim, 1);
+xt   = matrix( NaN, nSim, 1);
+nacc = 0;
 xt[ 1 ] = 0;
-nacc = 0;
+
 for( i in 2 : nSim )
 {
     # normal candidate
@@ -30,12 +33,13 @@
     f1 = kernel( r );
     # kernel at past
     f2 = kernel( xt[ i-1 ] );
-    prob = f1 / f2;
+    
+    prob    = f1 / f2;
     xt[ i ] = xt[ i-1 ];
     if( prob > 1 || runif(1) > (1 - prob) )
     {
         xt[ i ] = r; 
-        nacc = nacc + 1;   
+        nacc    = nacc + 1;   
     }  
 }
 ##################################################################################################################

Modified: pkg/Meucci/man/RandNormalInverseWishart.Rd
===================================================================
--- pkg/Meucci/man/RandNormalInverseWishart.Rd	2013-09-19 08:29:50 UTC (rev 3141)
+++ pkg/Meucci/man/RandNormalInverseWishart.Rd	2013-09-19 09:43:24 UTC (rev 3142)
@@ -1,27 +1,29 @@
 \name{RandNormalInverseWishart}
 \alias{RandNormalInverseWishart}
-\title{Generates a multivariate i.i.d. sample of lenght J from the normal-inverse-Wishart distribution, as described in
-A. Meucci "Risk and Asset Allocation", Springer, 2005.}
+\title{Generates a multivariate i.i.d. sample of lenght J from the normal-inverse-Wishart distribution.}
 \usage{
   RandNormalInverseWishart(Mu_0, T_0, Sigma_0, nu_0, J)
 }
 \arguments{
-  \item{Mu_0}{: [vector]}
+  \item{Mu_0}{[vector] location parameter.}
 
-  \item{T_0}{: [scalar]}
+  \item{T_0}{[scalar] number of observations.}
 
-  \item{Sigma_0}{: [matrix]}
+  \item{Sigma_0}{[matrix] scatter parameter.}
 
-  \item{nu_0}{: [scalar]}
+  \item{nu_0}{[scalar] degrees of freedom.}
 
-  \item{J}{: [scalar]}
+  \item{J}{[scalar] number of simulations to compute.}
 }
 \value{
-  Mu : [vector]
+  Mu [vector] location parameter from the
+  normal-inverse-Wishart distribution.
 
-  Sigma : [matrix]
+  Sigma [matrix] dispersion parameter from the
+  normal-inverse-Wishart distribution.
 
-  InvSigma : [matrix]
+  InvSigma [matrix] inverse of the dispersion parameter
+  from the normal-inverse-Wishart distribution.
 }
 \description{
   Generates a multivariate i.i.d. sample of lenght J from
@@ -29,8 +31,10 @@
   A. Meucci "Risk and Asset Allocation", Springer, 2005.
 }
 \note{
-  Mu|Sigma ~ N(Mu_0,Sigma/T_0) inv(Sigma) ~
-  W(Nu_0,inv(Sigma_0)/Nu_0)
+  \deqn{\mu\| \Sigma \sim N(\mu_{0}, \frac{\Sigma}{T_{0}})
+  }{Mu|Sigma ~ N(Mu_0,Sigma/T_0)} \deqn{\Sigma^{-1} \sim
+  W(\nu_{0},\frac{\Sigma_{0}^{-1}}{\nu_{0}})}{inv(Sigma) ~
+  W(Nu_0,inv(Sigma_0)/Nu_0)}
 }
 \author{
   Xavier Valls \email{flamejat at gmail.com}



More information about the Returnanalytics-commits mailing list