[Returnanalytics-commits] r2422 - pkg/Meucci/demo

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jun 24 23:46:42 CEST 2013


Author: xavierv
Date: 2013-06-24 23:46:41 +0200 (Mon, 24 Jun 2013)
New Revision: 2422

Modified:
   pkg/Meucci/demo/S_BivariateSample.R
   pkg/Meucci/demo/S_CovarianceEvolution.R
   pkg/Meucci/demo/S_DisplayLognormalCopulaPdf.R
   pkg/Meucci/demo/S_DisplayNormalCopulaCdf.R
   pkg/Meucci/demo/S_DisplayNormalCopulaPdf.R
   pkg/Meucci/demo/S_DisplayStudentTCopulaPdf.R
   pkg/Meucci/demo/S_EllipticalNDim.R
   pkg/Meucci/demo/S_LognormalSample.R
   pkg/Meucci/demo/S_NonAnalytical.R
   pkg/Meucci/demo/S_NormalSample.R
   pkg/Meucci/demo/S_StudentTSample.R
   pkg/Meucci/demo/S_WishartCorrelation.R
Log:
- changes to display multiple plots per demo

Modified: pkg/Meucci/demo/S_BivariateSample.R
===================================================================
--- pkg/Meucci/demo/S_BivariateSample.R	2013-06-24 21:14:39 UTC (rev 2421)
+++ pkg/Meucci/demo/S_BivariateSample.R	2013-06-24 21:46:41 UTC (rev 2422)
@@ -44,12 +44,13 @@
 Z_2 = Z[, 2];
 
 # display marginals: as expected, they are normal
-
+dev.new();
 NumBins = round(10 * log(nSim));
 par( mfrow = c( 2, 1) );
 hist( Z_1, NumBins, xlab = "normal 1", ylab = "" );
 hist( Z_2, NumBins, xlab = "normal 2", ylab = "" );
 
+dev.new();
 plot( Z_1, Z_2, type = "p", xlab = "normal 1", ylab = "normal 2" );
 
 
@@ -57,7 +58,7 @@
 
 NumBins2D = round(sqrt(100 * log(nSim)));
 Z_3 = table( cut (Z_1, NumBins2D ), cut ( Z_2, NumBins2D));
-
+dev.new();
 cloud( Z_3, panel.3d.cloud = panel.3dbars, scales = list( arrows = FALSE, just = "right" ), 
 	xlab = "normal 1", ylab = "normal 2", zlab="", main = "pdf normal" );
 
@@ -70,15 +71,18 @@
 
 # plot copula
 NumBins = round(10 * log(nSim));
+dev.new();
 par( mfrow = c( 2, 1) );
 hist( U_1, NumBins, xlab = "grade 1", ylab = "", main = "" );
 hist( U_2, NumBins, xlab = "grade 2", ylab = "", main = "" );
 
 # joint sample
+dev.new();
 plot(U_1, U_2, xlab="grade 1", ylab="grade 2" );
 
 # 3d histogram
 NumBins2D = round(sqrt(100 * log(nSim)));
+dev.new();
 U_3 = table( cut (U_1, NumBins2D ), cut ( U_2, NumBins2D ));
 cloud( U_3, panel.3d.cloud = panel.3dbars, scales = list( arrows = FALSE, just = "right" ), 
 	xlab = "grade 1", ylab = "grade 2", zlab="", main = "pdf copula" );
@@ -100,7 +104,7 @@
 
 NumBins = round(10 * log(nSim));
 
-
+dev.new();
 par( mfrow = c( 2, 1) );
 # Student t distribution
 hist( X_1, NumBins, xlab = "gamma", ylab = "", main = "" );
@@ -108,10 +112,12 @@
 hist( X_2, NumBins, xlab = "lognormal", ylab = "", main = "" );
 
 # joint sample
+dev.new();
 plot(X_1, X_2, xlab="gamma", ylab="lognormal" );
 
 # 3d histogram
 NumBins2D = round(sqrt(100 * log(nSim)));
