Benjamin Christoffersen 2020-02-05
Simulate data
library(DtD)
vol <- .1
mu <- .05
dt <- .05
V_0 <- 100
t. <- (1:50 - 1) * dt
D <- c(rep(80, 27), rep( 70, length(t.) - 27))
r <- c(rep( 0, 13), rep(.02, length(t.) - 13))
set.seed(1L)
dat <- replicate(
20, simplify = FALSE, BS_sim(
vol = vol, mu = mu, dt = dt, V_0 = V_0, D = D, r = r, T. = 1))
Define estimation function.
est_func <- function(method)
sapply(dat, function(d) with(d, BS_fit(
S = S, D = D, T. = T, r = r, time = time, method = method)$ests))
est_func("iterative")
#> [,1] [,2] [,3] [,4] [,5]
#> mu 0.08604546962 0.12654194942 -0.009850022463 0.05462714588 0.05855143183
#> vol 0.08223637222 0.09502896389 0.087030244456 0.10233857006 0.10770040721
#> [,6] [,7] [,8] [,9] [,10]
#> mu 0.04356239680 0.13370529811 0.02333608252 0.05115887062 0.01909147245
#> vol 0.09878759819 0.08878884353 0.10706182848 0.09586260277 0.12393000575
#> [,11] [,12] [,13] [,14] [,15]
#> mu 0.04489488573 0.05848739645 0.009730699895 -0.09987029681 0.03241097983
#> vol 0.11050912505 0.09788922937 0.105112643845 0.10579149833 0.11062506331
#> [,16] [,17] [,18] [,19] [,20]
#> mu 0.06989114958 0.02745015968 0.04774951269 0.09290306271 0.04388845417
#> vol 0.11084627381 0.11109323262 0.10670401062 0.09758450009 0.12257363819
est_func("mle")
#> [,1] [,2] [,3] [,4] [,5]
#> mu 0.08604387363 0.12653872491 -0.009848349055 0.05445239242 0.05853292733
#> vol 0.08221778391 0.09499804443 0.087048354245 0.10081606778 0.10755232389
#> [,6] [,7] [,8] [,9] [,10]
#> mu 0.04360250673 0.13369947118 0.02326435073 0.05115768082 0.01898979648
#> vol 0.09915047264 0.08872745419 0.10648071261 0.09585133563 0.12326504059
#> [,11] [,12] [,13] [,14] [,15]
#> mu 0.04487013009 0.05850482370 0.009733128815 -0.09980623852 0.03233781954
#> vol 0.11031837433 0.09804920958 0.105132794114 0.10804681345 0.11006066662
#> [,16] [,17] [,18] [,19] [,20]
#> mu 0.06979759418 0.02748060191 0.04773611696 0.09290954853 0.04390690229
#> vol 0.11012617410 0.11132542244 0.10659535266 0.09764434944 0.12269526609
Benchmark.
microbenchmark::microbenchmark(
iterative = est_func("iterative"), mle = est_func("mle"))
#> Unit: milliseconds
#> expr min lq mean median uq max
#> iterative 33.156815 33.6001525 34.01395831 33.8769645 34.166847 38.15630
#> mle 101.966503 102.6975650 103.79996364 103.5445735 104.549712 110.53743
#> neval
#> 100
#> 100
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.