Skip to contents

Computes a suite of diagnostic values for an MLMC estimation problem.

Usage

mlmc.test(
  mlmc_l,
  N,
  L,
  N0,
  eps.v,
  Lmin,
  Lmax,
  parallel = NA,
  silent = FALSE,
  ...
)

Arguments

mlmc_l

a user supplied function which provides the estimate for level \(l\). It must take at least two arguments, the first is the level number to be simulated and the second the number of paths. Additional arguments can be taken if desired: all additional ... arguments to this function are forwarded to the user defined mlmc_l function.

The user supplied function should return a named list containing one element named sums and second named cost, where:

sums

is a vector of length six \(\left(\sum Y_i, \sum Y_i^2, \sum Y_i^3, \sum Y_i^4, \sum X_i, \sum X_i^2\right)\) where \(Y_i\) are iid simulations with expectation \(E[P_0]\) when \(l=0\) and expectation \(E[P_l-P_{l-1}]\) when \(l>0\), and \(X_i\) are iid simulations with expectation \(E[P_l]\). Note that this differs from the main mlmc() driver, which only requires the first two of these elements in order to calculate the estimate. The remaining elements are required by mlmc.test() since they are used for convergence tests, kurtosis, and telescoping sum checks.

cost

is a scalar with the total cost of the paths simulated. For example, in the financial options samplers included in this package, this is calculated as \(NM^l\), where \(N\) is the number of paths requested in the call to the user function mlmc_l, \(M\) is the refinement cost factor (\(M=2\) for mcqmc06_l() and \(M=4\) for opre_l()), and \(l\) is the level being sampled.

See the function (and source code of) opre_l() and mcqmc06_l() in this package for an example of user supplied level samplers.

N

number of samples to use in the tests

L

number of levels to use in the tests

N0

initial number of samples which are used for the first 3 levels and for any subsequent levels which are automatically added. Must be \(> 0\).

eps.v

a vector of one or more target accuracies for the tests. Must all be \(> 0\).

Lmin

the minimum level of refinement. Must be \(\ge 2\).

Lmax

the maximum level of refinement. Must be \(\ge\) Lmin.

parallel

if an integer is supplied, R will fork parallel parallel processes. This is done for the convergence tests section by splitting the N samples as evenly as possible across cores when sampling each level. This is also done for the MLMC complexity tests by passing the parallel argument on to the mlmc() driver when targeting each accuracy level in eps.

silent

set to TRUE to supress running output (identical output can still be printed by printing the return result)

...

additional arguments which are passed on when the user supplied mlmc_l function is called

Value

An mlmc.test object which contains all the computed diagnostic values. This object can be printed or plotted (see plot.mlmc.test).

Details

See one of the example level sampler functions (e.g. opre_l()) for example usage.

This function is based on GPL-2 'Matlab' code by Mike Giles.

Author

Louis Aslett <louis.aslett@durham.ac.uk>

Mike Giles <Mike.Giles@maths.ox.ac.uk>

Tigran Nagapetyan <nagapetyan@stats.ox.ac.uk>

Examples

# \donttest{
# Example calls with realistic arguments
# Financial options using an Euler-Maruyama discretisation
tst <- mlmc.test(opre_l, N = 2000000,
                 L = 5, N0 = 1000,
                 eps.v = c(0.005, 0.01, 0.02, 0.05, 0.1),
                 Lmin = 2, Lmax = 6,
                 option = 1)
