[Returnanalytics-commits] r2390 - in pkg/Meucci: data demo

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jun 20 18:39:28 CEST 2013


Author: xavierv
Date: 2013-06-20 18:39:28 +0200 (Thu, 20 Jun 2013)
New Revision: 2390

Added:
   pkg/Meucci/data/fX.Rda
   pkg/Meucci/demo/S_FxCopulaMarginal.R
Modified:
   pkg/Meucci/demo/S_FullCodependence.R
Log:
- added script to display the empirical copula of a set of market variables and its data file 

Added: pkg/Meucci/data/fX.Rda
===================================================================
(Binary files differ)


Property changes on: pkg/Meucci/data/fX.Rda
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Modified: pkg/Meucci/demo/S_FullCodependence.R
===================================================================
--- pkg/Meucci/demo/S_FullCodependence.R	2013-06-20 16:14:08 UTC (rev 2389)
+++ pkg/Meucci/demo/S_FullCodependence.R	2013-06-20 16:39:28 UTC (rev 2390)
@@ -3,7 +3,7 @@
 #'
 #' @references
 #' \url{http://}
-#' See Meucci's script for "S_DisplayNormalCopulaPdf.m"
+#' See Meucci's script for "S_FullCodependence.m"
 #'
 #' @author Xavier Valls \email{flamejat@@gmail.com}
 #' @export

Added: pkg/Meucci/demo/S_FxCopulaMarginal.R
===================================================================
--- pkg/Meucci/demo/S_FxCopulaMarginal.R	                        (rev 0)
+++ pkg/Meucci/demo/S_FxCopulaMarginal.R	2013-06-20 16:39:28 UTC (rev 2390)
@@ -0,0 +1,62 @@
+#'This script display the empirical copula of a set of market variables, as described 
+#' in A. Meucci, "Risk and Asset Allocation", Springer, 2005,  Chapter 2.
+#'
+#' @references
+#' \url{http://}
+#' See Meucci's script for "S_FxCopulaMarginal.m"
+#'
+#' @author Xavier Valls \email{flamejat@@gmail.com}
+#' @export 
+
+### Load data and select the pair to display
+
+library(pracma)
+load( "../data/fX.Rda" )
+
+Display = c( 1, 2 );  # 1 = Spot USD/EUR; 2 = Spot USD/GBP; 3 = Spot USD/JPY; 
+
+#############################################################################################################
+### Define variables (NB: first column is time)
+
+X = apply( log( db_FX$Data[ , 2 : ncol( db_FX$Data ) ] ), 2, FUN = "diff" );
+
+#############################################################################################################
+### Compute empirical copula by sorting
+NumObs = nrow( X );
+K = ncol ( X );
+
+# Sort and get the permutation indices
+C = apply( X, 2, "order" ); 
+
+
+Copula = matrix( NaN, NumObs, K );
+
+for ( k in 1: K)
+{
+	# scatter plot
+    x  = C[ , k ];
+
+    y  = 1 : NumObs;
+    xi = 1 : NumObs;
+    yi = interp1(x, y, xi);
+    Copula[ , k ] = yi / ( NumObs + 1 );
+}
+
+############################################################################################################
+### Display
+
+# marginals
+NumBins = round(10 * log(NumObs));
+
+
+layout( matrix(c(1,2,3), 3, 1, byrow = TRUE), heights=c(1,2,1));
+
+
+hist( X[ , Display[ 2 ] ], NumBins, xlab = db_FX$Fields[[ Display[ 2 ] + 1 ]], ylab = "", main = "");
+
+# scatter plot
+plot( Copula[ , Display[ 1 ] ], Copula[ , Display[ 2 ] ], main = "Copula", 
+	xlab = db_FX$Fields[[ Display[ 2 ] + 1 ]], ylab = db_FX$Fields[[ Display[ 1 ] + 1 ]] );
+
+hist( X[ , Display[ 1 ] ], NumBins,xlab = db_FX$Fields[[ Display[ 1 ] + 1 ]], ylab = "", main = "");
+



More information about the Returnanalytics-commits mailing list