+dev.new();
 X_3 = table( cut (X_1, NumBins2D ), cut ( X_2, NumBins2D ));
 cloud( X_3, panel.3d.cloud = panel.3dbars, scales = list( arrows = FALSE, just = "right" ), 
 	xlab = "gamma", ylab = "lognormal", zlab="", main = "pdf joint distribution" );
\ No newline at end of file

Modified: pkg/Meucci/demo/S_CovarianceEvolution.R
===================================================================
--- pkg/Meucci/demo/S_CovarianceEvolution.R	2013-06-24 21:14:39 UTC (rev 2421)
+++ pkg/Meucci/demo/S_CovarianceEvolution.R	2013-06-24 21:46:41 UTC (rev 2422)
@@ -60,15 +60,18 @@
 Pick = cbind( K + 2*J - 1, K + 2*J )
            
 # horizon simulations
+dev.new();
 plot( OUstepResult$X_t[ , Pick[ 1 ] ] , OUstepResult$X_t[ , Pick[ 2 ] ] )
            
 # horizon location
+dev.new();
 plot( OUstepResult$Mu_t[ Pick[ 1 ] ] , OUstepResult$Mu_t[ Pick[ 2 ] ] )
            
 # horizon dispersion ellipsoid 
 # TwoDimEllipsoid(MuHat_t1(Pick),SigmaHat_t1(Pick,Pick),2,0,0);
            
 # starting point
+dev.new();
 plot( x0[ Pick[ 1 ] ] , x0[ Pick[ 2 ] ] )
            
 # starting generating dispersion ellipsoid

Modified: pkg/Meucci/demo/S_DisplayLognormalCopulaPdf.R
===================================================================
--- pkg/Meucci/demo/S_DisplayLognormalCopulaPdf.R	2013-06-24 21:14:39 UTC (rev 2421)
+++ pkg/Meucci/demo/S_DisplayLognormalCopulaPdf.R	2013-06-24 21:46:41 UTC (rev 2422)
@@ -1,3 +1,4 @@
+
 #'This script displays the pdf of the copula of a lognormal distribution, as described 
 #' in A. Meucci, "Risk and Asset Allocation", Springer, 2005,  Chapter 2.
 #'

Modified: pkg/Meucci/demo/S_DisplayNormalCopulaCdf.R
===================================================================
--- pkg/Meucci/demo/S_DisplayNormalCopulaCdf.R	2013-06-24 21:14:39 UTC (rev 2421)
+++ pkg/Meucci/demo/S_DisplayNormalCopulaCdf.R	2013-06-24 21:46:41 UTC (rev 2422)
@@ -1,3 +1,4 @@
+library(mvtnorm);
 #'This script displays the cdf of the copula of a normal distribution, as described 
 #' in A. Meucci, "Risk and Asset Allocation", Springer, 2005,  Chapter 2.
 #'
@@ -13,7 +14,7 @@
 Mu = c( 0, 0 );     
 r  = -0.999;            
 sigmas = c(1, 1 );    
-Sigma = diag( c( sigmas ) ) %*% rbind( c( 1, r ), c( r, 1 ) ) %*% diag( c( sigmas ) );
+Sigma = diag( sigmas ) %*% rbind( c( 1, r ), c( r, 1 ) ) %*% diag( sigmas );
 
 #############################################################################################################
 ### Grid

Modified: pkg/Meucci/demo/S_DisplayNormalCopulaPdf.R
===================================================================
--- pkg/Meucci/demo/S_DisplayNormalCopulaPdf.R	2013-06-24 21:14:39 UTC (rev 2421)
+++ pkg/Meucci/demo/S_DisplayNormalCopulaPdf.R	2013-06-24 21:46:41 UTC (rev 2422)
@@ -12,8 +12,8 @@
 ### input parameters
 Mu = rbind( 1,  -1 );     
 r  = 0.7;            