#> 
#> **********************************************************
#> *** Convergence tests, kurtosis, telescoping sum check ***
#> *** using N = 2e+06 samples                            ***
#> **********************************************************
#> 
#>  l   ave(Pf-Pc)    ave(Pf)   var(Pf-Pc)    var(Pf)    kurtosis      check       cost
#> ---------------------------------------------------------------------------------------
#>  0   1.0196e+01  1.0196e+01  1.6099e+02  1.6099e+02  0.0000e+00  0.0000e+00  1.0000e+00 
#>  1   2.1057e-01  1.0422e+01  4.4430e+00  2.0126e+02  1.9684e+01  2.6040e-01  4.0000e+00 
#>  2   2.8460e-02  1.0435e+01  1.0631e+00  2.1220e+02  1.2163e+01  2.4768e-01  1.6000e+01 
#>  3   5.9612e-03  1.0463e+01  2.7336e-01  2.1619e+02  7.5955e+00  3.4400e-01  6.4000e+01 
#>  4   1.8455e-03  1.0452e+01  6.8677e-02  2.1701e+02  6.2612e+00  1.9414e-01  2.5600e+02 
#>  5   4.9396e-04  1.0456e+01  1.7247e-02  2.1695e+02  5.9175e+00  5.9511e-02  1.0240e+03 
#> 
#> ******************************************************
#> *** Linear regression estimates of MLMC parameters ***
#> ******************************************************
#> 
#>  alpha = 2.141832  (exponent for MLMC weak convergence)
#>  beta  = 1.997038  (exponent for MLMC variance) 
#>  gamma = 2.000000  (exponent for MLMC cost) 
#> 
#> ***************************** 
#> *** MLMC complexity tests *** 
#> ***************************** 
#> 
#>   eps      value    mlmc_cost   std_cost  savings     N_l 
#> ----------------------------------------------------------- 
#> 0.0050  1.0455e+01  4.609e+07  2.963e+09    64.29  19907394   1654097    402588    101803     25802
#> 0.0100  1.0456e+01  8.493e+06  1.845e+08    21.72   4271774    355405     86235     22183
#> 0.0200  1.0449e+01  2.120e+06  4.612e+07    21.76   1066677     88207     21489      5568
#> 0.0500  1.0486e+01  2.395e+05  1.811e+06     7.56    143709     12008      2983
#> 0.1000  1.0371e+01  6.183e+04  4.527e+05     7.32     35312      2629      1000
#> 
tst
#> 
#> **********************************************************
#> *** Convergence tests, kurtosis, telescoping sum check ***
#> *** using N = 2e+06 samples                            ***
#> **********************************************************
#> 
#>  l   ave(Pf-Pc)    ave(Pf)   var(Pf-Pc)    var(Pf)    kurtosis      check       cost
#> ---------------------------------------------------------------------------------------
#>  0   1.0196e+01  1.0196e+01  1.6099e+02  1.6099e+02  0.0000e+00  0.0000e+00  1.0000e+00 
#>  1   2.1057e-01  1.0422e+01  4.4430e+00  2.0126e+02  1.9684e+01  2.6040e-01  4.0000e+00 
#>  2   2.8460e-02  1.0435e+01  1.0631e+00  2.1220e+02  1.2163e+01  2.4768e-01  1.6000e+01 
#>  3   5.9612e-03  1.0463e+01  2.7336e-01  2.1619e+02  7.5955e+00  3.4400e-01  6.4000e+01 
#>  4   1.8455e-03  1.0452e+01  6.8677e-02  2.1701e+02  6.2612e+00  1.9414e-01  2.5600e+02 
#>  5   4.9396e-04  1.0456e+01  1.7247e-02  2.1695e+02  5.9175e+00  5.9511e-02  1.0240e+03 
#> 
#> ******************************************************
#> *** Linear regression estimates of MLMC parameters ***
#> ******************************************************
#> 
#>  alpha = 2.141832  (exponent for MLMC weak convergence)
#>  beta  = 1.997038  (exponent for MLMC variance) 
#>  gamma = 2.000000  (exponent for MLMC cost) 
#> 
#> ***************************** 
#> *** MLMC complexity tests *** 
#> ***************************** 
#> 
#>   eps      value    mlmc_cost   std_cost  savings     N_l 
#> ----------------------------------------------------------- 
#> 0.0050  1.0455e+01  4.609e+07  2.963e+09    64.29  19907394   1654097    402588    101803     25802
#> 0.0100  1.0456e+01  8.493e+06  1.845e+08    21.72   4271774    355405     86235     22183
#> 0.0200  1.0449e+01  2.120e+06  4.612e+07    21.76   1066677     88207     21489      5568
#> 0.0500  1.0486e+01  2.395e+05  1.811e+06     7.56    143709     12008      2983
#> 0.1000  1.0371e+01  6.183e+04  4.527e+05     7.32     35312      2629      1000
#> 
plot(tst)


