[Rquantlib-commits] r270 - in pkg/RQuantLib: . inst/unitTests

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Jul 12 03:23:18 CEST 2010


Author: edd
Date: 2010-07-12 03:23:18 +0200 (Mon, 12 Jul 2010)
New Revision: 270

Modified:
   pkg/RQuantLib/DESCRIPTION
   pkg/RQuantLib/inst/unitTests/runit.options.R
Log:
updated runit.options throughout
depend upon Rcpp (>= 0.8.4)


Modified: pkg/RQuantLib/DESCRIPTION
===================================================================
--- pkg/RQuantLib/DESCRIPTION	2010-07-10 16:51:58 UTC (rev 269)
+++ pkg/RQuantLib/DESCRIPTION	2010-07-12 01:23:18 UTC (rev 270)
@@ -24,7 +24,7 @@
  Note that while RQuantLib's code is licensed under the GPL (v2 or later),
  QuantLib itself is released under a somewhat less restrictive Open Source
  license (see QuantLib-License.txt).
-Depends: R (>= 2.10.0), Rcpp (>= 0.8.2.12)
+Depends: R (>= 2.10.0), Rcpp (>= 0.8.4)
 LinkingTo: Rcpp
 SystemRequirements: QuantLib library (>= 0.9.9) from http://quantlib.org, 
  Boost library from http://www.boost.org