-sigmas = rbind( 1, 1 );    
-Sigma = diag( c( sigmas ) ) %*% rbind( c( 1, r ), c( r, 1 ) ) %*% diag( c( sigmas ) );
+sigmas = c( 1, 1 );    
+Sigma = diag( sigmas ) %*% rbind( c( 1, r ), c( r, 1 ) ) %*% diag( sigmas );
 
 #############################################################################################################
 ### Grid

Modified: pkg/Meucci/demo/S_DisplayStudentTCopulaPdf.R
===================================================================
--- pkg/Meucci/demo/S_DisplayStudentTCopulaPdf.R	2013-06-24 21:14:39 UTC (rev 2421)
+++ pkg/Meucci/demo/S_DisplayStudentTCopulaPdf.R	2013-06-24 21:46:41 UTC (rev 2422)
@@ -13,8 +13,8 @@
 
 Mu = rbind( 0, 0 );     
 r  = 0.5;            
-sigmas = rbind( 1, 2 );    
-Sigma = diag( c( sigmas ) ) %*% rbind( c( 1, r ), c( r, 1 ) ) %*% diag( c( sigmas ) );
+sigmas = c( 1, 2 );    
+Sigma = diag( sigmas ) %*% rbind( c( 1, r ), c( r, 1 ) ) %*% diag( sigmas );
 #nu = 1; Sigma(1,2) = 0; Sigma(2,1) = 0;
 nu = 200; 
 

Modified: pkg/Meucci/demo/S_EllipticalNDim.R
===================================================================
--- pkg/Meucci/demo/S_EllipticalNDim.R	2013-06-24 21:14:39 UTC (rev 2421)
+++ pkg/Meucci/demo/S_EllipticalNDim.R	2013-06-24 21:46:41 UTC (rev 2422)
@@ -48,11 +48,13 @@
 n = 3;
 xlabel = paste( "X_" , m );
 ylabel = paste( "X_", n );
+dev.new();
 plot( X[ , m ], X[ , n ], xlab = xlabel, ylab = ylabel);
 
 # visualize n-th marginal
 n = 4;
 xlabel = paste( "X_", m );
 NumBins = round(10 * log(nSim));
+dev.new();
 hist( X[ , n ], NumBins, xlab = xlabel, main= "histogram");
 

Modified: pkg/Meucci/demo/S_LognormalSample.R
===================================================================
--- pkg/Meucci/demo/S_LognormalSample.R	2013-06-24 21:14:39 UTC (rev 2421)
+++ pkg/Meucci/demo/S_LognormalSample.R	2013-06-24 21:46:41 UTC (rev 2422)
@@ -29,13 +29,16 @@
 ### Plots
 
 # plot over time
+dev.new();
 plot( X, main = "lognormal sample vs observation time" );
 
 # plot histogram
+dev.new();
 NumBins = round( 10 * log( nSim ) );
 hist( X, NumBins, main = "histogram of lognormal sample" );
 
 # plot empirical cdf
+dev.new();
 f = ecdf( X );
 plot( f, col = "red", main = "cdf of lognormal distribution" );
 
@@ -47,6 +50,7 @@
 
 ##################################################################################################################
 # plot empirical quantile
+dev.new();
 u= seq( 0.01, 0.99, 0.01 ); # range of quantiles (values between zero and one)
 q = quantile( X, u );
 plot( u, q, type = "l", xlab="Grade", ylab="Quantile",  lty = 1, col = "red",  main = "quantile of lognormal distribution" );

Modified: pkg/Meucci/demo/S_NonAnalytical.R
===================================================================
--- pkg/Meucci/demo/S_NonAnalytical.R	2013-06-24 21:14:39 UTC (rev 2421)
+++ pkg/Meucci/demo/S_NonAnalytical.R	2013-06-24 21:46:41 UTC (rev 2422)
@@ -35,20 +35,24 @@
 
 ##################################################################################################################
 ### Plot the sample Z
