[Rquantlib-commits] r277 - in pkg/RQuantLib: R inst inst/unitTests man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Aug 2 18:45:46 CEST 2010
Author: edd
Date: 2010-08-02 18:45:46 +0200 (Mon, 02 Aug 2010)
New Revision: 277
Modified:
pkg/RQuantLib/R/asian.R
pkg/RQuantLib/inst/ChangeLog
pkg/RQuantLib/inst/unitTests/runit.options.R
pkg/RQuantLib/man/AsianOption.Rd
Log:
added asian arithm. averaging unit tests
made maturity parameter optional / unused for arithm averaging
removed two old and unused parameters
Modified: pkg/RQuantLib/R/asian.R
===================================================================
--- pkg/RQuantLib/R/asian.R 2010-07-21 04:23:24 UTC (rev 276)
+++ pkg/RQuantLib/R/asian.R 2010-08-02 16:45:46 UTC (rev 277)
@@ -24,17 +24,23 @@
AsianOption <- function(averageType, type, underlying, strike, dividendYield,
riskFreeRate, maturity, volatility,
- first, length, fixings,
- timeSteps=150, gridPoints=151) {
+ first, length, fixings) {
UseMethod("AsianOption")
}
AsianOption.default <- function(averageType, type, underlying, strike, dividendYield,
riskFreeRate, maturity, volatility,
- first=0, length=0, fixings=0,
- timeSteps=150, gridPoints=151) {
+ first=0, length=0, fixings=0) {
averageType <- match.arg(averageType, c("geometric", "arithmetic"))
type <- match.arg(type, c("call", "put"))
+ if (missing(maturity)) {
+ if (averageType=="geometric") {
+ warning("Geometric Asian Option requires maturity argument")
+ return(NULL)
+ } else {
+ maturity <- 1.0 # actually unused for arithmetic option case
+ }
+ }
val <- .Call("QL_AsianOption",
list(averageType=as.character(averageType),
type=as.character(type),
@@ -46,15 +52,12 @@
volatility=as.double(volatility),
first=as.double(first),
length=as.double(length),
- fixings=as.double(fixings),
- timeSteps=as.integer(timeSteps),
- gridPoints=as.integer(gridPoints)),
+ fixings=as.double(fixings)),
PACKAGE="RQuantLib")
class(val) <- c("AsianOption","Option")
val
}
-
plot.Option <- function(x, ...) {
warning("No plotting available for class", class(x)[1],"\n")
invisible(x)
Modified: pkg/RQuantLib/inst/ChangeLog
===================================================================
--- pkg/RQuantLib/inst/ChangeLog 2010-07-21 04:23:24 UTC (rev 276)
+++ pkg/RQuantLib/inst/ChangeLog 2010-08-02 16:45:46 UTC (rev 277)
@@ -1,3 +1,11 @@
+2010-08-02 Dirk Eddelbuettel <edd at debian.org>
+
+ * inst/unitTests/runitOptions.R: Updated asian option test for
+ arithmetic averaging based on QuantLib's test-suite code
+ * R/asian.R: Removed two unused parameters, updated use of maturity
+ used only for geometric averaging
+ * man/asian.Rd: Corresponding manual page update
+
2010-07-05 Khanh Nguyen <knguyen at cs.umb.edu>
* src/asian.cpp: Added arithmetic average case
Modified: pkg/RQuantLib/inst/unitTests/runit.options.R
===================================================================
--- pkg/RQuantLib/inst/unitTests/runit.options.R 2010-07-21 04:23:24 UTC (rev 276)
+++ pkg/RQuantLib/inst/unitTests/runit.options.R 2010-08-02 16:45:46 UTC (rev 277)
@@ -55,40 +55,45 @@
test.asian <- function() {
## see QuantLib's test-suite/asianoptions.cpp
- 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)
+ AO <- AsianOption # shorthand
- ## 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)
+ 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)
- ##
## data from "Asian Option", Levy, 1997
## in "Exotic Options: The State of the Art",
## edited by Clewlow, Strickland
+ checkEquals(AO("arithmetic", "put", underl=90.0, strike=87.0, div=0.06, riskF=0.025, first=0.0, length=11.0/12.0, fixings=2, vol=0.13)$value, 1.3942835683, tol=1.0e-2)
+ checkEquals(AO("arithmetic", "put", underl=90.0, strike=87.0, div=0.06, riskF=0.025, first=0.0, length=11.0/12.0, fixings=4, vol=0.13)$value, 1.5852442983, tol=1.0e-2)
+ checkEquals(AO("arithmetic", "put", underl=90.0, strike=87.0, div=0.06, riskF=0.025, first=0.0, length=11.0/12.0, fixings=8, vol=0.13)$value, 1.66970673, tol=1.0e-2)
+ checkEquals(AO("arithmetic", "put", underl=90.0, strike=87.0, div=0.06, riskF=0.025, first=0.0, length=11.0/12.0, fixings=12, vol=0.13)$value, 1.6980019214, tol=1.0e-2)
+ checkEquals(AO("arithmetic", "put", underl=90.0, strike=87.0, div=0.06, riskF=0.025, first=0.0, length=11.0/12.0, fixings=26, vol=0.13)$value, 1.7255070456, tol=1.0e-2)
+ checkEquals(AO("arithmetic", "put", underl=90.0, strike=87.0, div=0.06, riskF=0.025, first=0.0, length=11.0/12.0, fixings=52, vol=0.13)$value, 1.7401553533, tol=1.0e-2)
+ checkEquals(AO("arithmetic", "put", underl=90.0, strike=87.0, div=0.06, riskF=0.025, first=0.0, length=11.0/12.0, fixings=100, vol=0.13)$value, 1.7478303712, tol=1.0e-2)
+ checkEquals(AO("arithmetic", "put", underl=90.0, strike=87.0, div=0.06, riskF=0.025, first=0.0, length=11.0/12.0, fixings=250, vol=0.13)$value, 1.7490291943, tol=1.0e-2)
+ checkEquals(AO("arithmetic", "put", underl=90.0, strike=87.0, div=0.06, riskF=0.025, first=0.0, length=11.0/12.0, fixings=500, vol=0.13)$value, 1.7515113291, tol=1.0e-2)
+ checkEquals(AO("arithmetic", "put", underl=90.0, strike=87.0, div=0.06, riskF=0.025, first=0.0, length=11.0/12.0, fixings=1000, vol=0.13)$value, 1.7537344885, tol=1.0e-2)
+ checkEquals(AO("arithmetic", "put", underl=90.0, strike=87.0, div=0.06, riskF=0.025, first=1.0/12.0, length=11.0/12.0, fixings=2, vol=0.13)$value, 1.8496053697, tol=1.0e-2)
+ checkEquals(AO("arithmetic", "put", underl=90.0, strike=87.0, div=0.06, riskF=0.025, first=1.0/12.0, length=11.0/12.0, fixings=4, vol=0.13)$value, 2.0111495205, tol=1.0e-2)
+ checkEquals(AO("arithmetic", "put", underl=90.0, strike=87.0, div=0.06, riskF=0.025, first=1.0/12.0, length=11.0/12.0, fixings=8, vol=0.13)$value, 2.0852138818, tol=1.0e-2)
+ checkEquals(AO("arithmetic", "put", underl=90.0, strike=87.0, div=0.06, riskF=0.025, first=1.0/12.0, length=11.0/12.0, fixings=12, vol=0.13)$value, 2.1105094397, tol=1.0e-2)
+ checkEquals(AO("arithmetic", "put", underl=90.0, strike=87.0, div=0.06, riskF=0.025, first=1.0/12.0, length=11.0/12.0, fixings=26, vol=0.13)$value, 2.1346526695, tol=1.0e-2)
+ checkEquals(AO("arithmetic", "put", underl=90.0, strike=87.0, div=0.06, riskF=0.025, first=1.0/12.0, length=11.0/12.0, fixings=52, vol=0.13)$value, 2.147489651, tol=1.0e-2)
+ checkEquals(AO("arithmetic", "put", underl=90.0, strike=87.0, div=0.06, riskF=0.025, first=1.0/12.0, length=11.0/12.0, fixings=100, vol=0.13)$value, 2.154728109, tol=1.0e-2)
+ checkEquals(AO("arithmetic", "put", underl=90.0, strike=87.0, div=0.06, riskF=0.025, first=1.0/12.0, length=11.0/12.0, fixings=250, vol=0.13)$value, 2.1564276565, tol=1.0e-2)
+ checkEquals(AO("arithmetic", "put", underl=90.0, strike=87.0, div=0.06, riskF=0.025, first=1.0/12.0, length=11.0/12.0, fixings=500, vol=0.13)$value, 2.1594238588, tol=1.0e-2)
+ checkEquals(AO("arithmetic", "put", underl=90.0, strike=87.0, div=0.06, riskF=0.025, first=1.0/12.0, length=11.0/12.0, fixings=1000, vol=0.13)$value, 2.1595367326, tol=1.0e-2)
+ checkEquals(AO("arithmetic", "put", underl=90.0, strike=87.0, div=0.06, riskF=0.025, first=3.0/12.0, length=11.0/12.0, fixings=2, vol=0.13)$value, 2.63315092584, tol=1.0e-2)
+ checkEquals(AO("arithmetic", "put", underl=90.0, strike=87.0, div=0.06, riskF=0.025, first=3.0/12.0, length=11.0/12.0, fixings=4, vol=0.13)$value, 2.76723962361, tol=1.0e-2)
+ checkEquals(AO("arithmetic", "put", underl=90.0, strike=87.0, div=0.06, riskF=0.025, first=3.0/12.0, length=11.0/12.0, fixings=8, vol=0.13)$value, 2.83124836881, tol=1.0e-2)
+ checkEquals(AO("arithmetic", "put", underl=90.0, strike=87.0, div=0.06, riskF=0.025, first=3.0/12.0, length=11.0/12.0, fixings=12, vol=0.13)$value, 2.84290301412, tol=1.0e-2)
+ checkEquals(AO("arithmetic", "put", underl=90.0, strike=87.0, div=0.06, riskF=0.025, first=3.0/12.0, length=11.0/12.0, fixings=26, vol=0.13)$value, 2.88179560417, tol=1.0e-2)
+ checkEquals(AO("arithmetic", "put", underl=90.0, strike=87.0, div=0.06, riskF=0.025, first=3.0/12.0, length=11.0/12.0, fixings=52, vol=0.13)$value, 2.88447044543, tol=1.0e-2)
+ checkEquals(AO("arithmetic", "put", underl=90.0, strike=87.0, div=0.06, riskF=0.025, first=3.0/12.0, length=11.0/12.0, fixings=100, vol=0.13)$value, 2.89985329603, tol=1.0e-2)
+ checkEquals(AO("arithmetic", "put", underl=90.0, strike=87.0, div=0.06, riskF=0.025, first=3.0/12.0, length=11.0/12.0, fixings=250, vol=0.13)$value, 2.90047296063, tol=1.0e-2)
+ checkEquals(AO("arithmetic", "put", underl=90.0, strike=87.0, div=0.06, riskF=0.025, first=3.0/12.0, length=11.0/12.0, fixings=500, vol=0.13)$value, 2.89813412160, tol=1.0e-2)
+ checkEquals(AO("arithmetic", "put", underl=90.0, strike=87.0, div=0.06, riskF=0.025, first=3.0/12.0, length=11.0/12.0, fixings=1000, vol=0.13)$value, 2.8970336243, tol=1.0e-2)
+}
- #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)
Modified: pkg/RQuantLib/man/AsianOption.Rd
===================================================================
--- pkg/RQuantLib/man/AsianOption.Rd 2010-07-21 04:23:24 UTC (rev 276)
+++ pkg/RQuantLib/man/AsianOption.Rd 2010-08-02 16:45:46 UTC (rev 277)
@@ -11,8 +11,8 @@
}
\usage{
\method{AsianOption}{default}(averageType, type, underlying, strike,
- dividendYield, riskFreeRate, maturity,
- volatility, first=0, length=0, fixings=0, timeSteps=150, gridPoints=151)
+ dividendYield, riskFreeRate, maturity,
+ volatility, first=0, length=0, fixings=0)
\method{plot}{Option}
\method{print}{Option}
\method{summary}{Option}
@@ -29,8 +29,6 @@
\item{first}{to be written}
\item{length}{to be written}
\item{fixings}{to be written}
- \item{timeSteps}{Time steps for the Finite Differences method, default value is 150}
- \item{gridPoints}{Grid points for the Finite Differences method, default value is 151}
}
\value{
The \code{AsianOption} function returns an object of class
More information about the Rquantlib-commits
mailing list