[Returnanalytics-commits] r2061 - pkg/PerformanceAnalytics/sandbox/Meucci/demo

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Jun 24 23:21:08 CEST 2012


Author: mkshah
Date: 2012-06-24 23:21:08 +0200 (Sun, 24 Jun 2012)
New Revision: 2061

Modified:
   pkg/PerformanceAnalytics/sandbox/Meucci/demo/HermiteGrid_demo.R
Log:
Cleaned and checked against Meucci's Matlab Code

Modified: pkg/PerformanceAnalytics/sandbox/Meucci/demo/HermiteGrid_demo.R
===================================================================
--- pkg/PerformanceAnalytics/sandbox/Meucci/demo/HermiteGrid_demo.R	2012-06-24 21:18:11 UTC (rev 2060)
+++ pkg/PerformanceAnalytics/sandbox/Meucci/demo/HermiteGrid_demo.R	2012-06-24 21:21:08 UTC (rev 2061)
@@ -1,4 +1,3 @@
-
 # This script compares the performance of plain Monte Carlo 
 # versus grid in applying Entropy Pooling to process extreme views
 # This script complements the article
@@ -6,7 +5,6 @@
 # The most recent version of this code is available at MATLAB Central - File Exchange
 library(matlab)
 
-
 ####################################################################################
 # Prior market model
 ####################################################################################
@@ -27,9 +25,7 @@
 
 # numerical (Gauss-Hermite grid) prior 
 ghqMesh = emptyMatrix
-#TODO FIXME NEED EXAMPLE data
-#load( file.choose() )
-ghqx = ghqx[[1]]
+load( "ghq1000.rda" )
 
 tmp = ( ghqx - min( ghqx ) ) / ( max( ghqx ) - min( ghqx ) ) # rescale GH zeros so they belong to [0,1]
 epsilon = 1e-10
@@ -39,7 +35,7 @@
 
 p = integrateSubIntervals(ghqMesh.X , market.cdf)
 ghqMesh.p = normalizeProb(p)
-ghqMesh.J = length(ghqMesh.X) 
+ghqMesh.J = nrow(ghqMesh.X) 
 
 ####################################################################################
 # Entropy posterior from extreme view on expectation
@@ -64,12 +60,11 @@
 # numerical (Gaussian-Hermite grid)
 Aeq = rbind( ones( 1 , ghqMesh.J ) , t( ghqMesh.X ) )
 beq = rbind( 1 , view.mu )
-ghqMeshOptimResult = EntropyProg( ghqMesh.J , emptyMatrix , emptyMatrix , Aeq , beq )
+ghqMeshOptimResult = EntropyProg( ghqMesh.p , emptyMatrix , emptyMatrix , Aeq , beq )
 
 ghqMesh.p_ = ghqMeshOptimResult$p_
 ghqMesh.KLdiv = ghqMeshOptimResult$optimizationPerformance$ml
 
-
 ####################################################################################
 # Plots
 ####################################################################################
@@ -83,6 +78,6 @@
 plot( plotDataMC$x , plotDataMC$f , type = "l" )
 
 # Gauss Hermite Grid
-plotDataGHQ = pHist(ghqMesh.X, ghqMesh.p_ , 50 )
+plotDataGHQ = pHist(data.matrix(ghqMesh.X), ghqMesh.p_ , 50 )
 plot( plotDataGHQ$x , plotDataGHQ$f , type = "l" )
 



More information about the Returnanalytics-commits mailing list