+dev.new();
 plot( Z,  xlab="simulations", ylab="Z", main = "sample vs observation time" );
 
 ##################################################################################################################
 ### Plot the histogram of Z
+dev.new();
 NumBins = round( 10 * log( nSim ) );
 hist( Z, NumBins, xlab="Z", main="sample histogram" );
 
 ##################################################################################################################
 ### Plot the empirical cdf of Z
+dev.new();
 f = ecdf( Z );
 plot( f, xlab="Z", main="empirical cdf" );
 
 ##################################################################################################################
 ### Plot the empirical quantile of Z
+dev.new();
 u= seq( 0.01, 0.99, 0.01 ); # range of quantiles (values between zero and one)
 q = quantile( Z, u );
 plot( u, q, type = "l", xlab="Grade", ylab="Quantile",  lty = 1,  main = "empirical quantile" );

Modified: pkg/Meucci/demo/S_NormalSample.R
===================================================================
--- pkg/Meucci/demo/S_NormalSample.R	2013-06-24 21:14:39 UTC (rev 2421)
+++ pkg/Meucci/demo/S_NormalSample.R	2013-06-24 21:46:41 UTC (rev 2422)
@@ -21,11 +21,13 @@
 
 ##################################################################################################################
 ### Plot the sample# plot over time
+dev.new();
 plot( X, main = "normal sample vs observation time" );
 
 
 ##################################################################################################################
 ### Plot the histogram
+dev.new();
 NumBins = round( 10 * log( nSim ) );
 hist( X, NumBins, main = "histogram of normal sample" );
 
@@ -33,6 +35,8 @@
 ### Compare empirical with exact cdfs
 
 # plot empirical cdf
+dev.new();
+
 f = ecdf( X );
 plot( f, col = "red", main = "cdf of normal distribution" );
 
@@ -43,7 +47,9 @@
 
 ##################################################################################################################
 ### Compare empirical and exact quantiles
+
 # plot empirical quantile
+dev.new();
 u= seq( 0.01, 0.99, 0.01 ); # range of quantiles (values between zero and one)
 q = quantile( X, u );
 plot( u, q, type = "l", xlab="Grade", ylab="Quantile",  lty = 1, col = "red",  main = "quantile of normal distribution" );

Modified: pkg/Meucci/demo/S_StudentTSample.R
===================================================================
--- pkg/Meucci/demo/S_StudentTSample.R	2013-06-24 21:14:39 UTC (rev 2421)
+++ pkg/Meucci/demo/S_StudentTSample.R	2013-06-24 21:46:41 UTC (rev 2422)
@@ -45,6 +45,7 @@
 ### Plot histograms
 NumBins = round(10 * log(nSim));
 
+dev.new();
 par( mfrow = c( 3, 1) );
 
 hist( X_a, NumBins, main = "built-in generator" );
@@ -66,7 +67,7 @@
 
 ##################################################################################################################
 ### Superimpose the the plots of the empirical quantiles
-
+dev.new();
 plot( u, q_a, type = "l", xlab="Grade", ylab="Quantile",  lty = 1, col = "red", main = "quantile of Student-t distribution" );
 lines( u, q_b, type = "l", lty = 1, col = "blue" );
 lines( u, q_c, type = "l", lty = 1, col = "green" );

Modified: pkg/Meucci/demo/S_WishartCorrelation.R
===================================================================
--- pkg/Meucci/demo/S_WishartCorrelation.R	2013-06-24 21:14:39 UTC (rev 2421)
+++ pkg/Meucci/demo/S_WishartCorrelation.R	2013-06-24 21:46:41 UTC (rev 2422)
@@ -53,6 +53,6 @@
 ### Analytical correlation
 corrs = sqrt( 2 ) * rhos / sqrt( 1 + rhos ^ 2);
 
-figure();
+dev.new();
 plot(rhos, corrs, xlab = expression( paste("input ", rho)), ylab = "Wishart correlation");
 lines( rhos, corrs2, col = "red" );



More information about the Returnanalytics-commits mailing list