From noreply at r-forge.r-project.org Sun Feb 17 22:10:52 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 17 Feb 2013 22:10:52 +0100 (CET) Subject: [Rquantlib-commits] r327 - in pkg/RQuantLib: . R demo man src Message-ID: <20130217211053.018A1184648@r-forge.r-project.org> Author: edd Date: 2013-02-17 22:10:52 +0100 (Sun, 17 Feb 2013) New Revision: 327 Modified: pkg/RQuantLib/ChangeLog pkg/RQuantLib/DESCRIPTION pkg/RQuantLib/R/arrays.R pkg/RQuantLib/cleanup pkg/RQuantLib/demo/OptionSurfaces.R pkg/RQuantLib/man/Bond.Rd pkg/RQuantLib/man/DiscountCurve.Rd pkg/RQuantLib/man/FixedRateBond.Rd pkg/RQuantLib/man/FloatingRateBond.Rd pkg/RQuantLib/man/ZeroCouponBond.Rd pkg/RQuantLib/src/discount.cpp Log: Release 0.3.10 with a flat discount curve in examples plus minor updates Modified: pkg/RQuantLib/ChangeLog =================================================================== --- pkg/RQuantLib/ChangeLog 2012-12-02 17:10:25 UTC (rev 326) +++ pkg/RQuantLib/ChangeLog 2013-02-17 21:10:52 UTC (rev 327) @@ -1,3 +1,20 @@ +2013-02-17 Dirk Eddelbuettel + + * DESCRIPTION: Release 0.3.10 + + * man/Bond.Rd: Use a flat discount curve in example + * man/DiscountCurve.Rd: Idem + * man/FixedRateBond.Rd: Idem + * man/FLoatingRateBond.Rd: Idem + * man/ZeroCouponBond.Rd: Idem + + * R/arrays.R (plotOptionSurface): Use explicit `rgl::' prefix for all + function from the rgl package to suppress spurious codetools warning + + * demo/OptionSurfaces.R: Reindented + + * cleanup: Simplified and updated + 2012-12-02 Dirk Eddelbuettel * src/discount.cpp (DiscountCurve): R-devel on Windows now longer @@ -10,8 +27,7 @@ * src/vanilla.cpp (AmericanOption): Support engine choice, adding "CrankNicolson" to the default "BaroneAdesiWhaley" as the former adds - delta, gamma and vega greeks -- thanks to Bryan Lewis for the - suggestion + delta + gamma -- thanks to Bryan Lewis for the suggestion * R/option.R: Support new the new 'engine' option * man/AmericanOption.Rd: Document new 'engine' option Modified: pkg/RQuantLib/DESCRIPTION =================================================================== --- pkg/RQuantLib/DESCRIPTION 2012-12-02 17:10:25 UTC (rev 326) +++ pkg/RQuantLib/DESCRIPTION 2013-02-17 21:10:52 UTC (rev 327) @@ -1,6 +1,6 @@ Package: RQuantLib Title: R interface to the QuantLib library -Version: 0.3.9 +Version: 0.3.10 Date: $Date$ Maintainer: Dirk Eddelbuettel Author: Dirk Eddelbuettel and Khanh Nguyen Modified: pkg/RQuantLib/R/arrays.R =================================================================== --- pkg/RQuantLib/R/arrays.R 2012-12-02 17:10:25 UTC (rev 326) +++ pkg/RQuantLib/R/arrays.R 2013-02-17 21:10:52 UTC (rev 327) @@ -116,6 +116,7 @@ plotOptionSurface <- function(EOres, ylabel="", xlabel="", zlabel="", fov=60) { stopifnot(require(rgl)) + utils::globalVariables(c("clear3d", "bg3d", "ligh3d", "rgl.viewpoint", "rgl.surface", "tgl.texts")) axis.col <- "black" text.col <- axis.col ylab <- ylabel @@ -124,39 +125,39 @@ y <- EOres ## clear scene: - clear3d() - clear3d(type="bbox") - clear3d(type="lights") + rgl::clear3d() + rgl::clear3d(type="bbox") + rgl::clear3d(type="lights") ## setup env: - bg3d(color="#DDDDDD") - light3d() + rgl::bg3d(color="#DDDDDD") + rgl::light3d() - rgl.viewpoint(fov=fov) + rgl::rgl.viewpoint(fov=fov) x <- 1:nrow(y) z <- 1:ncol(y) x <- (x-min(x))/(max(x)-min(x)) y <- (y-min(y))/(max(y)-min(y)) z <- (z-min(z))/(max(z)-min(z)) - rgl.surface(x, z, y, alpha=0.6, lit=TRUE, color="blue") - rgl.lines(c(0,1), c(0,0), c(0,0), col=axis.col) - rgl.lines(c(0,0), c(0,1), c(0,0), col=axis.col) - rgl.lines(c(0,0),c(0,0), c(0,1), col=axis.col) - rgl.texts(1,0,0, xlab, adj=1, col=text.col) - rgl.texts(0,1,0, ylab, adj=1, col=text.col) - rgl.texts(0,0,1, zlab, adj=1, col=text.col) + rgl::rgl.surface(x, z, y, alpha=0.6, lit=TRUE, color="blue") + rgl::rgl.lines(c(0,1), c(0,0), c(0,0), col=axis.col) + rgl::rgl.lines(c(0,0), c(0,1), c(0,0), col=axis.col) + rgl::rgl.lines(c(0,0),c(0,0), c(0,1), col=axis.col) + rgl::rgl.texts(1,0,0, xlab, adj=1, col=text.col) + rgl::rgl.texts(0,1,0, ylab, adj=1, col=text.col) + rgl::rgl.texts(0,0,1, zlab, adj=1, col=text.col) ## add grid (credit's to John Fox scatter3d) xgridind <- round(seq(1, nrow(y), length=25)) zgridind <- round(seq(1, ncol(y), length=25)) - rgl.surface(x[xgridind], z[zgridind], y[xgridind,zgridind], - color="darkgray", alpha=0.5, lit=TRUE, - front="lines", back="lines") + rgl::rgl.surface(x[xgridind], z[zgridind], y[xgridind,zgridind], + color="darkgray", alpha=0.5, lit=TRUE, + front="lines", back="lines") ## animate (credit to rgl.viewpoint() example) start <- proc.time()[3] while ((i <- 36*(proc.time()[3]-start)) < 360) { - rgl.viewpoint(i,i/8); + rgl::rgl.viewpoint(i,i/8); } } Modified: pkg/RQuantLib/cleanup =================================================================== --- pkg/RQuantLib/cleanup 2012-12-02 17:10:25 UTC (rev 326) +++ pkg/RQuantLib/cleanup 2013-02-17 21:10:52 UTC (rev 327) @@ -1,28 +1,9 @@ #!/bin/sh -for f in ./config.*; do - rm -f $f -done -if [ -e confdefs.h ]; then - rm -f confdefs.h -fi -if [ -e src/Makevars ]; then - rm -f src/Makevars -fi -if [ -e src/libRQuantLib.a ]; then - rm -f src/libRQuantLib.a -fi -if [ -e src/libRQuantLib.def ]; then - rm -f src/libRQuantLib.def -fi -if [ -e autom4te.cache ]; then - rm -rf autom4te.cache -fi -for f in src/*.o src/*.so; do - rm -f $f -done + +rm -f config.log config.status confdefs.h autom4te.cache \ + src/Makevars src/libRQuantLib.a src/libRQuantLib.def src/*.o src/*.so src/symbols.rds \ + RcppSrc/*.a RcppSrc/*.o RcppSrc/config.* inst/Rcpp-version.txt + find . -name \*~ | xargs rm -f -#rm -vf configure -rm -vf config.log config.status -rm -f RcppSrc/*.a RcppSrc/*.o RcppSrc/config.* -rm -f inst/Rcpp-version.txt + exit 0 Modified: pkg/RQuantLib/demo/OptionSurfaces.R =================================================================== --- pkg/RQuantLib/demo/OptionSurfaces.R 2012-12-02 17:10:25 UTC (rev 326) +++ pkg/RQuantLib/demo/OptionSurfaces.R 2013-02-17 21:10:52 UTC (rev 327) @@ -3,68 +3,65 @@ ## Dirk Eddelbuettel, September 2005 ## $Id: OptionSurfaces.R,v 1.1 2005/10/12 03:42:45 edd Exp $ -OptionSurface <- function(EOres, label, fov=60) { - axis.col <- "black" - text.col <- axis.col - ylab = label - xlab = "Underlying" - zlab = "Volatility" - y <- EOres +OptionSurface <- function(EOres, label, fov=60) { + axis.col <- "black" + text.col <- axis.col + ylab = label + xlab = "Underlying" + zlab = "Volatility" + y <- EOres - # clear scene: - clear3d() - clear3d(type="bbox") - clear3d(type="lights") - - # setup env: -# bg3d(color="#887777") - bg3d(color="#DDDDDD") - light3d() + ## clear scene: + clear3d() + clear3d(type="bbox") + clear3d(type="lights") - rgl.viewpoint(fov=fov) - #rgl.bg(col="white", fogtype="exp2") - #rgl.bg(col="black", fogtype="exp2") - #rgl.bg(col="black", fogtype="exp") - #rgl.bg(col="white", fogtype="exp") + ## setup env: + ## bg3d(color="#887777") + bg3d(color="#DDDDDD") + light3d() - x <- (1:nrow(y)) - z <- (1:ncol(y)) - x <- (x-min(x))/(max(x)-min(x)) - y <- (y-min(y))/(max(y)-min(y)) - z <- (z-min(z))/(max(z)-min(z)) - rgl.surface(x, z, y, alpha=0.6, lit=TRUE, color="blue") - rgl.lines(c(0,1), c(0,0), c(0,0), col=axis.col) - rgl.lines(c(0,0), c(0,1), c(0,0), col=axis.col) - rgl.lines(c(0,0),c(0,0), c(0,1), col=axis.col) - rgl.texts(1,0,0, xlab, adj=1, col=text.col) - rgl.texts(0,1,0, ylab, adj=1, col=text.col) - rgl.texts(0,0,1, zlab, adj=1, col=text.col) + rgl.viewpoint(fov=fov) + ##rgl.bg(col="white", fogtype="exp2") + ##rgl.bg(col="black", fogtype="exp2") + ##rgl.bg(col="black", fogtype="exp") + ##rgl.bg(col="white", fogtype="exp") - ## add grid (credit's to John Fox scatter3d) - xgridind <- round(seq(1, nrow(y), length=25)) - zgridind <- round(seq(1, ncol(y), length=25)) - rgl.surface(x[xgridind], z[zgridind], y[xgridind,zgridind], - color="darkgray", alpha=0.5, lit=TRUE, - front="lines", back="lines") + x <- (1:nrow(y)) + z <- (1:ncol(y)) + x <- (x-min(x))/(max(x)-min(x)) + y <- (y-min(y))/(max(y)-min(y)) + z <- (z-min(z))/(max(z)-min(z)) + rgl.surface(x, z, y, alpha=0.6, lit=TRUE, color="blue") + rgl.lines(c(0,1), c(0,0), c(0,0), col=axis.col) + rgl.lines(c(0,0), c(0,1), c(0,0), col=axis.col) + rgl.lines(c(0,0),c(0,0), c(0,1), col=axis.col) + rgl.texts(1,0,0, xlab, adj=1, col=text.col) + rgl.texts(0,1,0, ylab, adj=1, col=text.col) + rgl.texts(0,0,1, zlab, adj=1, col=text.col) - ## animate (credit to rgl.viewpoint() example) - start <- proc.time()[3] - while ((i <- 36*(proc.time()[3]-start)) < 360) { - rgl.viewpoint(i,i/8); - } + ## add grid (credit's to John Fox scatter3d) + xgridind <- round(seq(1, nrow(y), length=25)) + zgridind <- round(seq(1, ncol(y), length=25)) + rgl.surface(x[xgridind], z[zgridind], y[xgridind,zgridind], + color="darkgray", alpha=0.5, lit=TRUE, + front="lines", back="lines") + + ## animate (credit to rgl.viewpoint() example) + start <- proc.time()[3] + while ((i <- 36*(proc.time()[3]-start)) < 360) { + rgl.viewpoint(i,i/8); + } } RQuantLib.demo.OptionSurfaces <- function() { - - if (require(rgl,quiet=TRUE)) { - stopifnot(require(RQuantLib,quiet=TRUE)) und.seq <- seq(10, 200, by = 2.5) vol.seq <- seq(0.05, 2, by = 0.025) cat("Calculating surface ...") EOarr <- EuropeanOptionArrays("call", underlying = und.seq, strike = 100, - dividendYield = 0.01, riskFreeRate = 0.03, + dividendYield = 0.01, riskFreeRate = 0.03, maturity = 1, volatility = vol.seq) cat(" done.\n") @@ -74,7 +71,10 @@ OptionSurface(EOarr$gamma, "Gamma") OptionSurface(EOarr$vega, "Vega") OptionSurface(EOarr$theta, "Theta") - } + } +require(rgl,quiet=TRUE) +require(RQuantLib,quiet=TRUE) + RQuantLib.demo.OptionSurfaces() Modified: pkg/RQuantLib/man/Bond.Rd =================================================================== --- pkg/RQuantLib/man/Bond.Rd 2012-12-02 17:10:25 UTC (rev 326) +++ pkg/RQuantLib/man/Bond.Rd 2013-02-17 21:10:52 UTC (rev 327) @@ -62,7 +62,7 @@ s5y = 0.0443, s10y = 0.05165, s15y = 0.055175) - +tsQuotes <- list("flat" = 0.02) ## While discount curve code is buggy times <- seq(0,10,.1) discountCurve <- DiscountCurve(params, tsQuotes, times) Modified: pkg/RQuantLib/man/DiscountCurve.Rd =================================================================== --- pkg/RQuantLib/man/DiscountCurve.Rd 2012-12-02 17:10:25 UTC (rev 326) +++ pkg/RQuantLib/man/DiscountCurve.Rd 2013-02-17 21:10:52 UTC (rev 327) @@ -144,6 +144,7 @@ s10y = 0.05165, s15y = 0.055175) +tsQuotes <- list("flat" = 0.02) ## While discount curve code is buggy times <- seq(0,10,.1) # Loglinear interpolation of discount factors Modified: pkg/RQuantLib/man/FixedRateBond.Rd =================================================================== --- pkg/RQuantLib/man/FixedRateBond.Rd 2012-12-02 17:10:25 UTC (rev 326) +++ pkg/RQuantLib/man/FixedRateBond.Rd 2013-02-17 21:10:52 UTC (rev 327) @@ -187,6 +187,7 @@ s5y =0.0443, s10y =0.05165, s15y =0.055175) +tsQuotes <- list("flat" = 0.02) ## While discount curve code is buggy discountCurve <- DiscountCurve(params, tsQuotes) FixedRateBond(bond, coupon.rate, discountCurve, dateparams) Modified: pkg/RQuantLib/man/FloatingRateBond.Rd =================================================================== --- pkg/RQuantLib/man/FloatingRateBond.Rd 2012-12-02 17:10:25 UTC (rev 326) +++ pkg/RQuantLib/man/FloatingRateBond.Rd 2013-02-17 21:10:52 UTC (rev 327) @@ -152,8 +152,8 @@ s5y =0.0443, s10y =0.05165, s15y =0.055175) +tsQuotes <- list("flat" = 0.02) ## While discount curve code is buggy - ## when both discount and libor curves are flat. discountCurve.flat <- DiscountCurve(params, list(flat=0.05)) Modified: pkg/RQuantLib/man/ZeroCouponBond.Rd =================================================================== --- pkg/RQuantLib/man/ZeroCouponBond.Rd 2012-12-02 17:10:25 UTC (rev 326) +++ pkg/RQuantLib/man/ZeroCouponBond.Rd 2013-02-17 21:10:52 UTC (rev 327) @@ -155,6 +155,8 @@ s5y =0.0443, s10y =0.05165, s15y =0.055175) +tsQuotes <- list("flat" = 0.02) ## While discount curve code is buggy + discountCurve <- DiscountCurve(discountCurve.param, tsQuotes) ZeroCouponBond(bond, discountCurve, dateparams) Modified: pkg/RQuantLib/src/discount.cpp =================================================================== --- pkg/RQuantLib/src/discount.cpp 2012-12-02 17:10:25 UTC (rev 326) +++ pkg/RQuantLib/src/discount.cpp 2013-02-17 21:10:52 UTC (rev 327) @@ -5,6 +5,7 @@ // Copyright (C) 2005 - 2007 Dominick Samperi // Copyright (C) 2007 - 2009 Dirk Eddelbuettel // Copyright (C) 2009 - 2011 Dirk Eddelbuettel and Khanh Nguyen +// Copyright (C) 2012 - 2013 Dirk Eddelbuettel // // $Id$ // @@ -99,7 +100,7 @@ //SEXP fwds = PROTECT(Rf_allocVector(REALSXP, ntimes)); //SEXP zero = PROTECT(Rf_allocVector(REALSXP, ntimes)); Rcpp::NumericVector disc(ntimes), fwds(ntimes), zero(ntimes); - + QuantLib::Date current = settlementDate; for (i = 0; i < ntimes; i++) { //t = REAL(times)[i];