# Financial options using a Milstein discretisation
tst <- mlmc.test(mcqmc06_l, N = 20000,
                 L = 8, N0 = 200,
                 eps.v = c(0.005, 0.01, 0.02, 0.05, 0.1),
                 Lmin = 2, Lmax = 10,
                 option = 1)
#> 
#> **********************************************************
#> *** Convergence tests, kurtosis, telescoping sum check ***
#> *** using N = 20000 samples                            ***
#> **********************************************************
#> 
#>  l   ave(Pf-Pc)    ave(Pf)   var(Pf-Pc)    var(Pf)    kurtosis      check       cost
#> ---------------------------------------------------------------------------------------
#>  0   9.9752e+00  9.9752e+00  1.9507e+02  1.9507e+02  0.0000e+00  0.0000e+00  1.0000e+00 
#>  1   1.8516e-01  1.0320e+01  1.5125e-01  2.0605e+02  4.5448e+01  2.6257e-01  2.0000e+00 
#>  2   1.0286e-01  1.0354e+01  4.2899e-02  2.1216e+02  3.0678e+01  1.1259e-01  4.0000e+00 
#>  3   5.3252e-02  1.0312e+01  1.1354e-02  2.1187e+02  1.6533e+01  1.5358e-01  8.0000e+00 
#>  4   2.8970e-02  1.0798e+01  3.3326e-03  2.2566e+02  1.3345e+01  7.2728e-01  1.6000e+01 
#>  5   1.4151e-02  1.0423e+01  8.3526e-04  2.1640e+02  1.3669e+01  6.1601e-01  3.2000e+01 
#>  6   7.3986e-03  1.0704e+01  2.2395e-04  2.2544e+02  1.1963e+01  4.3338e-01  6.4000e+01 
#>  7   3.4873e-03  1.0387e+01  5.1566e-05  2.1071e+02  9.6595e+00  5.1188e-01  1.2800e+02 
#>  8   1.7975e-03  1.0456e+01  1.3383e-05  2.1602e+02  9.6563e+00  1.0901e-01  2.5600e+02 
#> 
#> ******************************************************
#> *** Linear regression estimates of MLMC parameters ***
#> ******************************************************
#> 
#>  alpha = 0.961837  (exponent for MLMC weak convergence)
#>  beta  = 1.925465  (exponent for MLMC variance) 
#>  gamma = 1.000000  (exponent for MLMC cost) 
#> 
#> ***************************** 
#> *** MLMC complexity tests *** 
#> ***************************** 
#> 
#>   eps      value    mlmc_cost   std_cost  savings     N_l 
#> ----------------------------------------------------------- 
#> 0.0050  1.0455e+01  1.354e+07  2.949e+09   217.77  11895928    238691     87730     32761     11721      4273      1647       595       200
#> 0.0100  1.0451e+01  3.392e+06  3.596e+08   106.03   2965597     57209     29757      8110      3033      1091       404       144
#> 0.0200  1.0436e+01  8.268e+05  4.809e+07    58.17    733803     14002      5317      2084       757       274        97
#> 0.0500  1.0425e+01  1.300e+05  3.693e+06    28.41    115840      2548       892       317       108        39
#> 0.1000  1.0417e+01  3.399e+04  4.814e+05    14.16     29912       873       224       104        38
#> 
tst
#> 
#> **********************************************************
#> *** Convergence tests, kurtosis, telescoping sum check ***
#> *** using N = 20000 samples                            ***
#> **********************************************************
#> 
#>  l   ave(Pf-Pc)    ave(Pf)   var(Pf-Pc)    var(Pf)    kurtosis      check       cost
#> ---------------------------------------------------------------------------------------
#>  0   9.9752e+00  9.9752e+00  1.9507e+02  1.9507e+02  0.0000e+00  0.0000e+00  1.0000e+00 
#>  1   1.8516e-01  1.0320e+01  1.5125e-01  2.0605e+02  4.5448e+01  2.6257e-01  2.0000e+00 
#>  2   1.0286e-01  1.0354e+01  4.2899e-02  2.1216e+02  3.0678e+01  1.1259e-01  4.0000e+00 
#>  3   5.3252e-02  1.0312e+01  1.1354e-02  2.1187e+02  1.6533e+01  1.5358e-01  8.0000e+00 
#>  4   2.8970e-02  1.0798e+01  3.3326e-03  2.2566e+02  1.3345e+01  7.2728e-01  1.6000e+01 
#>  5   1.4151e-02  1.0423e+01  8.3526e-04  2.1640e+02  1.3669e+01  6.1601e-01  3.2000e+01 
#>  6   7.3986e-03  1.0704e+01  2.2395e-04  2.2544e+02  1.1963e+01  4.3338e-01  6.4000e+01 
#>  7   3.4873e-03  1.0387e+01  5.1566e-05  2.1071e+02  9.6595e+00  5.1188e-01  1.2800e+02 
#>  8   1.7975e-03  1.0456e+01  1.3383e-05  2.1602e+02  9.6563e+00  1.0901e-01  2.5600e+02 
#> 
#> ******************************************************
#> *** Linear regression estimates of MLMC parameters ***
#> ******************************************************
#> 
#>  alpha = 0.961837  (exponent for MLMC weak convergence)
#>  beta  = 1.925465  (exponent for MLMC variance) 
#>  gamma = 1.000000  (exponent for MLMC cost) 
#> 
#> ***************************** 
#> *** MLMC complexity tests *** 
#> ***************************** 
#> 
#>   eps      value    mlmc_cost   std_cost  savings     N_l 
#> ----------------------------------------------------------- 
#> 0.0050  1.0455e+01  1.354e+07  2.949e+09   217.77  11895928    238691     87730     32761     11721      4273      1647       595       200
#> 0.0100  1.0451e+01  3.392e+06  3.596e+08   106.03   2965597     57209     29757      8110      3033      1091       404       144
#> 0.0200  1.0436e+01  8.268e+05  4.809e+07    58.17    733803     14002      5317      2084       757       274        97
#> 0.0500  1.0425e+01  1.300e+05  3.693e+06    28.41    115840      2548       892       317       108        39
#> 0.1000  1.0417e+01  3.399e+04  4.814e+05    14.16     29912       873       224       104        38
#> 
plot(tst)