Modified: pkg/RQuantLib/inst/unitTests/runit.options.R
===================================================================
--- pkg/RQuantLib/inst/unitTests/runit.options.R	2010-07-10 16:51:58 UTC (rev 269)
+++ pkg/RQuantLib/inst/unitTests/runit.options.R	2010-07-12 01:23:18 UTC (rev 270)
@@ -1,7 +1,7 @@
 
 ## American option tests based on Haug's book
 test.american.Haug <- function() {
-    ## see QL's test-suite/americanoption.cpp
+    ## see QuantLib's test-suite/americanoption.cpp
     #/* The data below are from
     #   "Option pricing formulas", E.G. Haug, McGraw-Hill 1998
     #   pag 24
@@ -11,168 +11,170 @@
     #   C++ implementation
     #
     #*/
-    Lines <- "type  strike  spot  q  r  t  v  value
-call 100.00  90.00 0.10 0.10 0.10 0.15  0.0206
-call 100.00 100.00 0.10 0.10 0.10 0.15  1.8771
-call 100.00 110.00 0.10 0.10 0.10 0.15 10.0089
-call 100.00  90.00 0.10 0.10 0.10 0.25  0.3159
-call 100.00 100.00 0.10 0.10 0.10 0.25  3.1280
-call 100.00 110.00 0.10 0.10 0.10 0.25 10.3919
-call 100.00  90.00 0.10 0.10 0.10 0.35  0.9495
-call 100.00 100.00 0.10 0.10 0.10 0.35  4.3777
-call 100.00 110.00 0.10 0.10 0.10 0.35 11.1679
-call 100.00  90.00 0.10 0.10 0.50 0.15  0.8208
-call 100.00 100.00 0.10 0.10 0.50 0.15  4.0842
-call 100.00 110.00 0.10 0.10 0.50 0.15 10.8087
-call 100.00  90.00 0.10 0.10 0.50 0.25  2.7437
-call 100.00 100.00 0.10 0.10 0.50 0.25  6.8015
-call 100.00 110.00 0.10 0.10 0.50 0.25 13.0170
-call 100.00  90.00 0.10 0.10 0.50 0.35  5.0063
-call 100.00 100.00 0.10 0.10 0.50 0.35  9.5106
-call 100.00 110.00 0.10 0.10 0.50 0.35 15.5689
-put  100.00  90.00 0.10 0.10 0.10 0.15 10.0000
-put  100.00 100.00 0.10 0.10 0.10 0.15  1.8770
-put  100.00 110.00 0.10 0.10 0.10 0.15  0.0410
-put  100.00  90.00 0.10 0.10 0.10 0.25 10.2533
-put  100.00 100.00 0.10 0.10 0.10 0.25  3.1277
-put  100.00 110.00 0.10 0.10 0.10 0.25  0.4562
-put  100.00  90.00 0.10 0.10 0.10 0.35 10.8787
-put  100.00 100.00 0.10 0.10 0.10 0.35  4.3777
-put  100.00 110.00 0.10 0.10 0.10 0.35  1.2402
-put  100.00  90.00 0.10 0.10 0.50 0.15 10.5595
-put  100.00 100.00 0.10 0.10 0.50 0.15  4.0842
-put  100.00 110.00 0.10 0.10 0.50 0.15  1.0822
-put  100.00  90.00 0.10 0.10 0.50 0.25 12.4419
-put  100.00 100.00 0.10 0.10 0.50 0.25  6.8014
-put  100.00 110.00 0.10 0.10 0.50 0.25  3.3226
-put  100.00  90.00 0.10 0.10 0.50 0.35 14.6945
-put  100.00 100.00 0.10 0.10 0.50 0.35  9.5104
-put  100.00 110.00 0.10 0.10 0.50 0.35  5.8823"
 
-    ## now loop over all tests -- note that we need a fairly loose tolerance value
-    con <- textConnection(Lines)
-    Params <- read.delim(con, sep="")
-    close(con)
-    for (i in NROW(Params)) {
-        P <- Params[i,]
-        rc <- AmericanOption(type=as.character(P$type), underlying=P$spot, strike=P$strike,
-                             dividendYield=P$q, riskFreeRate=P$r, maturity=P$t, volatility=P$v)
-        checkEquals(rc$value, P$value, tolerance=1.0e-4)
-    }
-    return()
+    AO <- AmericanOption                # shorthand
+    checkEquals(AO(type="call", strike= 100.00, underl= 90.00,  div= 0.10, riskF=0.10,  mat=0.10,  vol= 0.15)$value,  0.0206, tol=1.0e-2)
+    checkEquals(AO(type="call", strike= 100.00, underl= 100.00, div= 0.10, riskF= 0.10, mat= 0.10, vol= 0.15)$value,  1.8771, tol=1.0e-4)
+    checkEquals(AO(type="call", strike= 100.00, underl= 110.00, div= 0.10, riskF= 0.10, mat= 0.10, vol= 0.15)$value, 10.0089, tol=1.0e-3)
+    checkEquals(AO(type="call", strike= 100.00, underl=  90.00, div= 0.10, riskF= 0.10, mat= 0.10, vol= 0.25)$value,  0.3159, tol=1.0e-3)
+    checkEquals(AO(type="call", strike= 100.00, underl= 100.00, div= 0.10, riskF= 0.10, mat= 0.10, vol= 0.25)$value,  3.1280, tol=1.0e-3)
+    checkEquals(AO(type="call", strike= 100.00, underl= 110.00, div= 0.10, riskF= 0.10, mat= 0.10, vol= 0.25)$value, 10.3919, tol=1.0e-3)
+    checkEquals(AO(type="call", strike= 100.00, underl=  90.00, div= 0.10, riskF= 0.10, mat= 0.10, vol= 0.35)$value,  0.9495, tol=1.0e-3)
+    checkEquals(AO(type="call", strike= 100.00, underl= 100.00, div= 0.10, riskF= 0.10, mat= 0.10, vol= 0.35)$value,  4.3777, tol=1.0e-3)
+    checkEquals(AO(type="call", strike= 100.00, underl= 110.00, div= 0.10, riskF= 0.10, mat= 0.10, vol= 0.35)$value, 11.1679, tol=1.0e-3)
+    checkEquals(AO(type="call", strike= 100.00, underl=  90.00, div= 0.10, riskF= 0.10, mat= 0.50, vol= 0.15)$value,  0.8208, tol=1.0e-3)
+    checkEquals(AO(type="call", strike= 100.00, underl= 100.00, div= 0.10, riskF= 0.10, mat= 0.50, vol= 0.15)$value,  4.0842, tol=1.0e-3)
+    checkEquals(AO(type="call", strike= 100.00, underl= 110.00, div= 0.10, riskF= 0.10, mat= 0.50, vol= 0.15)$value, 10.8087, tol=1.0e-3)
+    checkEquals(AO(type="call", strike= 100.00, underl=  90.00, div= 0.10, riskF= 0.10, mat= 0.50, vol= 0.25)$value,  2.7437, tol=1.0e-3)
+    checkEquals(AO(type="call", strike= 100.00, underl= 100.00, div= 0.10, riskF= 0.10, mat= 0.50, vol= 0.25)$value,  6.8015, tol=1.0e-3)
+    checkEquals(AO(type="call", strike= 100.00, underl= 110.00, div= 0.10, riskF= 0.10, mat= 0.50, vol= 0.25)$value, 13.0170, tol=1.0e-3)
+    checkEquals(AO(type="call", strike= 100.00, underl=  90.00, div= 0.10, riskF= 0.10, mat= 0.50, vol= 0.35)$value,  5.0063, tol=1.0e-3)
+    checkEquals(AO(type="call", strike= 100.00, underl= 100.00, div= 0.10, riskF= 0.10, mat= 0.50, vol= 0.35)$value,  9.5106, tol=1.0e-3)
+    checkEquals(AO(type="call", strike= 100.00, underl= 110.00, div= 0.10, riskF= 0.10, mat= 0.50, vol= 0.35)$value, 15.5689, tol=1.0e-3)
+    checkEquals(AO(type="put", strike=  100.00, underl=  90.00, div= 0.10, riskF= 0.10, mat= 0.10, vol= 0.15)$value, 10.0000, tol=1.0e-3)
+    checkEquals(AO(type="put", strike=  100.00, underl= 100.00, div= 0.10, riskF= 0.10, mat= 0.10, vol= 0.15)$value,  1.8770, tol=1.0e-3)
+    checkEquals(AO(type="put", strike=  100.00, underl= 110.00, div= 0.10, riskF= 0.10, mat= 0.10, vol= 0.15)$value,  0.0410, tol=1.0e-3)
+    checkEquals(AO(type="put", strike=  100.00, underl=  90.00, div= 0.10, riskF= 0.10, mat= 0.10, vol= 0.25)$value, 10.2533, tol=1.0e-3)
+    checkEquals(AO(type="put", strike=  100.00, underl= 100.00, div= 0.10, riskF= 0.10, mat= 0.10, vol= 0.25)$value,  3.1277, tol=1.0e-3)
+    checkEquals(AO(type="put", strike=  100.00, underl= 110.00, div= 0.10, riskF= 0.10, mat= 0.10, vol= 0.25)$value,  0.4562, tol=1.0e-3)
+    checkEquals(AO(type="put", strike=  100.00, underl=  90.00, div= 0.10, riskF= 0.10, mat= 0.10, vol= 0.35)$value, 10.8787, tol=1.0e-3)
+    checkEquals(AO(type="put", strike=  100.00, underl= 100.00, div= 0.10, riskF= 0.10, mat= 0.10, vol= 0.35)$value,  4.3777, tol=1.0e-3)
+    checkEquals(AO(type="put", strike=  100.00, underl= 110.00, div= 0.10, riskF= 0.10, mat= 0.10, vol= 0.35)$value,  1.2402, tol=1.0e-3)
+    checkEquals(AO(type="put", strike=  100.00, underl=  90.00, div= 0.10, riskF= 0.10, mat= 0.50, vol= 0.15)$value, 10.5595, tol=1.0e-3)
+    checkEquals(AO(type="put", strike=  100.00, underl= 100.00, div= 0.10, riskF= 0.10, mat= 0.50, vol= 0.15)$value,  4.0842, tol=1.0e-3)
+    checkEquals(AO(type="put", strike=  100.00, underl= 110.00, div= 0.10, riskF= 0.10, mat= 0.50, vol= 0.15)$value,  1.0822, tol=1.0e-3)
+    checkEquals(AO(type="put", strike=  100.00, underl=  90.00, div= 0.10, riskF= 0.10, mat= 0.50, vol= 0.25)$value, 12.4419, tol=1.0e-3)
+    checkEquals(AO(type="put", strike=  100.00, underl= 100.00, div= 0.10, riskF= 0.10, mat= 0.50, vol= 0.25)$value,  6.8014, tol=1.0e-3)
+    checkEquals(AO(type="put", strike=  100.00, underl= 110.00, div= 0.10, riskF= 0.10, mat= 0.50, vol= 0.25)$value,  3.3226, tol=1.0e-3)
+    checkEquals(AO(type="put", strike=  100.00, underl=  90.00, div= 0.10, riskF= 0.10, mat= 0.50, vol= 0.35)$value, 14.6945, tol=1.0e-3)
+    checkEquals(AO(type="put", strike=  100.00, underl= 100.00, div= 0.10, riskF= 0.10, mat= 0.50, vol= 0.35)$value,  9.5104, tol=1.0e-3)
+    checkEquals(AO(type="put", strike=  100.00, underl= 110.00, div= 0.10, riskF= 0.10, mat= 0.50, vol= 0.35)$value,  5.8823, tol=1.0e-3)
 }
 
