[Returnanalytics-commits] r2235 - pkg/PerformanceAnalytics/sandbox/Meucci/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Aug 16 23:13:10 CEST 2012


Author: mkshah
Date: 2012-08-16 23:13:09 +0200 (Thu, 16 Aug 2012)
New Revision: 2235

Added:
   pkg/PerformanceAnalytics/sandbox/Meucci/R/EmpiricalMultivariateOUnCointegration.R
Log:
Creating a R script for empirical version of Multivariate OU

Added: pkg/PerformanceAnalytics/sandbox/Meucci/R/EmpiricalMultivariateOUnCointegration.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Meucci/R/EmpiricalMultivariateOUnCointegration.R	                        (rev 0)
+++ pkg/PerformanceAnalytics/sandbox/Meucci/R/EmpiricalMultivariateOUnCointegration.R	2012-08-16 21:13:09 UTC (rev 2235)
@@ -0,0 +1,27 @@
+FitOU = function ( Y, tau )
+{
+  T = nrow( Y )
+  N = ncol( Y )
+
+  X = Y[ -1 , ]
+  F = cbind( rep( 1, T-1 ), Y [ 1:T-1 ,] )
+  E_XF = t( X ) %*% F / T
+  E_FF = t( F ) %*% F / T
+  B = E_XF %*% solve( E_FF )
+
+  Th = -logm ( B [ , -1 ] ) / tau
+  Mu = solve( diag( N ) - B[ , -1 ] ) %*% B[ , 1 ]
+
+  U = F %*% t( B ) - X
+  Sig_tau = cov( U )
+
+  N = length( Mu )
+  TsT = kronecker( Th , diag( N ) ) + kronecker( diag( N ) , Th )
+
+  VecSig_tau = Sig_tau
+  dim( VecSig_tau ) = c( N^2 , 1 )
+  VecSig = solve( diag( N^2 ) - expm(- TsT * tau ) ) %*% TsT %*% VecSig_tau
+  Sig = VecSig
+  dim( Sig ) = c( N , N )
+}
+



More information about the Returnanalytics-commits mailing list