# }

# Toy versions for CRAN tests
tst <- mlmc.test(opre_l, N = 10000,
                 L = 5, N0 = 1000,
                 eps.v = c(0.025, 0.1),
                 Lmin = 2, Lmax = 6,
                 option = 1)
#> 
#> **********************************************************
#> *** Convergence tests, kurtosis, telescoping sum check ***
#> *** using N = 10000 samples                            ***
#> **********************************************************
#> 
#>  l   ave(Pf-Pc)    ave(Pf)   var(Pf-Pc)    var(Pf)    kurtosis      check       cost
#> ---------------------------------------------------------------------------------------
#>  0   1.0232e+01  1.0232e+01  1.5823e+02  1.5823e+02  0.0000e+00  0.0000e+00  1.0000e+00 
#>  1   1.9481e-01  1.0313e+01  4.5620e+00  2.0120e+02  2.1503e+01  1.3030e-01  4.0000e+00 
#>  2   3.3953e-02  1.0629e+01  1.0900e+00  2.1325e+02  1.1524e+01  3.1512e-01  1.6000e+01 
#>  3   6.7849e-03  1.0348e+01  2.6568e-01  2.0846e+02  8.2740e+00  3.2525e-01  6.4000e+01 
#>  4   1.2933e-03  1.0592e+01  6.9911e-02  2.1665e+02  5.9317e+00  2.7516e-01  2.5600e+02 
#>  5   1.6629e-03  1.0420e+01  1.7553e-02  2.1756e+02  6.3481e+00  1.9562e-01  1.0240e+03 
#> 
#> ******************************************************
#> *** Linear regression estimates of MLMC parameters ***
#> ******************************************************
#> 
#>  alpha = 1.845878  (exponent for MLMC weak convergence)
#>  beta  = 2.000624  (exponent for MLMC variance) 
#>  gamma = 2.000000  (exponent for MLMC cost) 
#> 
#> ***************************** 
#> *** MLMC complexity tests *** 
#> ***************************** 
#> 
#>   eps      value    mlmc_cost   std_cost  savings     N_l 
#> ----------------------------------------------------------- 
#> 0.0250  1.0455e+01  1.348e+06  2.846e+07    21.11    681953     56853     13713      3428
#> 0.1000  1.0429e+01  6.355e+04  4.549e+05     7.16     35700      2963      1000
#> 

