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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Sep 5 21:33:22 CEST 2013


Author: xavierv
Date: 2013-09-05 21:33:22 +0200 (Thu, 05 Sep 2013)
New Revision: 3003

Modified:
   pkg/Meucci/R/PerformIidAnalysis.R
   pkg/Meucci/demo/FullFlexProbs.R
   pkg/Meucci/demo/S_DerivativesInvariants.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_HedgeOptions.R
   pkg/Meucci/demo/S_HorizonEffect.R
   pkg/Meucci/demo/S_LinVsLogReturn.R
   pkg/Meucci/demo/S_MeanVarianceBenchmark.R
Log:
 -fixed some errors with non ASCII characters and other porting errors

Modified: pkg/Meucci/R/PerformIidAnalysis.R
===================================================================
--- pkg/Meucci/R/PerformIidAnalysis.R	2013-09-05 18:08:13 UTC (rev 3002)
+++ pkg/Meucci/R/PerformIidAnalysis.R	2013-09-05 19:33:22 UTC (rev 3003)
@@ -17,7 +17,7 @@
 #' @author Xavier Valls \email{flamejat@@gmail.com}
 #' @export
 
-PerformIidAnalysis = function( Dates = dim( Data, 1), Data, Str = "")
+PerformIidAnalysis = function( Dates = dim( Data)[1], Data, Str = "")
 {
 
 	##########################################################################################################

Modified: pkg/Meucci/demo/FullFlexProbs.R
===================================================================
--- pkg/Meucci/demo/FullFlexProbs.R	2013-09-05 18:08:13 UTC (rev 3002)
+++ pkg/Meucci/demo/FullFlexProbs.R	2013-09-05 19:33:22 UTC (rev 3003)
@@ -68,21 +68,20 @@
 # DefineProbs = "5" : partial information prox. kernel damping
 # DefineProbs = "6" : partial information: match covariance
 
-DefineProbs = "6";
+DefineProbs = 1;
 
 T = dim(X)[1];
 p = matrix( 0, T, 1 );
 
 
-if( DefineProbs = 1)
+if( DefineProbs == 1)
 {
 	# rolling window
 
         tau = 2 * 252;
         p[ 1:tau ] = 1;
         p = p / sum( p );
-}
-} else if( DefineProbs = 2 )
+} else if( DefineProbs == 2 )
 { 	
 	# exponential smoothing
 
@@ -90,14 +89,14 @@
         p   = exp( -lmd * ( T - ( 1 : T ) ) );
         p   = p / sum( p );
 
-} else if( DefineProbs = 3 )
+} else if( DefineProbs == 3 )
 { 
 	# market conditions
         Cond = Y >= 2.8;
         p[ Cond ] = 1;
         p = p / sum( p );
 
-} else if( DefineProbs = 4 )
+} else if( DefineProbs == 4 )
 { 
 	# kernel damping
         y  = 3;
@@ -105,7 +104,7 @@
         p  = dmvnorm( Y, y, h2 );
         p  = p / sum( p );
     
-} else if( DefineProbs = 5 )
+} else if( DefineProbs == 5 )
 { 
 	# partial information prox. kernel damping
         y  = 3;
@@ -113,7 +112,7 @@
         h2 = cov( 1 * diff( Y ) );
         p  = LeastInfoKernel( Y, y, h2 );
     
-} else if( DefineProbs = 6 ){ 
+} else if( DefineProbs == 6 ){ 
 	 #partial information: match covariance
 
 		l_c = 0.0055;

Modified: pkg/Meucci/demo/S_DerivativesInvariants.R
===================================================================
--- pkg/Meucci/demo/S_DerivativesInvariants.R	2013-09-05 18:08:13 UTC (rev 3002)
+++ pkg/Meucci/demo/S_DerivativesInvariants.R	2013-09-05 19:33:22 UTC (rev 3003)
@@ -29,11 +29,11 @@
 PerformIidAnalysis( 1:length(X), X, 'Changes in implied vol');
 
 Y = diff(log(derivatives$impVol[ eachFiveRowsSeq , maturityIndex, moneynessIndex ]));
-PerformIidAnalysis( 1:size(Y,1), Y, 'Changes in log of implied vol' );
+PerformIidAnalysis( 1:length( Y ), Y, 'Changes in log of implied vol' );
 
 ##################################################################################################################
 ### Multivariate test with AR(1) structure
-[T, Mat, Mon] 
+
 Dim = dim(derivatives$impVol[ eachFiveRowsSeq  , ,  ]);
 Z = matrix(log(derivatives$impVol[ eachFiveRowsSeq  , , ] ), Dim[ 1 ], Dim[ 2 ] * Dim[ 3 ]);
 # VAR(1) model by least square
@@ -41,9 +41,7 @@
 F = cbind(matrix( 1, Dim[ 1 ]-1, 1),  Z[ -length( Z[1, ] ) , ]);
 E_XF = t( X ) %*% F / Dim[ 1 ];
 E_FF = t( F ) %*% F / Dim[ 1 ];
-B = E_XF %*% (E_FF \ diag( 1,  ncol(size(E_FF) ) ) );
+B = E_XF %*% solve(E_FF);
 Eps = X - F %*% t( B ); # residuals
 
-PerformIidAnalysis(1:size(Eps,1), Eps(:,3), 'VAR(1) residuals');
-
-### EOF
\ No newline at end of file
+PerformIidAnalysis(1:dim(Eps)[1], Eps[ , 3 ], "VAR(1) residuals");

Modified: pkg/Meucci/demo/S_EstimateExpectedValueEvaluation.R
===================================================================
--- pkg/Meucci/demo/S_EstimateExpectedValueEvaluation.R	2013-09-05 18:08:13 UTC (rev 3002)
+++ pkg/Meucci/demo/S_EstimateExpectedValueEvaluation.R	2013-09-05 19:33:22 UTC (rev 3003)
@@ -1,5 +1,5 @@
-#'This script 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 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
 #' \url{http://symmys.com/node/170}
@@ -132,12 +132,12 @@
 b = barplot(Bias_G1sq + Ineff_G1sq, col = "red", main = "stress-test of estimator: x(1)*x(3)");
 barplot( Ineff_G1sq, col="blue", add = TRUE);
 lines( b, Err_G1sq);
-legend( "topleft", 1.9, c( "bias²", "ineff²", "error²" ), col = c( "red","blue", "black" ),
+legend( "topleft", 1.9, c( "bias^2", "ineff^2", "error^2" ), col = c( "red","blue", "black" ),
      lty=1, lwd=c(5,5,1),bg = "gray90" );
 
 
 b=barplot( Bias_G2sq + Ineff_G2sq , col = "red", main = "stress-test of estimator sample mean");
 barplot( Ineff_G2sq, col="blue", add = TRUE);
 lines(b, Err_G2sq);
-legend( "topleft", 1.9, c( "bias²", "ineff²", "error²" ), col = c( "red","blue", "black" ),
+legend( "topleft", 1.9, c( "bias^2", "ineff^2", "error^2" ), col = c( "red","blue", "black" ),
      lty=1, lwd=c(5,5,1),bg = "gray90" );

Modified: pkg/Meucci/demo/S_EstimateMomentsComboEvaluation.R
===================================================================
--- pkg/Meucci/demo/S_EstimateMomentsComboEvaluation.R	2013-09-05 18:08:13 UTC (rev 3002)
+++ pkg/Meucci/demo/S_EstimateMomentsComboEvaluation.R	2013-09-05 19:33:22 UTC (rev 3003)
@@ -187,23 +187,23 @@
 b = barplot( Bias_Gasq + Ineff_Gasq, col = "red", main = "stress-test of estimator a" );
 barplot( Ineff_Gasq, col = "blue", add = TRUE);
 lines( b, Err_Gasq);
-legend( "topleft", 1.9, c( "bias²", "ineff²", "error²" ), col = c( "red","blue", "black" ),
+legend( "topleft", 1.9, c( "bias^2", "ineff^2", "error^2" ), col = c( "red","blue", "black" ),
      lty=1, lwd=c(5,5,1),bg = "gray90" );
 
 b = barplot( Bias_Gbsq + Ineff_Gbsq, col = "red", main = "stress-test of estimator b" );
 barplot( Ineff_Gbsq, col = "blue", add = TRUE);
 lines( b, Err_Gbsq);
-legend( "topleft", 1.9, c( "bias²", "ineff²", "error²" ), col = c( "red","blue", "black" ),
+legend( "topleft", 1.9, c( "bias^2", "ineff^2", "error^2" ), col = c( "red","blue", "black" ),
      lty=1, lwd=c(5,5,1),bg = "gray90" );
 
 b = barplot( Bias_Gcsq + Ineff_Gcsq, col = "red", main = "stress-test of estimator c" );
 barplot( Ineff_Gcsq, col = "blue", add = TRUE);
 lines( b, Err_Gcsq);
-legend( "topleft", 1.9, c( "bias²", "ineff²", "error²" ), col = c( "red","blue", "black" ),
+legend( "topleft", 1.9, c( "bias^2", "ineff^2", "error^2" ), col = c( "red","blue", "black" ),
      lty=1, lwd=c(5,5,1),bg = "gray90" );
 
 b = barplot( Bias_Gdsq + Ineff_Gdsq, col = "red", main = "stress-test of estimator d" );
 barplot( Ineff_Gdsq, col = "blue", add = TRUE);
 lines( b, Err_Gdsq);
-legend( "topleft", 1.9, c( "bias²", "ineff²", "error²" ), col = c( "red","blue", "black" ),
+legend( "topleft", 1.9, c( "bias^2", "ineff^2", "error^2" ), col = c( "red","blue", "black" ),
      lty=1, lwd=c(5,5,1),bg = "gray90" );
\ No newline at end of file

Modified: pkg/Meucci/demo/S_EstimateQuantileEvaluation.R
===================================================================
--- pkg/Meucci/demo/S_EstimateQuantileEvaluation.R	2013-09-05 18:08:13 UTC (rev 3002)
+++ pkg/Meucci/demo/S_EstimateQuantileEvaluation.R	2013-09-05 19:33:22 UTC (rev 3003)
@@ -139,12 +139,12 @@
 b = barplot(Bias_Gesq +Ineff_Gesq , col = "red", main = "stress-test of estimator e");
 barplot( Ineff_Gesq, col="blue", add = TRUE);
 lines( b, Err_Gesq);
-legend( "topleft", 1.9, c( "bias²", "ineff²", "error²" ), col = c( "red","blue", "black" ),
+legend( "topleft", 1.9, c( "bias^2", "ineff^2", "error^2" ), col = c( "red","blue", "black" ),
      lty=1, lwd=c(5,5,1),bg = "gray90" );
 
 
 b = barplot(Bias_Gbsq+Ineff_Gbsq, col = "red", main = "stress-test of estimator b");
 barplot( Ineff_Gbsq, col="blue", add = TRUE);
 lines( b, Err_Gbsq);
-legend( "topleft", 1.9, c( "bias²", "ineff²", "error²" ), col = c( "red","blue", "black" ),
+legend( "topleft", 1.9, c( "bias^2", "ineff^2", "error^2" ), col = c( "red","blue", "black" ),
      lty=1, lwd=c(5,5,1),bg = "gray90" );
\ No newline at end of file

Modified: pkg/Meucci/demo/S_Estimator.R
===================================================================
--- pkg/Meucci/demo/S_Estimator.R	2013-09-05 18:08:13 UTC (rev 3002)
+++ pkg/Meucci/demo/S_Estimator.R	2013-09-05 19:33:22 UTC (rev 3003)
@@ -132,12 +132,12 @@
 b = barplot(Bias_G1sq + Ineff_G1sq, col = "red", main = "stress-test of estimator: x(1)*x(3)");
 barplot( Ineff_G1sq, col="blue", add = TRUE);
 lines( b, Err_G1sq);
-legend( "topleft", 1.9, c( "bias²", "ineff²", "error²" ), col = c( "red","blue", "black" ),
+legend( "topleft", 1.9, c( "bias^2", "ineff^2", "error^2" ), col = c( "red","blue", "black" ),
      lty=1, lwd=c(5,5,1),bg = "gray90" );
 
 
 b=barplot( Bias_G2sq + Ineff_G2sq , col = "red", main = "stress-test of estimator sample mean");
 barplot( Ineff_G2sq, col="blue", add = TRUE);
 lines(b, Err_G2sq);
-legend( "topleft", 1.9, c( "bias²", "ineff²", "error²" ), col = c( "red","blue", "black" ),
+legend( "topleft", 1.9, c( "bias^2", "ineff^2", "error^2" ), col = c( "red","blue", "black" ),
      lty=1, lwd=c(5,5,1),bg = "gray90" );

Modified: pkg/Meucci/demo/S_HedgeOptions.R
===================================================================
--- pkg/Meucci/demo/S_HedgeOptions.R	2013-09-05 18:08:13 UTC (rev 3002)
+++ pkg/Meucci/demo/S_HedgeOptions.R	2013-09-05 19:33:22 UTC (rev 3003)
@@ -8,11 +8,6 @@
 #' @author Xavier Valls \email{flamejat@@gmail.com}
 
 ##################################################################################################################
-### 
-### == Chapter 3 ==
-##################################################################################################################
-
-##################################################################################################################
 ### Load data
 load( "../data/implVol.Rda" );
 
@@ -105,7 +100,7 @@
 a_bs = BSCP$cash / BSCP$c * r_free * tau / 252;
 b_bs = t( BSCP$delta / BSCP$c * spot_T);
 
-printf( "OLS: a = [ %s\t]\n", sprintf("\t%7.4f", t(a) ) ));
+printf( "OLS: a = [ %s\t]\n", sprintf("\t%7.4f", t(a) ) );
 printf( "B-S: a = [ %s\t]\n", sprintf("\t%7.4f", t(a_bs) ) );
 printf( "OLS: b = [ %s\t]\n", sprintf("\t%7.4f", t(b) ) );
 printf( "B-S: b = [ %s\t]\n", sprintf("\t%7.4f", t(b_bs) ) );
@@ -113,6 +108,6 @@
 for( i in 1 : numCalls )
 {
     dev.new();
-    plot( Rsp, Rc[ , i ], xlab = "return underlying" , ylab = "return call option");
+    plot( Rsp, Rc[ , i ], xlab = "return underlying" , ylab = "return call option" );
 }
 

Modified: pkg/Meucci/demo/S_HorizonEffect.R
===================================================================
--- pkg/Meucci/demo/S_HorizonEffect.R	2013-09-05 18:08:13 UTC (rev 3002)
+++ pkg/Meucci/demo/S_HorizonEffect.R	2013-09-05 19:33:22 UTC (rev 3003)
@@ -17,7 +17,7 @@
 
 ##################################################################################################################
 # Load parameters of the model: D, muX, sigmaF, sigmaEps
-load( "../data/DB_LinearModel.mat" );
+load( "../data/linearModel.Rda" );
 
 # Specify range of investment horizon, weeks
 tauRangeWeeks = 1:52;
@@ -95,4 +95,3 @@
 lines(tauRangeWeeks, minCorrU, col = "green");
 legend( "topleft", 1.9, c( "max absolute corr", "mean absolute corr", "min absolute corr" ), col = c( "red","blue", "green" ),
      lty=1, bg = "gray90" );
-}
\ No newline at end of file

Modified: pkg/Meucci/demo/S_LinVsLogReturn.R
===================================================================
--- pkg/Meucci/demo/S_LinVsLogReturn.R	2013-09-05 18:08:13 UTC (rev 3002)
+++ pkg/Meucci/demo/S_LinVsLogReturn.R	2013-09-05 19:33:22 UTC (rev 3003)
@@ -54,7 +54,6 @@
 
 Col = rgb( 0.8, 0.8, 0.8 );
 
-subplot('Position', ( 0.05, 0.55, 0.9, 0.4 ) );
 
 par(mfrow=c(2,1));
 

Modified: pkg/Meucci/demo/S_MeanVarianceBenchmark.R
===================================================================
--- pkg/Meucci/demo/S_MeanVarianceBenchmark.R	2013-09-05 18:08:13 UTC (rev 3002)
+++ pkg/Meucci/demo/S_MeanVarianceBenchmark.R	2013-09-05 19:33:22 UTC (rev 3003)
@@ -138,7 +138,7 @@
 # frontiers in relative return space
 dev.new();
 plot( Rel_Std_Deviation, Rel_ExpectedValue, type = "l", lwd = 2, col = "blue", xlab = "TE rets.", ylab = "EOP rets.",
-	xlim =c( Rel_Std_Deviation_b[1], Rel_Std_Deviation_b[length(Rel_Std_Deviation_b)] ), ylim = c( min( Rel_ExpectedValue_b ), max( Rel_ExpectedValue_b )) ););
+	xlim =c( Rel_Std_Deviation_b[1], Rel_Std_Deviation_b[length(Rel_Std_Deviation_b)] ), ylim = c( min( Rel_ExpectedValue_b ), max( Rel_ExpectedValue_b )) );
 lines( Rel_Std_Deviation_b, Rel_ExpectedValue_b, lwd = 2, col = "red" );
 legend( "topleft", 1.9, c( "total ret", "relative" ), col = c( "blue","red" ),
      lty=1, bg = "gray90" );



More information about the Returnanalytics-commits mailing list