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,
  alpha = NA,
  beta = NA,
  gamma = NA,
  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 convergence tests, kurtosis, telescoping sum check.

L

number of levels to use in convergence tests, kurtosis, telescoping sum check.

N0

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

eps.v

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

Lmin

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

Lmax

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

alpha

the weak error, \(O(2^{-\alpha l})\). Must be \(> 0\) if specified. If NA then alpha will be estimated.

beta

the variance, \(O(2^{-\beta l})\). Must be \(> 0\) if specified. If NA then beta will be estimated.

gamma

the sample cost, \(O(2^{\gamma l})\). Must be \(> 0\) if specified. If NA then gamma will be estimated.

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.0209e+01  1.0209e+01  1.6139e+02  1.6139e+02  0.0000e+00  0.0000e+00  1.0000e+00 
#>  1   2.0971e-01  1.0420e+01  4.4439e+00  2.0102e+02  2.0055e+01  2.9916e-02  4.0000e+00 
#>  2   2.9164e-02  1.0443e+01  1.0641e+00  2.1243e+02  1.2387e+01  9.3236e-02  1.6000e+01 
#>  3   5.8030e-03  1.0457e+01  2.7256e-01  2.1538e+02  7.5182e+00  1.1818e-01  6.4000e+01 
#>  4   1.6226e-03  1.0450e+01  6.8529e-02  2.1643e+02  6.2241e+00  1.3021e-01  2.5600e+02 
#>  5   5.6870e-04  1.0456e+01  1.7268e-02  2.1633e+02  5.9348e+00  8.0291e-02  1.0240e+03 
#> 
#> ******************************************************
#> *** Linear regression estimates of MLMC parameters ***
#> ******************************************************
#> 
#>  alpha = 2.122090  (exponent for MLMC weak convergence)
#>  beta  = 1.997195  (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.0449e+01  4.625e+07  2.955e+09    63.88  19941583   1650853    405719    103214     25829
#> 0.0100  1.0454e+01  8.433e+06  1.838e+08    21.80   4257398    354804     85692     21643
#> 0.0200  1.0449e+01  2.127e+06  4.595e+07    21.60   1068793     88086     22057      5520
#> 0.0500  1.0440e+01  2.519e+05  1.813e+06     7.20    159399     11284      2959
#> 0.1000  1.0495e+01  6.324e+04  4.532e+05     7.17     35177      3016      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.0209e+01  1.0209e+01  1.6139e+02  1.6139e+02  0.0000e+00  0.0000e+00  1.0000e+00 
#>  1   2.0971e-01  1.0420e+01  4.4439e+00  2.0102e+02  2.0055e+01  2.9916e-02  4.0000e+00 
#>  2   2.9164e-02  1.0443e+01  1.0641e+00  2.1243e+02  1.2387e+01  9.3236e-02  1.6000e+01 
#>  3   5.8030e-03  1.0457e+01  2.7256e-01  2.1538e+02  7.5182e+00  1.1818e-01  6.4000e+01 
#>  4   1.6226e-03  1.0450e+01  6.8529e-02  2.1643e+02  6.2241e+00  1.3021e-01  2.5600e+02 
#>  5   5.6870e-04  1.0456e+01  1.7268e-02  2.1633e+02  5.9348e+00  8.0291e-02  1.0240e+03 
#> 
#> ******************************************************
#> *** Linear regression estimates of MLMC parameters ***
#> ******************************************************
#> 
#>  alpha = 2.122090  (exponent for MLMC weak convergence)
#>  beta  = 1.997195  (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.0449e+01  4.625e+07  2.955e+09    63.88  19941583   1650853    405719    103214     25829
#> 0.0100  1.0454e+01  8.433e+06  1.838e+08    21.80   4257398    354804     85692     21643
#> 0.0200  1.0449e+01  2.127e+06  4.595e+07    21.60   1068793     88086     22057      5520
#> 0.0500  1.0440e+01  2.519e+05  1.813e+06     7.20    159399     11284      2959
#> 0.1000  1.0495e+01  6.324e+04  4.532e+05     7.17     35177      3016      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   1.0133e+01  1.0133e+01  1.9810e+02  1.9810e+02  0.0000e+00  0.0000e+00  1.0000e+00 
#>  1   1.8339e-01  1.0238e+01  1.4650e-01  2.0666e+02  4.3668e+01  1.2791e-01  2.0000e+00 
#>  2   1.0178e-01  1.0207e+01  4.1696e-02  2.0649e+02  3.1277e+01  2.1643e-01  4.0000e+00 
#>  3   5.4679e-02  1.0390e+01  1.2096e-02  2.1192e+02  2.2094e+01  2.0862e-01  8.0000e+00 
#>  4   2.7491e-02  1.0312e+01  3.0769e-03  2.1030e+02  1.2999e+01  1.7120e-01  1.6000e+01 
#>  5   1.3946e-02  1.0439e+01  8.5509e-04  2.2017e+02  1.3315e+01  1.8132e-01  3.2000e+01 
#>  6   6.9500e-03  1.0260e+01  2.1296e-04  2.1398e+02  1.1626e+01  2.9709e-01  6.4000e+01 
#>  7   3.5764e-03  1.0542e+01  5.3863e-05  2.1728e+02  9.9385e+00  4.4704e-01  1.2800e+02 
#>  8   1.8070e-03  1.0587e+01  1.3390e-05  2.1707e+02  9.4222e+00  6.9319e-02  2.5600e+02 
#> 
#> ******************************************************
#> *** Linear regression estimates of MLMC parameters ***
#> ******************************************************
#> 
#>  alpha = 0.960913  (exponent for MLMC weak convergence)
#>  beta  = 1.919459  (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.0447e+01  1.355e+07  2.964e+09   218.65  11903219    229699     88580     33052     12456      4446      1600       569       220
#> 0.0100  1.0438e+01  3.363e+06  3.708e+08   110.27   2957414     56143     25072      8068      2875      1106       426       155
#> 0.0200  1.0468e+01  9.014e+05  4.565e+07    50.64    795790     15288      8075      2046       735       266        96
#> 0.0500  1.0432e+01  1.313e+05  3.758e+06    28.62    116815      2610       840       297       127        46
#> 0.1000  1.0251e+01  3.492e+04  4.486e+05    12.85     31940       613       200        65        27
#> 
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   1.0133e+01  1.0133e+01  1.9810e+02  1.9810e+02  0.0000e+00  0.0000e+00  1.0000e+00 
#>  1   1.8339e-01  1.0238e+01  1.4650e-01  2.0666e+02  4.3668e+01  1.2791e-01  2.0000e+00 
#>  2   1.0178e-01  1.0207e+01  4.1696e-02  2.0649e+02  3.1277e+01  2.1643e-01  4.0000e+00 
#>  3   5.4679e-02  1.0390e+01  1.2096e-02  2.1192e+02  2.2094e+01  2.0862e-01  8.0000e+00 
#>  4   2.7491e-02  1.0312e+01  3.0769e-03  2.1030e+02  1.2999e+01  1.7120e-01  1.6000e+01 
#>  5   1.3946e-02  1.0439e+01  8.5509e-04  2.2017e+02  1.3315e+01  1.8132e-01  3.2000e+01 
#>  6   6.9500e-03  1.0260e+01  2.1296e-04  2.1398e+02  1.1626e+01  2.9709e-01  6.4000e+01 
#>  7   3.5764e-03  1.0542e+01  5.3863e-05  2.1728e+02  9.9385e+00  4.4704e-01  1.2800e+02 
#>  8   1.8070e-03  1.0587e+01  1.3390e-05  2.1707e+02  9.4222e+00  6.9319e-02  2.5600e+02 
#> 
#> ******************************************************
#> *** Linear regression estimates of MLMC parameters ***
#> ******************************************************
#> 
#>  alpha = 0.960913  (exponent for MLMC weak convergence)
#>  beta  = 1.919459  (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.0447e+01  1.355e+07  2.964e+09   218.65  11903219    229699     88580     33052     12456      4446      1600       569       220
#> 0.0100  1.0438e+01  3.363e+06  3.708e+08   110.27   2957414     56143     25072      8068      2875      1106       426       155
#> 0.0200  1.0468e+01  9.014e+05  4.565e+07    50.64    795790     15288      8075      2046       735       266        96
#> 0.0500  1.0432e+01  1.313e+05  3.758e+06    28.62    116815      2610       840       297       127        46
#> 0.1000  1.0251e+01  3.492e+04  4.486e+05    12.85     31940       613       200        65        27
#> 
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.0144e+01  1.0144e+01  1.5933e+02  1.5933e+02  0.0000e+00  0.0000e+00  1.0000e+00 
#>  1   2.0461e-01  1.0494e+01  4.3545e+00  2.0017e+02  1.6552e+01  1.6836e-01  4.0000e+00 
#>  2   3.4172e-02  1.0188e+01  1.0920e+00  2.0313e+02  1.3486e+01  3.8611e-01  1.6000e+01 
#>  3   2.7394e-03  1.0609e+01  2.7241e-01  2.1473e+02  8.9020e+00  4.7445e-01  6.4000e+01 
#>  4   4.6225e-03  1.0487e+01  7.0387e-02  2.2204e+02  6.2642e+00  1.4175e-01  2.5600e+02 
#>  5   2.3568e-03  1.0375e+01  1.6529e-02  2.1034e+02  5.6902e+00  1.2895e-01  1.0240e+03 
#> 
#> ******************************************************
#> *** Linear regression estimates of MLMC parameters ***
#> ******************************************************
#> 
#>  alpha = 1.576591  (exponent for MLMC weak convergence)
#>  beta  = 2.003820  (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.0442e+01  1.352e+06  2.932e+07    21.68    682155     56440     13888      3468
#> 0.1000  1.0326e+01  6.651e+04  4.333e+05     6.52     38193      3079      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.7083e+00  9.7083e+00  1.8872e+02  1.8872e+02  0.0000e+00  0.0000e+00  1.0000e+00 
#>  1   1.8889e-01  1.0493e+01  1.5689e-01  2.1033e+02  4.2469e+01  6.9418e-01  2.0000e+00 
#>  2   1.0293e-01  1.0345e+01  4.1077e-02  2.1021e+02  2.5473e+01  2.8726e-01  4.0000e+00 
#>  3   5.2791e-02  1.0138e+01  1.1696e-02  2.1027e+02  2.0845e+01  2.9683e-01  8.0000e+00 
#>  4   2.7545e-02  1.0462e+01  3.1582e-03  2.1956e+02  1.3111e+01  3.3625e-01  1.6000e+01 
#>  5   1.4108e-02  1.0503e+01  7.9526e-04  2.1093e+02  1.2555e+01  2.9865e-02  3.2000e+01 
#>  6   6.8579e-03  1.0170e+01  2.0129e-04  2.1102e+02  9.9169e+00  3.8931e-01  6.4000e+01 
#>  7   3.5937e-03  1.0490e+01  5.4733e-05  2.1709e+02  1.2669e+01  3.6073e-01  1.2800e+02 
#>  8   1.7843e-03  1.0185e+01  1.3757e-05  2.1383e+02  9.7348e+00  3.4885e-01  2.5600e+02 
#> 
#> ******************************************************
#> *** Linear regression estimates of MLMC parameters ***
#> ******************************************************
#> 
#>  alpha = 0.965258  (exponent for MLMC weak convergence)
#>  beta  = 1.924650  (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.0446e+01  5.278e+05  2.881e+07    54.59    468086      9101      3436      1207       505       183        65
#> 0.1000  1.0334e+01  3.549e+04  4.684e+05    13.20     28562      1000      1000        76        20
#>