tst <- mlmc.test(mcqmc06_l, N = 10000,
                 L = 8, N0 = 1000,
                 eps.v = c(0.025, 0.1),
                 Lmin = 2, Lmax = 10,
                 option = 1)
#> 
#> **********************************************************
#> *** Convergence tests, kurtosis, telescoping sum check ***
#> *** using N = 10000 samples                            ***
#> **********************************************************
#> 
#>  l   ave(Pf-Pc)    ave(Pf)   var(Pf-Pc)    var(Pf)    kurtosis      check       cost
#> ---------------------------------------------------------------------------------------
#>  0   9.9662e+00  9.9662e+00  1.9301e+02  1.9301e+02  0.0000e+00  0.0000e+00  1.0000e+00 
#>  1   1.8497e-01  1.0252e+01  1.4717e-01  2.0805e+02  3.5050e+01  1.1762e-01  2.0000e+00 
#>  2   1.0443e-01  1.0462e+01  4.2785e-02  2.1483e+02  2.4410e+01  1.2022e-01  4.0000e+00 
#>  3   5.4997e-02  1.0541e+01  1.1994e-02  2.1655e+02  1.8253e+01  2.6352e-02  8.0000e+00 
#>  4   2.9120e-02  1.0736e+01  3.3241e-03  2.2103e+02  1.4422e+01  1.8669e-01  1.6000e+01 
#>  5   1.4115e-02  1.0361e+01  8.3478e-04  2.1369e+02  1.1162e+01  4.3886e-01  3.2000e+01 
#>  6   6.9755e-03  1.0358e+01  2.0620e-04  2.1376e+02  1.1453e+01  1.1802e-02  6.4000e+01 
#>  7   3.6329e-03  1.0607e+01  5.4272e-05  2.1635e+02  1.1230e+01  2.7890e-01  1.2800e+02 
#>  8   1.7866e-03  1.0468e+01  1.3504e-05  2.1960e+02  1.0223e+01  1.5951e-01  2.5600e+02 
#> 
#> ******************************************************
#> *** Linear regression estimates of MLMC parameters ***
#> ******************************************************
#> 
#>  alpha = 0.965073  (exponent for MLMC weak convergence)
#>  beta  = 1.923518  (exponent for MLMC variance) 
#>  gamma = 1.000000  (exponent for MLMC cost) 
#> 
#> ***************************** 
#> *** MLMC complexity tests *** 
#> ***************************** 
#> 
#>   eps      value    mlmc_cost   std_cost  savings     N_l 
#> ----------------------------------------------------------- 
#> 0.0250  1.0427e+01  5.301e+05  2.919e+07    55.06    469429      8857      3386      1412       509       172        70
#> 0.1000  1.0350e+01  3.621e+04  4.715e+05    13.02     28934      1000      1000        95        32
#>