Skip to content

Commit

Permalink
Further docs tidying, bringing opre_l up to date and also improving r…
Browse files Browse the repository at this point in the history
…eferences to literature with DOI links etc
  • Loading branch information
louisaslett committed Aug 23, 2024
1 parent d23e5ce commit fe50621
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 52 deletions.
4 changes: 2 additions & 2 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#' Financial options using a Milstein discretisation
#'
#' Financial options based on scalar geometric Brownian motion, similar to Mike Giles' MCQMC06 paper, using a Milstein discretisation.
#' Financial options based on scalar geometric Brownian motion, similar to Mike Giles' MCQMC06 paper, Giles (2008), using a Milstein discretisation.
#'
#' This function is based on GPL-2 C++ code by Mike Giles.
#'
Expand All @@ -26,7 +26,7 @@
#' @author Mike Giles <[email protected]>
#'
#' @references
#' M.B. Giles. 'Improved multilevel Monte Carlo convergence using the Milstein scheme', p.343-358 in \emph{Monte Carlo and Quasi-Monte Carlo Methods 2006}, Springer, 2007.
#' Giles, M. (2008) 'Improved Multilevel Monte Carlo Convergence using the Milstein Scheme', in A. Keller, S. Heinrich, and H. Niederreiter (eds) \emph{Monte Carlo and Quasi-Monte Carlo Methods 2006}. Berlin, Heidelberg: Springer, pp. 343–358. Available at: \url{https://doi.org/10.1007/978-3-540-74496-2_20}.
#'
#' @examples
#' \dontrun{
Expand Down
6 changes: 3 additions & 3 deletions R/mlmc.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
#' @author Tigran Nagapetyan <[email protected]>
#'
#' @references
#' M.B. Giles. Multilevel Monte Carlo path simulation. \emph{Operations Research}, 56(3):607-617, 2008.
#' Giles, M.B. (2008) 'Multilevel Monte Carlo Path Simulation', \emph{Operations Research}, 56(3), pp. 607617. Available at: \url{https://doi.org/10.1287/opre.1070.0496}.
#'
#' M.B. Giles. Multilevel Monte Carlo methods. \emph{Acta Numerica}, 24:259-328, 2015.
#' Giles, M.B. (2015) 'Multilevel Monte Carlo methods', \emph{Acta Numerica}, 24, pp. 259328. Available at: \url{https://doi.org/10.1017/S096249291500001X}.
#'
#' S. Heinrich. Monte Carlo complexity of global solution of integral equations. \emph{Journal of Complexity}, 14(2):151-175, 1998.
#' Heinrich, S. (1998) 'Monte Carlo Complexity of Global Solution of Integral Equations', \emph{Journal of Complexity}, 14(2), pp. 151175. Available at: \url{https://doi.org/10.1006/jcom.1998.0471}.
#'
#' @param Lmin
#' the minimum level of refinement. Must be \eqn{\ge 2}.
Expand Down
46 changes: 26 additions & 20 deletions R/opre_l.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mu <- function(x, h) {

#' Financial options using an Euler-Maruyama discretisation
#'
#' Financial options based on scalar geometric Brownian motion and Heston models, similar to Mike Giles' original 2008 Operations Research paper, using an Euler-Maruyama discretisation
#' Financial options based on scalar geometric Brownian motion and Heston models, similar to Mike Giles' original 2008 Operations Research paper, Giles (2008), using an Euler-Maruyama discretisation
#'
#' This function is based on GPL-2 'Matlab' code by Mike Giles.
#'
Expand All @@ -39,7 +39,7 @@ mu <- function(x, h) {
#' @author Tigran Nagapetyan <[email protected]>
#'
#' @references
#' M.B. Giles. Multilevel Monte Carlo path simulation. \emph{Operations Research}, 56(3):607-617, 2008.
#' Giles, M.B. (2008) 'Multilevel Monte Carlo Path Simulation', \emph{Operations Research}, 56(3), pp. 607617. Available at: \url{https://doi.org/10.1287/opre.1070.0496}.
#'
#' @examples
#' \dontrun{
Expand All @@ -53,60 +53,66 @@ mu <- function(x, h) {
#' # -- the new MLMC driver is a little different
#' # -- switch to X_0=100 instead of X_0=1
#'
#' M <- 4 # refinement cost factor
#' N0 <- 1000 # initial samples on coarse levels
#' Lmin <- 2 # minimum refinement level
#' Lmax <- 6 # maximum refinement level
#'
#' test.res <- list()
#' for(option in 1:5) {
#' if(option==1) {
#' if(option == 1) {
#' cat("\n ---- Computing European call ---- \n")
#' N <- 2000000 # samples for convergence tests
#' N <- 1000000 # samples for convergence tests
#' L <- 5 # levels for convergence tests
#' Eps <- c(0.005, 0.01, 0.02, 0.05, 0.1)
#' } else if(option==2) {
#' } else if(option == 2) {
#' cat("\n ---- Computing Asian call ---- \n")
#' N <- 2000000 # samples for convergence tests
#' N <- 1000000 # samples for convergence tests
#' L <- 5 # levels for convergence tests
#' Eps <- c(0.005, 0.01, 0.02, 0.05, 0.1)
#' } else if(option==3) {
#' } else if(option == 3) {
#' cat("\n ---- Computing lookback call ---- \n")
#' N <- 2000000 # samples for convergence tests
#' N <- 1000000 # samples for convergence tests
#' L <- 5 # levels for convergence tests
#' Eps <- c(0.01, 0.02, 0.05, 0.1, 0.2)
#' } else if(option==4) {
#' } else if(option == 4) {
#' cat("\n ---- Computing digital call ---- \n")
#' N <- 3000000 # samples for convergence tests
#' N <- 4000000 # samples for convergence tests
#' L <- 5 # levels for convergence tests
#' Eps <- c(0.02, 0.05, 0.1, 0.2, 0.5)
#' } else if(option==5) {
#' } else if(option == 5) {
#' cat("\n ---- Computing Heston model ---- \n")
#' N <- 2000000 # samples for convergence tests
#' L <- 5 # levels for convergence tests
#' Eps <- c(0.005, 0.01, 0.02, 0.05, 0.1)
#' }
#'
#' test.res[[option]] <- mlmc.test(opre_l, M, N, L, N0, Eps, Lmin, Lmax, option=option)
#' test.res[[option]] <- mlmc.test(opre_l, N, L, N0, Eps, Lmin, Lmax, option = option)
#'
#' # print exact analytic value, based on S0=K
#' T <- 1
#' r <- 0.05
#' sig <- 0.2
#' K <- 100
#'
#' k <- 0.5*sig^2/r;
#' d1 <- (r+0.5*sig^2)*T / (sig*sqrt(T))
#' d2 <- (r-0.5*sig^2)*T / (sig*sqrt(T))
#'
#' if(option==1) {
#' if(option == 1) {
#' val <- K*( pnorm(d1) - exp(-r*T)*pnorm(d2) )
#' cat(sprintf("\n Exact value: %f, MLMC value: %f \n", val, test.res[[option]]$P[1]))
#' } else if(option==3) {
#' k <- 0.5*sig^2/r
#' } else if(option == 2) {
#' val <- NA
#' } else if(option == 3) {
#' val <- K*( pnorm(d1) - pnorm(-d1)*k - exp(-r*T)*(pnorm(d2) - pnorm(d2)*k) )
#' cat(sprintf("\n Exact value: %f, MLMC value: %f \n", val, test.res[[option]]$P[1]))
#' } else if(option==4) {
#' } else if(option == 4) {
#' val <- K*exp(-r*T)*pnorm(d2)
#' } else if(option == 5) {
#' val <- NA
#' }
#'
#' if(is.na(val)) {
#' cat(sprintf("\n Exact value unknown, MLMC value: %f \n", test.res[[option]]$P[1]))
#' } else {
#' cat(sprintf("\n Exact value: %f, MLMC value: %f \n", val, test.res[[option]]$P[1]))
#' }
#'
Expand All @@ -116,7 +122,7 @@ mu <- function(x, h) {
#' }
#'
#' # The level sampler can be called directly to retrieve the relevant level sums:
#' opre_l(l=7, N=10, option=1)
#' opre_l(l = 7, N = 10, option = 1)
#'
#' @importFrom stats rnorm
#' @export
Expand Down
1 change: 1 addition & 0 deletions R/plot.mlmc.test.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#'
#' @references
#' Giles, M.B. (2015) 'Multilevel Monte Carlo methods', \emph{Acta Numerica}, 24, pp. 259–328. Available at: \url{https://doi.org/10.1017/S096249291500001X}.
#'
#' @examples
#' \dontrun{
#' tst <- mlmc.test(opre_l, N = 2000000,
Expand Down
4 changes: 2 additions & 2 deletions man/mcqmc06_l.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/mlmc.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 26 additions & 20 deletions man/opre_l.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/mcqmc06_l.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using namespace Rcpp;

//' Financial options using a Milstein discretisation
//'
//' Financial options based on scalar geometric Brownian motion, similar to Mike Giles' MCQMC06 paper, using a Milstein discretisation.
//' Financial options based on scalar geometric Brownian motion, similar to Mike Giles' MCQMC06 paper, Giles (2008), using a Milstein discretisation.
//'
//' This function is based on GPL-2 C++ code by Mike Giles.
//'
Expand All @@ -31,7 +31,7 @@ using namespace Rcpp;
//' @author Mike Giles <[email protected]>
//'
//' @references
//' M.B. Giles. 'Improved multilevel Monte Carlo convergence using the Milstein scheme', p.343-358 in \emph{Monte Carlo and Quasi-Monte Carlo Methods 2006}, Springer, 2007.
//' Giles, M. (2008) 'Improved Multilevel Monte Carlo Convergence using the Milstein Scheme', in A. Keller, S. Heinrich, and H. Niederreiter (eds) \emph{Monte Carlo and Quasi-Monte Carlo Methods 2006}. Berlin, Heidelberg: Springer, pp. 343–358. Available at: \url{https://doi.org/10.1007/978-3-540-74496-2_20}.
//'
//' @examples
//' \dontrun{
Expand Down

0 comments on commit fe50621

Please sign in to comment.