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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jul 5 01:03:54 CEST 2012


Author: mkshah
Date: 2012-07-05 01:03:54 +0200 (Thu, 05 Jul 2012)
New Revision: 2109

Modified:
   pkg/PerformanceAnalytics/sandbox/Meucci/R/HermiteGrid.R
Log:
Making hermitePolynomial executable and adding a function gaussHermiteMesh

Modified: pkg/PerformanceAnalytics/sandbox/Meucci/R/HermiteGrid.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Meucci/R/HermiteGrid.R	2012-07-04 21:49:42 UTC (rev 2108)
+++ pkg/PerformanceAnalytics/sandbox/Meucci/R/HermiteGrid.R	2012-07-04 23:03:54 UTC (rev 2109)
@@ -38,14 +38,27 @@
 {
   # convert last object to matrix
   # initialize p based on its expected dimension
-  p<-matrix(nrow=2,ncol=2)    
+  p = zeros(n+1,n+1)
   p[1, 1] = 1.0
   p[2, 1:2] = c(2,0)
-    
-  for (k in 2:n)
-  {
-    p[ k + 1, 1:k + 1] = 2 * cbind(p[k, 1:k], 0) - 2 * (k-1) * cbind(0, 0, p(k-1, 1:k-1))
+  
+  if( n >= 2 ) {
+    for (k in 2:n)
+    {
+      firstPart = 2 *  cbind(t(p[k, 1:k]), 0)
+      secondPart = 2 * (k-1) * cbind(0, 0, t(p[k-1, 1:k-1]))
+      p[ k + 1, 1:(k + 1)] = firstPart  - secondPart
+    }
   }
     
   return( p )  
 }
+
+gaussHermiteMesh = function( J )
+{
+  p = hermitePolynomial( J )
+  x = polyroot( sort( p[ nrow(p), ] ) )
+  x = Re(x) 
+                
+  return( x )
+}
\ No newline at end of file



More information about the Returnanalytics-commits mailing list