RQuantLib/ 0000755 0001751 0000144 00000000000 12630057262 012134 5 ustar hornik users RQuantLib/inst/ 0000755 0001751 0000144 00000000000 12627632333 013115 5 ustar hornik users RQuantLib/inst/Boost_LICENSE.TXT 0000644 0001751 0000144 00000002473 12347555514 015760 0 ustar hornik users Boost Software License - Version 1.0 - August 17th, 2003
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:
The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
RQuantLib/inst/NEWS.Rd 0000644 0001751 0000144 00000007512 12630031036 014150 0 ustar hornik users \name{NEWS}
\title{News for Package 'RQuantLib'}
\newcommand{\ghpr}{\href{https://github.com/eddelbuettel/rquantlib/pull/#1}{##1}}
\newcommand{\ghit}{\href{https://github.com/eddelbuettel/rquantlib/issues/#1}{##1}}
\section{Changes in RQuantLib version 0.4.2 (2015-12-03)}{
\itemize{
\item Changes in RQuantLib code:
\itemize{
\item Intra-day times are now available if QuantLib 1.7 or later is
used, and has been configured with \code{--enable-intraday}
\item New helper functions \code{getQuantLibVersion()} and
\code{getQuantLibCapabilties()}
\item New package startup code detects and warns about outdated
QuantLib versions, or missing intra-day capability, unless not
interactive.
\item The missing \code{Monthly} parameter has been added to
\code{matchFrequency} (fixing issue ticket \ghit{19})
}
}
}
\section{Changes in RQuantLib version 0.4.1 (2015-09-11)}{
\itemize{
\item Changes in RQuantLib code:
\itemize{
\item A simple \CRANpkg{shiny} application is now included in the
directory \code{shiny/DiscountCurve/} and accessible via the new
demo function \code{ShinyDiscountCurve}.
\item The option surface plotting example in \code{arrays.R} now
checks for \CRANpkg{rgl} by using \code{requireNamespace}.
\item The files \code{NAMESPACE} and \code{DESCRIPTION} have been
updated to reflect all the suggestions of \code{R CMD check}.
\item The Travis CI tests now use binary Debian packages for all
package dependencies making the tests a little faster.
}
}
}
\section{Changes in RQuantLib version 0.4.0 (2014-12-01)}{
\itemize{
\item Changes in RQuantLib code:
\itemize{
\item All function interfaces have been rewritten using \CRANpkg{Rcpp}
Attributes. No \code{SEXP} remain in the function signatures. This
make the code shorter, more readable and more easily extensible.
\item The header files have been reorganized so that plugin use is
possible. An \code{impl.h} files is imported once for each compilation
unit: for RQuantLib from the file \code{src/dates.cpp} directory, from
a sourced file via a \code{#define} set by the plugin wrapper.
\item \code{as<>()} and \code{wrap()} converters have added for
QuantLib Date types.
\item Plugin support has been added, allowing more ad-hoc use via Rcpp
Attributes.
\item Several Fixed Income functions have been added, and/or
rewritten to better match the QuantLib signatures; this was done
mostly by Michele Salvadore.
\item Several Date and Calendar functions have been added.
\item Calendar support has been greatly expanded thanks to Danilo
Dias da Silva.
\item Exported curve objects are now more parsimonious and advance
entries in the \code{table} object roughly one business month at a
time.
\item The \code{DiscountCurve} and \code{Bond} curve construction
has been fixed via a corrected evaluation date and omitted the
two-year swap rate, as suggested by Luigi Ballabio.
\item The \code{NAMESPACE} file has a tighter rule for export of
\code{*.default} functions, as suggested by Bill Dunlap
\item Builds now use OpenMP where available.
\item The package now depends on QuantLib 1.4.0 or later.
}
\item Changes in RQuantLib tests:
\itemize{
\item New unit tests for dates have been added.
\item C++ code for the unit tests has also been converted to
\CRANpkg{Rcpp} Attributes use; a helper function
\code{unitTestSetup()} has been added.
\item Continuous Integration via Travis is now enabled from the
GitHub repo.
}
\item Changes in RQuantLib documentation:
\itemize{
\item This NEWS file has been added. Better late than never, as
they say.
}
}
}
RQuantLib/inst/shiny/ 0000755 0001751 0000144 00000000000 12437636657 014263 5 ustar hornik users RQuantLib/inst/shiny/DiscountCurve/ 0000755 0001751 0000144 00000000000 12436673577 017061 5 ustar hornik users RQuantLib/inst/shiny/DiscountCurve/ui.R 0000644 0001751 0000144 00000002055 12436673577 017623 0 ustar hornik users library(shiny)
shinyUI(fluidPage(
## Application title
titlePanel("Simple DiscountCurve Example from RQuantLib"),
## Sidebar with controls to select parameters
sidebarLayout(
sidebarPanel(
radioButtons("interpolation", "Interpolation type:",
c("loglinear" = "loglinear",
"linear" = "linear",
"spline" = "spline")),
br(),
radioButtons("curve", "Curve type:",
c("forwards" = "forwards",
"zero rates" = "zerorates",
"discounts" = "discounts"))
),
## Show a tabset that includes a plot, summary, and table view
mainPanel(
tabsetPanel(type = "tabs",
tabPanel("Plot", plotOutput("plot")),
tabPanel("Summary", verbatimTextOutput("summary")),
tabPanel("Table", tableOutput("table"))
)
)
)
))
RQuantLib/inst/shiny/DiscountCurve/server.R 0000644 0001751 0000144 00000004443 12436673577 020517 0 ustar hornik users
library(shiny)
library(RQuantLib)
shinyServer(function(input, output) {
## This data is taken from sample code shipped with QuantLib 0.9.7
## from the file Examples/Swap/swapvaluation
params <- list(tradeDate=as.Date('2004-09-20'),
settleDate=as.Date('2004-09-22'),
dt=.25,
interpWhat="discount",
interpHow="loglinear")
setEvaluationDate(as.Date("2004-09-20"))
## We get numerical issue for the spline interpolation if we add
## any on of these three extra futures -- the original example
## creates different curves based on different deposit, fra, futures
## and swap data
## Removing s2y helps, as kindly pointed out by Luigi Ballabio
tsQuotes <- list(d1w = 0.0382,
d1m = 0.0372,
d3m = 0.0363,
d6m = 0.0353,
d9m = 0.0348,
d1y = 0.0345,
fut1=96.2875,
fut2=96.7875,
fut3=96.9875,
fut4=96.6875,
fut5=96.4875,
fut6=96.3875,
fut7=96.2875,
fut8=96.0875,
## s2y = 0.037125,
s3y = 0.0398,
s5y = 0.0443,
s10y = 0.05165,
s15y = 0.055175)
times <- seq(0,10,.1)
## Reactive expression to generate the requested curves.
data <- reactive({
params$interpHow <- input$interpolation
curve <- DiscountCurve(params, tsQuotes, times)
})
## Generate a plot of the data.
output$plot <- renderPlot({
interp <- input$interpolation
crv <- input$curve
dat <- data()
plot(dat[["times"]], dat[[crv]],
type='l', main=paste(interp, crv),
ylab=crv, xlab="time in years")
})
## Generate a summary of the data
output$summary <- renderPrint({
dat <- data()
cat("Return Object Structure\n")
str(dat)
cat("\n\nSummary of first four elements\n")
summary(data.frame(dat[1:4]))
})
## Generate an HTML table view of the data
output$table <- renderTable({
data.frame(x=data()[1:4])
})
})
RQuantLib/inst/QuantLib_LICENSE.TXT 0000644 0001751 0000144 00000013736 12347555514 016415 0 ustar hornik users QuantLib is
Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
Copyright (C) 2001, 2002, 2003 Nicolas Di Césaré
Copyright (C) 2001, 2002, 2003 Sadruddin Rejeb
Copyright (C) 2002, 2003, 2004 Decillion Pty(Ltd)
Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 Ferdinando Ametrano
Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2014 StatPro Italia srl
Copyright (C) 2003, 2004, 2007 Neil Firth
Copyright (C) 2003, 2004 Roman Gitlin
Copyright (C) 2003, 2005, 2013 Gary Kennedy
Copyright (C) 2003 Niels Elken Sønderby
Copyright (C) 2003 Kawanishi Tomoya
Copyright (C) 2004 FIMAT Group
Copyright (C) 2004 M-Dimension Consulting Inc.
Copyright (C) 2004 Mike Parker
Copyright (C) 2004 Walter Penschke
Copyright (C) 2004 Gianni Piolanti
Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Klaus Spanderen
Copyright (C) 2004 Jeff Yu
Copyright (C) 2005, 2006, 2008 Toyin Akin
Copyright (C) 2005 Sercan Atalik
Copyright (C) 2005, 2006 Theo Boafo
Copyright (C) 2005, 2006, 2007, 2009 Piter Dias
Copyright (C) 2005, 2006, 2007 Joseph Wang
Copyright (C) 2005 Charles Whitmore
Copyright (C) 2006, 2007 Banca Profilo S.p.A.
Copyright (C) 2006, 2007 Marco Bianchetti
Copyright (C) 2006 Yiping Chen
Copyright (C) 2006 Warren Chou
Copyright (C) 2006, 2007 Cristina Duminuco
Copyright (C) 2006, 2007 Giorgio Facchinetti
Copyright (C) 2006, 2007 Chiara Fornarola
Copyright (C) 2006 Silvia Frasson
Copyright (C) 2006 Richard Gould
Copyright (C) 2006, 2007, 2008, 2009, 2010 Mark Joshi
Copyright (C) 2006, 2007, 2008 Allen Kuo
Copyright (C) 2006, 2007, 2008, 2009, 2012 Roland Lichters
Copyright (C) 2006, 2007 Katiuscia Manzoni
Copyright (C) 2006, 2007 Mario Pucci
Copyright (C) 2006, 2007 François du Vignaud
Copyright (C) 2007 Affine Group Limited
Copyright (C) 2007 Richard Gomes
Copyright (C) 2007, 2008 Laurent Hoffmann
Copyright (C) 2007, 2008, 2009, 2010, 2011 Chris Kenyon
Copyright (C) 2007 Gang Liang
Copyright (C) 2008, 2009 Jose Aparicio
Copyright (C) 2008 Yee Man Chan
Copyright (C) 2008, 2011 Charles Chongseok Hyun
Copyright (C) 2008 Piero Del Boca
Copyright (C) 2008 Paul Farrington
Copyright (C) 2008 Lorella Fatone
Copyright (C) 2008, 2009 Andreas Gaida
Copyright (C) 2008 Marek Glowacki
Copyright (C) 2008 Florent Grenier
Copyright (C) 2008 Frank Hövermann
Copyright (C) 2008 Simon Ibbotson
Copyright (C) 2008 John Maiden
Copyright (C) 2008 Francesca Mariani
Copyright (C) 2008, 2009, 2010, 2011, 2012 Master IMAFA - Polytech'Nice Sophia - Université de Nice Sophia Antipolis
Copyright (C) 2008, 2009 Andrea Odetti
Copyright (C) 2008 J. Erik Radmall
Copyright (C) 2008 Maria Cristina Recchioni
Copyright (C) 2008, 2009, 2012 Ralph Schreyer
Copyright (C) 2008 Roland Stamm
Copyright (C) 2008 Francesco Zirilli
Copyright (C) 2009 Nathan Abbott
Copyright (C) 2009 Sylvain Bertrand
Copyright (C) 2009 Frédéric Degraeve
Copyright (C) 2009 Dirk Eddelbuettel
Copyright (C) 2009 Bernd Engelmann
Copyright (C) 2009, 2010, 2012 Liquidnet Holdings, Inc.
Copyright (C) 2009 Bojan Nikolic
Copyright (C) 2009, 2010 Dimitri Reiswich
Copyright (C) 2009 Sun Xiuxin
Copyright (C) 2010 Kakhkhor Abdijalilov
Copyright (C) 2010 Hachemi Benyahia
Copyright (C) 2010 Manas Bhatt
Copyright (C) 2010 DeriveXperts SAS
Copyright (C) 2010, 2014 Cavit Hafizoglu
Copyright (C) 2010 Michael Heckl
Copyright (C) 2010 Slava Mazur
Copyright (C) 2010, 2011, 2012, 2013 Andre Miemiec
Copyright (C) 2010 Adrian O' Neill
Copyright (C) 2010 Robert Philipp
Copyright (C) 2010 Alessandro Roveda
Copyright (C) 2010 SunTrust Bank
Copyright (C) 2011, 2013 Fabien Le Floc'h
Copyright (C) 2012, 2013 Grzegorz Andruszkiewicz
Copyright (C) 2012, 2013, 2014 Peter Caspers
Copyright (C) 2012 Mateusz Kapturski
Copyright (C) 2012 Simon Shakeshaft
Copyright (C) 2012 Édouard Tallent
Copyright (C) 2012 Samuel Tebege
Copyright (C) 2013 BGC Partners L.P.
Copyright (C) 2013 Cheng Li
Copyright (C) 2013 Yue Tian
QuantLib includes code taken from Peter Jäckel's book "Monte Carlo
Methods in Finance".
QuantLib includes software developed by the University of Chicago,
as Operator of Argonne National Laboratory.
QuantLib includes a set of numbers provided by Stephen Joe and Frances
Kuo under a BSD-style license.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
Neither the names of the copyright holders nor the names of the QuantLib
Group and its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
RQuantLib/inst/unitTests/ 0000755 0001751 0000144 00000000000 12627632333 015117 5 ustar hornik users RQuantLib/inst/unitTests/runit.options.R 0000644 0001751 0000144 00000075312 12627632333 020105 0 ustar hornik users
## AsianOption() currently has issue of Windows
.onWindows <- .Platform$OS.type == "windows"
## American option tests based on Haug's book
test.american.Haug <- function() {
## see QuantLib's test-suite/americanoption.cpp
#/* The data below are from
# "Option pricing formulas", E.G. Haug, McGraw-Hill 1998
# pag 24
#
# The following values were replicated only up to the second digit
# by the VB code provided by Haug, which was used as base for the
# C++ implementation
#
#*/
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)
}
## Asian option tests
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)
if (!.onWindows) {
## 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)
}
}
## 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 QuantLib's test-suite/barrieroption.cpp
# /* The data below are from
# * "Option pricing formulas", E.G. Haug, McGraw-Hill 1998 pag. 72
# */
#
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
test.binary <- function() {
## cash or nothing European
rc <- BinaryOption(binType="cash", type="put", excType="european", strike=80, underl=100, div=0.06, r=0.06, mat=0.75, vol=0.35, cash=10)
checkEquals(rc$value, 2.671045684)
checkEquals(rc[1:7],
list(value=2.671045, delta=-0.1060594, gamma=0.00310624, vega=8.153881, theta=-1.742309, rho=-9.9577, divRho=7.9544),
tolerance=1.0e-5)
}
## European option tests based on Haug's book
test.european.Haug <- function() {
## 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"
EO <- EuropeanOption # shorthand
checkEquals(EO(type="call", strike=65.00, underl=60.00, div= 0.00, riskF=0.08, mat=0.25, vol=0.30)$value, 2.1334, tol=1.0e-3)
checkEquals(EO(type="put", strike=95.00, underl=100.00, div= 0.05, riskF=0.10, mat=0.50, vol=0.20)$value, 2.4648, tol=1.0e-3)
checkEquals(EO(type="put", strike=19.00, underl=19.00, div= 0.10, riskF=0.10, mat=0.75, vol=0.28)$value, 1.7011, tol=1.0e-3)
checkEquals(EO(type="call", strike=19.00, underl=19.00, div= 0.10, riskF=0.10, mat=0.75, vol=0.28)$value, 1.7011, tol=1.0e-3)
checkEquals(EO(type="call", strike=1.60, underl=1.56, div= 0.08, riskF=0.06, mat=0.50, vol=0.12)$value, 0.0291, tol=1.0e-3)
checkEquals(EO(type="put", strike=70.00, underl=75.00, div= 0.05, riskF=0.10, mat=0.50, vol=0.35)$value, 4.0870, tol=1.0e-3)
checkEquals(EO(type="call", strike=100.00, underl=90.00, div= 0.10, riskF=0.10, mat=0.10, vol=0.15)$value, 0.0205, tol=1.0e-3)
checkEquals(EO(type="call", strike=100.00, underl=100.00, div= 0.10, riskF=0.10, mat=0.10, vol=0.15)$value, 1.8734, tol=1.0e-3)
checkEquals(EO(type="call", strike=100.00, underl=110.00, div= 0.10, riskF=0.10, mat=0.10, vol=0.15)$value, 9.9413, tol=1.0e-3)
checkEquals(EO(type="call", strike=100.00, underl=90.00, div= 0.10, riskF=0.10, mat=0.10, vol=0.25)$value, 0.3150, tol=1.0e-3)
checkEquals(EO(type="call", strike=100.00, underl=100.00, div= 0.10, riskF=0.10, mat=0.10, vol=0.25)$value, 3.1217, tol=1.0e-3)
checkEquals(EO(type="call", strike=100.00, underl=110.00, div= 0.10, riskF=0.10, mat=0.10, vol=0.25)$value, 10.3556, tol=1.0e-3)
checkEquals(EO(type="call", strike=100.00, underl=90.00, div= 0.10, riskF=0.10, mat=0.10, vol=0.35)$value, 0.9474, tol=1.0e-3)
checkEquals(EO(type="call", strike=100.00, underl=100.00, div= 0.10, riskF=0.10, mat=0.10, vol=0.35)$value, 4.3693, tol=1.0e-3)
checkEquals(EO(type="call", strike=100.00, underl=110.00, div= 0.10, riskF=0.10, mat=0.10, vol=0.35)$value, 11.1381, tol=1.0e-3)
checkEquals(EO(type="call", strike=100.00, underl=90.00, div= 0.10, riskF=0.10, mat=0.50, vol=0.15)$value, 0.8069, tol=1.0e-3)
checkEquals(EO(type="call", strike=100.00, underl=100.00, div= 0.10, riskF=0.10, mat=0.50, vol=0.15)$value, 4.0232, tol=1.0e-3)
checkEquals(EO(type="call", strike=100.00, underl=110.00, div= 0.10, riskF=0.10, mat=0.50, vol=0.15)$value, 10.5769, tol=1.0e-3)
checkEquals(EO(type="call", strike=100.00, underl=90.00, div= 0.10, riskF=0.10, mat=0.50, vol=0.25)$value, 2.7026, tol=1.0e-3)
checkEquals(EO(type="call", strike=100.00, underl=100.00, div= 0.10, riskF=0.10, mat=0.50, vol=0.25)$value, 6.6997, tol=1.0e-3)
checkEquals(EO(type="call", strike=100.00, underl=110.00, div= 0.10, riskF=0.10, mat=0.50, vol=0.25)$value, 12.7857, tol=1.0e-3)
checkEquals(EO(type="call", strike=100.00, underl=90.00, div= 0.10, riskF=0.10, mat=0.50, vol=0.35)$value, 4.9329, tol=1.0e-3)
checkEquals(EO(type="call", strike=100.00, underl=100.00, div= 0.10, riskF=0.10, mat=0.50, vol=0.35)$value, 9.3679, tol=1.0e-3)
checkEquals(EO(type="call", strike=100.00, underl=110.00, div= 0.10, riskF=0.10, mat=0.50, vol=0.35)$value, 15.3086, tol=1.0e-3)
checkEquals(EO(type="put", strike=100.00, underl=90.00, div= 0.10, riskF=0.10, mat=0.10, vol=0.15)$value, 9.9210, tol=1.0e-3)
checkEquals(EO(type="put", strike=100.00, underl=100.00, div= 0.10, riskF=0.10, mat=0.10, vol=0.15)$value, 1.8734, tol=1.0e-3)
checkEquals(EO(type="put", strike=100.00, underl=110.00, div= 0.10, riskF=0.10, mat=0.10, vol=0.15)$value, 0.0408, tol=1.0e-3)
checkEquals(EO(type="put", strike=100.00, underl=90.00, div= 0.10, riskF=0.10, mat=0.10, vol=0.25)$value, 10.2155, tol=1.0e-3)
checkEquals(EO(type="put", strike=100.00, underl=100.00, div= 0.10, riskF=0.10, mat=0.10, vol=0.25)$value, 3.1217, tol=1.0e-3)
checkEquals(EO(type="put", strike=100.00, underl=110.00, div= 0.10, riskF=0.10, mat=0.10, vol=0.25)$value, 0.4551, tol=1.0e-3)
checkEquals(EO(type="put", strike=100.00, underl=90.00, div= 0.10, riskF=0.10, mat=0.10, vol=0.35)$value, 10.8479, tol=1.0e-3)
checkEquals(EO(type="put", strike=100.00, underl=100.00, div= 0.10, riskF=0.10, mat=0.10, vol=0.35)$value, 4.3693, tol=1.0e-3)
checkEquals(EO(type="put", strike=100.00, underl=110.00, div= 0.10, riskF=0.10, mat=0.10, vol=0.35)$value, 1.2376, tol=1.0e-3)
checkEquals(EO(type="put", strike=100.00, underl=90.00, div= 0.10, riskF=0.10, mat=0.50, vol=0.15)$value, 10.3192, tol=1.0e-3)
checkEquals(EO(type="put", strike=100.00, underl=100.00, div= 0.10, riskF=0.10, mat=0.50, vol=0.15)$value, 4.0232, tol=1.0e-3)
checkEquals(EO(type="put", strike=100.00, underl=110.00, div= 0.10, riskF=0.10, mat=0.50, vol=0.15)$value, 1.0646, tol=1.0e-3)
checkEquals(EO(type="put", strike=100.00, underl=90.00, div= 0.10, riskF=0.10, mat=0.50, vol=0.25)$value, 12.2149, tol=1.0e-3)
checkEquals(EO(type="put", strike=100.00, underl=100.00, div= 0.10, riskF=0.10, mat=0.50, vol=0.25)$value, 6.6997, tol=1.0e-3)
checkEquals(EO(type="put", strike=100.00, underl=110.00, div= 0.10, riskF=0.10, mat=0.50, vol=0.25)$value, 3.2734, tol=1.0e-3)
checkEquals(EO(type="put", strike=100.00, underl=90.00, div= 0.10, riskF=0.10, mat=0.50, vol=0.35)$value, 14.4452, tol=1.0e-3)
checkEquals(EO(type="put", strike=100.00, underl=100.00, div= 0.10, riskF=0.10, mat=0.50, vol=0.35)$value, 9.3679, tol=1.0e-3)
checkEquals(EO(type="put", strike=100.00, underl=110.00, div= 0.10, riskF=0.10, mat=0.50, vol=0.35)$value, 5.7963, tol=1.0e-3)
checkEquals(EO(type="call", strike=40.00, underl=42.00, div= 0.08, riskF=0.04, mat=0.75, vol=0.35)$value, 5.0975, tol=1.0e-3)
}
RQuantLib/inst/unitTests/runit.calendar.R 0000644 0001751 0000144 00000000537 12420231675 020153 0 ustar hornik users
## test for calendaring functions
##
## cf test-suite/calendars.cpp in the QL sources
test.isHoliday <- function() {
checkEquals(isHoliday("UnitedStates", as.Date("2004-05-01")), TRUE, msg="isHoliday.US")
}
test.isBusinessDay <- function() {
checkEquals(isBusinessDay("UnitedStates", as.Date("2004-04-26")), TRUE, msg="isBusinessDay.US")
}
RQuantLib/inst/unitTests/runTests.R 0000644 0001751 0000144 00000002624 12271557403 017074 0 ustar hornik users ## borrowed from Rmetrics' unit testing framework
## removed test for interactive()
##
## Dirk Eddelbuettel, 29 Dec 2007
pkg <- "RQuantLib"
if (require("RUnit", quietly = TRUE)) {
library(package=pkg, character.only = TRUE)
if(!(exists("path") && file.exists(path)))
path <- system.file("unitTests", package = pkg)
## Define tests
testSuite <- defineTestSuite(name = paste(pkg, "unit testing"), dirs = path)
## Run tests
tests <- runTestSuite(testSuite)
if(file.access(path, 02) != 0) {
## cannot write to path -> use writable one
tdir <- tempfile(paste(pkg, "unitTests", sep="_"))
dir.create(tdir)
pathReport <- file.path(tdir, "report")
cat("RUnit reports are written into ", tdir, "/report.(txt|html)", sep = "")
} else {
pathReport <- file.path(path, "report")
}
## Print Results:
printTextProtocol(tests)
printTextProtocol(tests, fileName = paste(pathReport, ".txt", sep = ""))
## Print HTML Version to a File:
printHTMLProtocol(tests, fileName = paste(pathReport, ".html", sep = ""))
## stop() if there are any failures i.e. FALSE to unit test.
## This will cause R CMD check to return error and stop
if(getErrors(tests)$nFail > 0) {
stop("one of the unit tests failed")
}
} else {
cat("R package 'RUnit' cannot be loaded -- no unit tests run\n", "for package", pkg,"\n")
}
RQuantLib/inst/unitTests/cpp/ 0000755 0001751 0000144 00000000000 12423004400 015657 5 ustar hornik users RQuantLib/inst/unitTests/cpp/dates.cpp 0000644 0001751 0000144 00000003267 12423004400 017473 0 ustar hornik users // -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
//
// dates.cpp: RQuantLib date conversion tests
//
// Copyright (C) 2014 Dirk Eddelbuettel
//
// This file is part of RQuantLib.
//
// RQuantLib is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// RQuantLib is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with RQuantLib. If not, see .
// [[Rcpp::depends(RQuantLib)]]
#include
// [[Rcpp::export]]
Rcpp::Date advanceDateRR(Rcpp::Date d, int n) {
return d + n;
}
// [[Rcpp::export]]
Rcpp::Date advanceDateQR(QuantLib::Date d, int n) {
return Rcpp::wrap(d + n);
}
// [[Rcpp::export]]
QuantLib::Date advanceDateQQ(QuantLib::Date d, int n) {
return d + n;
}
// [[Rcpp::export]]
Rcpp::DateVector advanceDatesRR(Rcpp::DateVector d, int n) {
for (int i=0; i d, int n) {
for (unsigned int i=0; i advanceDatesQQ(std::vector d, int n) {
for (unsigned int i=0; i