-## Barrier Options
-test.barrier <- function() {
-    checkEquals(BarrierOption(barrType="downin", type="call", underlying=100,
-                              strike=100, dividendYield=0.02, riskFreeRate=0.03,
-                              maturity=0.5, volatility=0.4, barrier=90)$value,
-                3.738254414)
+## Asian option tests
+test.asian <- function() {
+    ## see QuantLib's test-suite/asianoptions.cpp
 
-    checkEquals(BarrierOption("downout", barrier=95, rebate=3, type="call",
-                              strike=90, underlying=100, div=0.04, riskF=0.08,
-                              mat=0.5, vol=0.25)$value,
-                9.024567695)
+    AO <- AsianOption   	             # shorthand
+    checkEquals(AO(averageType="geometric", typ="put", strike=85, underl=80, div=-0.03, riskF=0.05, mat=0.25, vol=0.20)$value, 4.6922, tol=1.0e-4)
 
-    checkEquals(BarrierOption("downin", barrier=95, rebate=3, type="call",
-                              strike=90, underlying=100, div=0.04, riskF=0.08,
-                              mat=0.5, vol=0.25)$value,
-                7.76267021)
-    return()
+    ## data from "Implementing Derivatives Model",
+    ## Clewlow, Strickland, p.118-123
+    ## ?? checkEquals(AO(averageType="geometric", typ="put", strike=85, underl=100, div=0.03, riskF=0.06, mat=1.0, vol=0.20)$value, 4.6922, tol=1.0e-4)
+
+    ##
+    ## data from "Asian Option", Levy, 1997
+    ## in "Exotic Options: The State of the Art",
+    ## edited by Clewlow, Strickland
+
+    #checkEquals(
+    #AO("arithmetic", "put", underl=87, strike=90, div=0.06, riskF=0.025, first=0, length=11/12, mat=0.15,  fixi=2, vol=0.13)
+
+    #AsianOption(Option::Put, 90.0, 87.0, 0.06, 0.025, 0.0, 11.0/12.0, 2,
+    #      0.13, true, 1.3942835683 ,
+    #
+    ## struct DiscreteAverageData {
+    ##     Option::Type type;
+    ##     Real underlying;
+    ##     Real strike;
+    ##     Rate dividendYield;
+    ##     Rate riskFreeRate;
+    ##     Time first;
+    ##     Time length;
+    ##     Size fixings;
+    ##     Volatility volatility;
+    ##     bool controlVariate;
+    ##     Real result;
+    ## };
+
+#}
+
+## Barrier Options
+test.barrier <- function() {
+    checkEquals(BarrierOption(barrType="downin", type="call", underl=100, strike=100, div=0.02, riskF=0.03, mat=0.5, vol=0.4, barrier=90)$value, 3.738254414)
+    checkEquals(BarrierOption("downout", barrier=95, rebate=3, type="call", strike=90, underlying=100, div=0.04, riskF=0.08, mat=0.5, vol=0.25)$value, 9.024567695)
+    checkEquals(BarrierOption("downin", barrier=95, rebate=3, type="call", strike=90, underlying=100, div=0.04, riskF=0.08, mat=0.5, vol=0.25)$value, 7.76267021)
 }
 
 test.barrier.Haug <- function() {
-    ## see QL's test-suite/barrieroption.cpp
+    ## see QuantLib's test-suite/barrieroption.cpp
     #    /* The data below are from
     #     * "Option pricing formulas", E.G. Haug, McGraw-Hill 1998 pag. 72
     #     */
     #
-    #    //     barrierType, barrier, rebate,         type, strike,     s,    q,    r,    t,    v,  result, tol
-    Lines <- "barrierType  barrier  rebate  type  strike  spot  q  r  t  v  result  tol
-downout     95.0     3.0  call      90  100.0  0.04  0.08  0.50  0.25   9.0246  1.0e-4
-downout     95.0     3.0  call     100  100.0  0.04  0.08  0.50  0.25   6.7924  1.0e-4
-downout     95.0     3.0  call     110  100.0  0.04  0.08  0.50  0.25   4.8759  1.0e-4
-downout    100.0     3.0  call      90  100.0  0.04  0.08  0.50  0.25   3.0000  1.0e-4
-downout    100.0     3.0  call     100  100.0  0.04  0.08  0.50  0.25   3.0000  1.0e-4
-downout    100.0     3.0  call     110  100.0  0.04  0.08  0.50  0.25   3.0000  1.0e-4
-upout      105.0     3.0  call      90  100.0  0.04  0.08  0.50  0.25   2.6789  1.0e-4
-upout      105.0     3.0  call     100  100.0  0.04  0.08  0.50  0.25   2.3580  1.0e-4
-upout      105.0     3.0  call     110  100.0  0.04  0.08  0.50  0.25   2.3453  1.0e-4
-downin      95.0     3.0  call     90  100.0  0.04  0.08  0.50  0.25   7.7627  1.0e-4
-downin      95.0     3.0  call    100  100.0  0.04  0.08  0.50  0.25   4.0109  1.0e-4
-downin      95.0     3.0  call    110  100.0  0.04  0.08  0.50  0.25   2.0576  1.0e-4
-downin     100.0     3.0  call     90  100.0  0.04  0.08  0.50  0.25  13.8333  1.0e-4
-downin     100.0     3.0  call    100  100.0  0.04  0.08  0.50  0.25   7.8494  1.0e-4
-downin     100.0     3.0  call    110  100.0  0.04  0.08  0.50  0.25   3.9795  1.0e-4
-upin       105.0     3.0  call     90  100.0  0.04  0.08  0.50  0.25  14.1112  1.0e-4
-upin       105.0     3.0  call    100  100.0  0.04  0.08  0.50  0.25   8.4482  1.0e-4
-upin       105.0     3.0  call    110  100.0  0.04  0.08  0.50  0.25   4.5910  1.0e-4
-downout     95.0     3.0  call     90  100.0  0.04  0.08  0.50  0.30   8.8334  1.0e-4
-downout     95.0     3.0  call    100  100.0  0.04  0.08  0.50  0.30   7.0285  1.0e-4
-downout     95.0     3.0  call    110  100.0  0.04  0.08  0.50  0.30   5.4137  1.0e-4
-downout    100.0     3.0  call     90  100.0  0.04  0.08  0.50  0.30   3.0000  1.0e-4
-downout    100.0     3.0  call    100  100.0  0.04  0.08  0.50  0.30   3.0000  1.0e-4
-downout    100.0     3.0  call    110  100.0  0.04  0.08  0.50  0.30   3.0000  1.0e-4
-upout      105.0     3.0  call     90  100.0  0.04  0.08  0.50  0.30   2.6341  1.0e-4
-upout      105.0     3.0  call    100  100.0  0.04  0.08  0.50  0.30   2.4389  1.0e-4
-upout      105.0     3.0  call    110  100.0  0.04  0.08  0.50  0.30   2.4315  1.0e-4
-downin      95.0     3.0  call     90  100.0  0.04  0.08  0.50  0.30   9.0093  1.0e-4
-downin      95.0     3.0  call    100  100.0  0.04  0.08  0.50  0.30   5.1370  1.0e-4
-downin      95.0     3.0  call    110  100.0  0.04  0.08  0.50  0.30   2.8517  1.0e-4
-downin     100.0     3.0  call     90  100.0  0.04  0.08  0.50  0.30  14.8816  1.0e-4
-downin     100.0     3.0  call    100  100.0  0.04  0.08  0.50  0.30   9.2045  1.0e-4
-downin     100.0     3.0  call    110  100.0  0.04  0.08  0.50  0.30   5.3043  1.0e-4
-upin       105.0     3.0  call     90  100.0  0.04  0.08  0.50  0.30  15.2098  1.0e-4
-upin       105.0     3.0  call    100  100.0  0.04  0.08  0.50  0.30   9.7278  1.0e-4
-upin       105.0     3.0  call    110  100.0  0.04  0.08  0.50  0.30   5.8350  1.0e-4
-downout     95.0     3.0   put     90  100.0  0.04  0.08  0.50  0.25   2.2798  1.0e-4
-downout     95.0     3.0   put    100  100.0  0.04  0.08  0.50  0.25   2.2947  1.0e-4
-downout     95.0     3.0   put    110  100.0  0.04  0.08  0.50  0.25   2.6252  1.0e-4
-downout    100.0     3.0   put     90  100.0  0.04  0.08  0.50  0.25   3.0000  1.0e-4
-downout    100.0     3.0   put    100  100.0  0.04  0.08  0.50  0.25   3.0000  1.0e-4
-downout    100.0     3.0   put    110  100.0  0.04  0.08  0.50  0.25   3.0000  1.0e-4
-upout      105.0     3.0   put     90  100.0  0.04  0.08  0.50  0.25   3.7760  1.0e-4
-upout      105.0     3.0   put    100  100.0  0.04  0.08  0.50  0.25   5.4932  1.0e-4
-upout      105.0     3.0   put    110  100.0  0.04  0.08  0.50  0.25   7.5187  1.0e-4
-downin      95.0     3.0   put     90  100.0  0.04  0.08  0.50  0.25   2.9586  1.0e-4
-downin      95.0     3.0   put    100  100.0  0.04  0.08  0.50  0.25   6.5677  1.0e-4
-downin      95.0     3.0   put    110  100.0  0.04  0.08  0.50  0.25  11.9752  1.0e-4
-downin     100.0     3.0   put     90  100.0  0.04  0.08  0.50  0.25   2.2845  1.0e-4
-downin     100.0     3.0   put    100  100.0  0.04  0.08  0.50  0.25   5.9085  1.0e-4
-downin     100.0     3.0   put    110  100.0  0.04  0.08  0.50  0.25  11.6465  1.0e-4
-upin       105.0     3.0   put     90  100.0  0.04  0.08  0.50  0.25   1.4653  1.0e-4
-upin       105.0     3.0   put    100  100.0  0.04  0.08  0.50  0.25   3.3721  1.0e-4
-upin       105.0     3.0   put    110  100.0  0.04  0.08  0.50  0.25   7.0846  1.0e-4
-downout     95.0     3.0   put     90  100.0  0.04  0.08  0.50  0.30   2.4170  1.0e-4
-downout     95.0     3.0   put    100  100.0  0.04  0.08  0.50  0.30   2.4258  1.0e-4
-downout     95.0     3.0   put    110  100.0  0.04  0.08  0.50  0.30   2.6246  1.0e-4
-downout    100.0     3.0   put     90  100.0  0.04  0.08  0.50  0.30   3.0000  1.0e-4
-downout    100.0     3.0   put    100  100.0  0.04  0.08  0.50  0.30   3.0000  1.0e-4
-downout    100.0     3.0   put    110  100.0  0.04  0.08  0.50  0.30   3.0000  1.0e-4
-upout      105.0     3.0   put     90  100.0  0.04  0.08  0.50  0.30   4.2293  1.0e-4
-upout      105.0     3.0   put    100  100.0  0.04  0.08  0.50  0.30   5.8032  1.0e-4
-upout      105.0     3.0   put    110  100.0  0.04  0.08  0.50  0.30   7.5649  1.0e-4
-downin      95.0     3.0   put     90  100.0  0.04  0.08  0.50  0.30   3.8769  1.0e-4
-downin      95.0     3.0   put    100  100.0  0.04  0.08  0.50  0.30   7.7989  1.0e-4
-downin      95.0     3.0   put    110  100.0  0.04  0.08  0.50  0.30  13.3078  1.0e-4
-downin     100.0     3.0   put     90  100.0  0.04  0.08  0.50  0.30   3.3328  1.0e-4
-downin     100.0     3.0   put    100  100.0  0.04  0.08  0.50  0.30   7.2636  1.0e-4
-downin     100.0     3.0   put    110  100.0  0.04  0.08  0.50  0.30  12.9713  1.0e-4
-upin       105.0     3.0   put     90  100.0  0.04  0.08  0.50  0.30   2.0658  1.0e-4
-upin       105.0     3.0   put    100  100.0  0.04  0.08  0.50  0.30   4.4226  1.0e-4
-upin       105.0     3.0   put    110  100.0  0.04  0.08  0.50  0.30   8.3686  1.0e-4"
-
-    ## now loop over all tests -- note that we need a fairly loose tolerance value
-    con <- textConnection(Lines)
-    Params <- read.delim(con, sep="")
-    close(con)
-    for (i in NROW(Params)) {
-        P <- Params[i,]
-        rc <- BarrierOption(barrType=as.character(P$barrierType), type=as.character(P$type), underlying=P$spot, strike=P$strike,
-                            dividendYield=P$q, riskFreeRate=P$r, maturity=P$t, volatility=P$v, barrier=P$barrier)
-        checkEquals(rc$value, P$result, tolerance=0.1)
-    }
-    return(Params)
+    BO <- BarrierOption                 # shorthand
+    checkEquals(BO(barrType="downout", barrier=95.0,  rebate=3.0, type="call", strike=90,  underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value,  9.0246, tol=1.0e-4)
+    checkEquals(BO(barrType="downout", barrier=95.0,  rebate=3.0, type="call", strike=100, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value,  6.7924, tol=1.0e-4)
+    checkEquals(BO(barrType="downout", barrier=95.0,  rebate=3.0, type="call", strike=110, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value,  4.8759, tol=1.0e-4)
+    checkEquals(BO(barrType="downout", barrier=100.0, rebate=3.0, type="call", strike=90,  underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value,  3.0000, tol=1.0e-4)
+    checkEquals(BO(barrType="downout", barrier=100.0, rebate=3.0, type="call", strike=100, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value,  3.0000, tol=1.0e-4)
+    checkEquals(BO(barrType="downout", barrier=100.0, rebate=3.0, type="call", strike=110, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value,  3.0000, tol=1.0e-4)
+    checkEquals(BO(barrType="upout",   barrier=105.0, rebate=3.0, type="call", strike=90,  underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value,  2.6789, tol=1.0e-4)
+    checkEquals(BO(barrType="upout",   barrier=105.0, rebate=3.0, type="call", strike=100, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value,  2.3580, tol=1.0e-4)
+    checkEquals(BO(barrType="upout",   barrier=105.0, rebate=3.0, type="call", strike=110, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value,  2.3453, tol=1.0e-4)
+    checkEquals(BO(barrType="downin",  barrier=95.0,  rebate=3.0, type="call", strike=90,  underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value,  7.7627, tol=1.0e-4)
+    checkEquals(BO(barrType="downin",  barrier=95.0,  rebate=3.0, type="call", strike=100, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value,  4.0109, tol=1.0e-4)
+    checkEquals(BO(barrType="downin",  barrier=95.0,  rebate=3.0, type="call", strike=110, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value,  2.0576, tol=1.0e-4)
+    checkEquals(BO(barrType="downin",  barrier=100.0, rebate=3.0, type="call", strike=90,  underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value, 13.8333, tol=1.0e-4)
+    checkEquals(BO(barrType="downin",  barrier=100.0, rebate=3.0, type="call", strike=100, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value,  7.8494, tol=1.0e-4)
+    checkEquals(BO(barrType="downin",  barrier=100.0, rebate=3.0, type="call", strike=110, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value,  3.9795, tol=1.0e-4)
+    checkEquals(BO(barrType="upin",    barrier=105.0, rebate=3.0, type="call", strike=90,  underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value, 14.1112, tol=1.0e-4)
+    checkEquals(BO(barrType="upin",    barrier=105.0, rebate=3.0, type="call", strike=100, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value,  8.4482, tol=1.0e-4)
+    checkEquals(BO(barrType="upin",    barrier=105.0, rebate=3.0, type="call", strike=110, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value,  4.5910, tol=1.0e-4)
+    checkEquals(BO(barrType="downout", barrier=95.0,  rebate=3.0, type="call", strike=90,  underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value,  8.8334, tol=1.0e-4)
+    checkEquals(BO(barrType="downout", barrier=95.0,  rebate=3.0, type="call", strike=100, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value,  7.0285, tol=1.0e-4)
+    checkEquals(BO(barrType="downout", barrier=95.0,  rebate=3.0, type="call", strike=110, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value,  5.4137, tol=1.0e-4)
+    checkEquals(BO(barrType="downout", barrier=100.0, rebate=3.0, type="call", strike=90,  underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value,  3.0000, tol=1.0e-4)
+    checkEquals(BO(barrType="downout", barrier=100.0, rebate=3.0, type="call", strike=100, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value,  3.0000, tol=1.0e-4)
+    checkEquals(BO(barrType="downout", barrier=100.0, rebate=3.0, type="call", strike=110, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value,  3.0000, tol=1.0e-4)
+    checkEquals(BO(barrType="upout",   barrier=105.0, rebate=3.0, type="call", strike=90,  underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value,  2.6341, tol=1.0e-4)
+    checkEquals(BO(barrType="upout",   barrier=105.0, rebate=3.0, type="call", strike=100, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value,  2.4389, tol=1.0e-4)
+    checkEquals(BO(barrType="upout",   barrier=105.0, rebate=3.0, type="call", strike=110, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value,  2.4315, tol=1.0e-4)
+    checkEquals(BO(barrType="downin",  barrier=95.0,  rebate=3.0, type="call", strike=90,  underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value,  9.0093, tol=1.0e-4)
+    checkEquals(BO(barrType="downin",  barrier=95.0,  rebate=3.0, type="call", strike=100, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value,  5.1370, tol=1.0e-4)
+    checkEquals(BO(barrType="downin",  barrier=95.0,  rebate=3.0, type="call", strike=110, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value,  2.8517, tol=1.0e-4)
+    checkEquals(BO(barrType="downin",  barrier=100.0, rebate=3.0, type="call", strike=90,  underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value, 14.8816, tol=1.0e-4)
+    checkEquals(BO(barrType="downin",  barrier=100.0, rebate=3.0, type="call", strike=100, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value,  9.2045, tol=1.0e-4)
+    checkEquals(BO(barrType="downin",  barrier=100.0, rebate=3.0, type="call", strike=110, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value,  5.3043, tol=1.0e-4)
+    checkEquals(BO(barrType="upin",    barrier=105.0, rebate=3.0, type="call", strike=90,  underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value, 15.2098, tol=1.0e-4)
+    checkEquals(BO(barrType="upin",    barrier=105.0, rebate=3.0, type="call", strike=100, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value,  9.7278, tol=1.0e-4)
+    checkEquals(BO(barrType="upin",    barrier=105.0, rebate=3.0, type="call", strike=110, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value,  5.8350, tol=1.0e-4)
+    checkEquals(BO(barrType="downout", barrier=95.0,  rebate=3.0, type="put",  strike=90,  underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value,  2.2798, tol=1.0e-4)
+    checkEquals(BO(barrType="downout", barrier=95.0,  rebate=3.0, type="put",  strike=100, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value,  2.2947, tol=1.0e-4)
+    checkEquals(BO(barrType="downout", barrier=95.0,  rebate=3.0, type="put",  strike=110, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value,  2.6252, tol=1.0e-4)
+    checkEquals(BO(barrType="downout", barrier=100.0, rebate=3.0, type="put",  strike=90,  underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value,  3.0000, tol=1.0e-4)
+    checkEquals(BO(barrType="downout", barrier=100.0, rebate=3.0, type="put",  strike=100, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value,  3.0000, tol=1.0e-4)
+    checkEquals(BO(barrType="downout", barrier=100.0, rebate=3.0, type="put",  strike=110, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value,  3.0000, tol=1.0e-4)
+    checkEquals(BO(barrType="upout",   barrier=105.0, rebate=3.0, type="put",  strike=90,  underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value,  3.7760, tol=1.0e-4)
+    checkEquals(BO(barrType="upout",   barrier=105.0, rebate=3.0, type="put",  strike=100, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value,  5.4932, tol=1.0e-4)
+    checkEquals(BO(barrType="upout",   barrier=105.0, rebate=3.0, type="put",  strike=110, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value,  7.5187, tol=1.0e-4)
+    checkEquals(BO(barrType="downin",  barrier=95.0,  rebate=3.0, type="put",  strike=90,  underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value,  2.9586, tol=1.0e-4)
+    checkEquals(BO(barrType="downin",  barrier=95.0,  rebate=3.0, type="put",  strike=100, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value,  6.5677, tol=1.0e-4)
+    checkEquals(BO(barrType="downin",  barrier=95.0,  rebate=3.0, type="put",  strike=110, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value, 11.9752, tol=1.0e-4)
+    checkEquals(BO(barrType="downin",  barrier=100.0, rebate=3.0, type="put",  strike=90,  underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value,  2.2845, tol=1.0e-4)
+    checkEquals(BO(barrType="downin",  barrier=100.0, rebate=3.0, type="put",  strike=100, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value,  5.9085, tol=1.0e-4)
+    checkEquals(BO(barrType="downin",  barrier=100.0, rebate=3.0, type="put",  strike=110, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value, 11.6465, tol=1.0e-4)
+    checkEquals(BO(barrType="upin",    barrier=105.0, rebate=3.0, type="put",  strike=90,  underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value,  1.4653, tol=1.0e-4)
+    checkEquals(BO(barrType="upin",    barrier=105.0, rebate=3.0, type="put",  strike=100, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value,  3.3721, tol=1.0e-4)
+    checkEquals(BO(barrType="upin",    barrier=105.0, rebate=3.0, type="put",  strike=110, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.25)$value,  7.0846, tol=1.0e-4)
+    checkEquals(BO(barrType="downout", barrier=95.0,  rebate=3.0, type="put",  strike=90,  underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value,  2.4170, tol=1.0e-4)
+    checkEquals(BO(barrType="downout", barrier=95.0,  rebate=3.0, type="put",  strike=100, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value,  2.4258, tol=1.0e-4)
+    checkEquals(BO(barrType="downout", barrier=95.0,  rebate=3.0, type="put",  strike=110, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value,  2.6246, tol=1.0e-4)
+    checkEquals(BO(barrType="downout", barrier=100.0, rebate=3.0, type="put",  strike=90,  underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value,  3.0000, tol=1.0e-4)
+    checkEquals(BO(barrType="downout", barrier=100.0, rebate=3.0, type="put",  strike=100, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value,  3.0000, tol=1.0e-4)
+    checkEquals(BO(barrType="downout", barrier=100.0, rebate=3.0, type="put",  strike=110, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value,  3.0000, tol=1.0e-4)
+    checkEquals(BO(barrType="upout",   barrier=105.0, rebate=3.0, type="put",  strike=90,  underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value,  4.2293, tol=1.0e-4)
+    checkEquals(BO(barrType="upout",   barrier=105.0, rebate=3.0, type="put",  strike=100, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value,  5.8032, tol=1.0e-4)
+    checkEquals(BO(barrType="upout",   barrier=105.0, rebate=3.0, type="put",  strike=110, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value,  7.5649, tol=1.0e-4)
+    checkEquals(BO(barrType="downin",  barrier=95.0,  rebate=3.0, type="put",  strike=90,  underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value,  3.8769, tol=1.0e-4)
+    checkEquals(BO(barrType="downin",  barrier=95.0,  rebate=3.0, type="put",  strike=100, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value,  7.7989, tol=1.0e-4)
+    checkEquals(BO(barrType="downin",  barrier=95.0,  rebate=3.0, type="put",  strike=110, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value, 13.3078, tol=1.0e-4)
+    checkEquals(BO(barrType="downin",  barrier=100.0, rebate=3.0, type="put",  strike=90,  underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value,  3.3328, tol=1.0e-4)
+    checkEquals(BO(barrType="downin",  barrier=100.0, rebate=3.0, type="put",  strike=100, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value,  7.2636, tol=1.0e-4)
+    checkEquals(BO(barrType="downin",  barrier=100.0, rebate=3.0, type="put",  strike=110, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value, 12.9713, tol=1.0e-4)
+    checkEquals(BO(barrType="upin",    barrier=105.0, rebate=3.0, type="put",  strike=90,  underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value,  2.0658, tol=1.0e-4)
+    checkEquals(BO(barrType="upin",    barrier=105.0, rebate=3.0, type="put",  strike=100, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value,  4.4226, tol=1.0e-4)
+    checkEquals(BO(barrType="upin",    barrier=105.0, rebate=3.0, type="put",  strike=110, underl=100.0, div=0.04, riskF=0.08, mat=0.50, vol=0.30)$value,  8.3686, tol=1.0e-4)
 }
 
 ## Binary Options aka Digitals
@@ -188,66 +190,55 @@
 
 ## European option tests based on Haug's book
 test.european.Haug <- function() {
-    ## see QL's test-suite/europeanoption.cpp
+    ## see QuantLib's test-suite/europeanoption.cpp
     #/* The data below are from
     #   "Option pricing formulas", E.G. Haug, McGraw-Hill 1998
     #*/
     #  // pag 2-8, pg 24, p 27
     #
-    Lines <- "type  strike  spot  q  r  t  v  value tol
-call  65.00  60.00 0.00 0.08 0.25 0.30  2.1334 1.0e-4
-put   95.00 100.00 0.05 0.10 0.50 0.20  2.4648 1.0e-4
-put   19.00  19.00 0.10 0.10 0.75 0.28  1.7011 1.0e-4
-call  19.00  19.00 0.10 0.10 0.75 0.28  1.7011 1.0e-4
-call   1.60   1.56 0.08 0.06 0.50 0.12  0.0291 1.0e-4
-put   70.00  75.00 0.05 0.10 0.50 0.35  4.0870 1.0e-4
-call 100.00  90.00 0.10 0.10 0.10 0.15  0.0205 1.0e-4
-call 100.00 100.00 0.10 0.10 0.10 0.15  1.8734 1.0e-4
-call 100.00 110.00 0.10 0.10 0.10 0.15  9.9413 1.0e-4
-call 100.00  90.00 0.10 0.10 0.10 0.25  0.3150 1.0e-4
-call 100.00 100.00 0.10 0.10 0.10 0.25  3.1217 1.0e-4
-call 100.00 110.00 0.10 0.10 0.10 0.25 10.3556 1.0e-4
-call 100.00  90.00 0.10 0.10 0.10 0.35  0.9474 1.0e-4
-call 100.00 100.00 0.10 0.10 0.10 0.35  4.3693 1.0e-4
-call 100.00 110.00 0.10 0.10 0.10 0.35 11.1381 1.0e-4
-call 100.00  90.00 0.10 0.10 0.50 0.15  0.8069 1.0e-4
-call 100.00 100.00 0.10 0.10 0.50 0.15  4.0232 1.0e-4
-call 100.00 110.00 0.10 0.10 0.50 0.15 10.5769 1.0e-4
-call 100.00  90.00 0.10 0.10 0.50 0.25  2.7026 1.0e-4
-call 100.00 100.00 0.10 0.10 0.50 0.25  6.6997 1.0e-4
-call 100.00 110.00 0.10 0.10 0.50 0.25 12.7857 1.0e-4
-call 100.00  90.00 0.10 0.10 0.50 0.35  4.9329 1.0e-4
-call 100.00 100.00 0.10 0.10 0.50 0.35  9.3679 1.0e-4
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/rquantlib -r 270


More information about the Rquantlib-commits mailing list