[Rquantlib-commits] r176 - in pkg: R man tests

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Feb 13 06:01:03 CET 2010


Author: knguyen
Date: 2010-02-13 06:01:03 +0100 (Sat, 13 Feb 2010)
New Revision: 176

Modified:
   pkg/R/bond.R
   pkg/man/FloatingRateBond.Rd
   pkg/tests/RQuantlib.R
   pkg/tests/RQuantlib.Rout.save
Log:
Code Cleaning. Remove depreciated FloatRate codes

Modified: pkg/R/bond.R
===================================================================
--- pkg/R/bond.R	2010-02-13 04:31:17 UTC (rev 175)
+++ pkg/R/bond.R	2010-02-13 05:01:03 UTC (rev 176)
@@ -277,50 +277,17 @@
     if (is.null(dateparams$refDate)) {dateparams$refDate=bond$issueDate-2}
     
     dateparams <- matchParams(dateparams)
-    if (class(curve)=="DiscountCurve"){
-        indexparams <- list(type=index$type, length=index$length, 
+    
+    indexparams <- list(type=index$type, length=index$length, 
                         inTermOf=index$inTermOf)
-        ibor <- index$term
-        val <- .Call("QL_FloatingWithRebuiltCurve",
+    ibor <- index$term
+    val <- .Call("QL_FloatingWithRebuiltCurve",
                  bond, gearings, spreads, caps, floors, indexparams,
                  c(ibor$table$date), ibor$table$zeroRates,
                  c(curve$table$date), curve$table$zeroRates, 
                  dateparams, 
                  PACKAGE="RQuantLib")
-    }   
-    else {
-         indexparams <- list(type=index$type, length=index$length, 
-                        inTermOf=index$inTermOf)
-         if ((length(curve)==2) && (length(index$term)==2)){
-             val <- .Call("QL_FloatBond1", 
-                     bond, gearings, spreads, caps, floors,
-                     indexparams, index$term, curve, dateparams,
-                     PACKAGE="RQuantLib")
-          }
-          if ((length(curve)==2) && (length(index$term)==3)){
-             ibor <- index$term
-             val <- .Call("QL_FloatBond2", 
-                     bond, gearings, spreads, caps, floors,
-                     indexparams, ibor[[1]], ibor[[2]],
-                     ibor[[3]], curve, dateparams,
-                     PACKAGE="RQuantLib")
-          }
-          if ((length(curve)==3) && (length(index$term)==2)){
-              val <- .Call("QL_FloatBond3", 
-                    bond, gearings, spreads, caps, floors, 
-                    indexparams, index$term, curve[[1]],curve[[2]], 
-                    curve[[3]], dateparams,
-                    PACKAGE="RQuantLib")      
-          }
-          if ((length(curve)==3) && (length(index$term)==3)){
-              ibor <- index$term
-              val <- .Call("QL_FloatBond4", 
-                    bond, gearings, spreads, caps, floors, 
-                    indexparams, ibor[[1]], ibor[[2]], ibor[[3]], 
-                    curve[[1]],curve[[2]], curve[[3]], dateparams,
-                    PACKAGE="RQuantLib")      
-          }
-    }
+    
     val$cashFlow <- as.data.frame(val$cashFlow)
     class(val) <- c("FloatingRateBond", "Bond")    
     val

Modified: pkg/man/FloatingRateBond.Rd
===================================================================
--- pkg/man/FloatingRateBond.Rd	2010-02-13 04:31:17 UTC (rev 175)
+++ pkg/man/FloatingRateBond.Rd	2010-02-13 05:01:03 UTC (rev 176)
@@ -124,22 +124,16 @@
 bond <- list(faceAmount=100, issueDate=as.Date("2004-11-30"),
              maturityDate=as.Date("2008-11-30"), redemption=100, 
              effectiveDate=as.Date("2004-11-30"))
-
-dateparams <- list(settlementDays=1, calendar="us", dayCounter = 1, period=3, 
+dateparams <- list(settlementDays=1, calendar="us",
+                   dayCounter = 'ActualActual', period=2, 
                    businessDayConvention = 1, terminationDateConvention=1,
                    dateGeneration=0, endOfMonth=0, fixingDays = 1)
 
 gearings <- c()
-
 spreads <- c()
-
 caps <- c()
-
 floors <- c()
 
-
-length2 <- list(todayDate=as.Date("2004-11-22"), riskFreeRate=0.025)
-
 params <- list(tradeDate=as.Date('2002-2-15'),
                settleDate=as.Date('2002-2-19'),
                dt=.25,
@@ -161,66 +155,29 @@
                  s10y =0.05165,
                  s15y =0.055175)
 
-times <- seq(0,10,.1)
 
-length3 <- list(params, tsQuotes, times)
+## when both discount and libor curves are flat.
 
-
-# both curves are flat
-
-curve <- length2
-termstructure <- length2
-iborindex <- list(type="USDLibor", length=6, 
+discountCurve.flat <- DiscountCurve(params, list(flat=0.05))
+termstructure <- DiscountCurve(params, list(flat=0.03))
+iborIndex.params <- list(type="USDLibor", length=6, 
                   inTermOf="Month", term=termstructure)                      
 FloatingRateBond(bond, gearings, spreads, caps, floors, 
-                 iborindex, curve, dateparams)
+                 iborIndex.params, discountCurve.flat, dateparams)
 
 
-# one flat, another one is constructe
-
-curve <- length2
-termstructure <- length3
-iborindex <- list(type="USDLibor", length=6, 
+## discount curve is constructed from market quotes
+## and a flat libor curve
+discountCurve <- DiscountCurve(params, tsQuotes)
+termstructure <- DiscountCurve(params, list(flat=0.03))
+iborIndex.params <- list(type="USDLibor", length=6, 
                   inTermOf="Month", term = termstructure)                      
 FloatingRateBond(bond, gearings, spreads, caps, floors, 
-                 iborindex, curve, dateparams)
+                 iborIndex.params, discountCurve, dateparams)
 
-
-curve <- length3
-termstructure <- length2
-iborindex <- list(type="USDLibor", length=6, 
-                  inTermOf="Month", term = termstructure)                      
-FloatingRateBond(bond, gearings, spreads, caps, floors, 
-                 iborindex, curve, dateparams)
-
-
-# both curves are constructed
-
-curve <- length3
-termstructure <- length3
-iborindex <- list(type="USDLibor", length=6, 
-                  inTermOf="Month", term = termstructure)                      
-FloatingRateBond(bond, gearings, spreads, caps, floors, 
-                 iborindex, curve, dateparams)
-
-
-curve2 <- DiscountCurve(params, tsQuotes, times)
-index2 <- DiscountCurve(params, tsQuotes, times)
-ibor <- list(type="USDLibor", length=6, 
-             inTermOf="Month", term = index2)
-dateparams <- list(settlementDays=1, calendar="us", dayCounter = "Actual360", 
-                   period="Semiannual", 
-                   businessDayConvention = "Following", 
-                   terminationDateConvention= "Following",
-                   dateGeneration= "Forward", 
-                   endOfMonth=0, fixingDays = 1)
-FloatingRateBond(bond, gearings, spreads, caps, floors,
-                  ibor, curve2, dateparams)
-
 #example using default values
-FloatingRateBond(bond=bond, index=ibor, curve=curve2)
+FloatingRateBond(bond=bond, index=iborIndex.params, curve=discountCurve)
 
-
 }
 \keyword{misc}
 

Modified: pkg/tests/RQuantlib.R
===================================================================
--- pkg/tests/RQuantlib.R	2010-02-13 04:31:17 UTC (rev 175)
+++ pkg/tests/RQuantlib.R	2010-02-13 05:01:03 UTC (rev 176)
@@ -114,21 +114,48 @@
 discountCurve.flat <- DiscountCurve(params, list(flat=0.05))
 FixedRateBond(bond, coupon.rate, discountCurve.flat, dateparams)
 ## bond.cpp FloatingRateBond, following test-suite/bonds.cpp
+
 bond <- list(faceAmount=100, issueDate=as.Date("2004-11-30"),
              maturityDate=as.Date("2008-11-30"), redemption=100, 
              effectiveDate=as.Date("2004-11-30"))
-dateparams <- list(settlementDays=1, calendar="us", dayCounter = 1, period=3, 
+dateparams <- list(settlementDays=1, calendar="us",
+                   dayCounter = 'ActualActual', period=2, 
                    businessDayConvention = 1, terminationDateConvention=1,
                    dateGeneration=0, endOfMonth=0, fixingDays = 1)
+
 gearings <- c()
 spreads <- c()
 caps <- c()
 floors <- c()
-length2 <- list(todayDate=as.Date("2004-11-22"), riskFreeRate=0.025)
-curve <- length2
-termstructure <- length2
-iborindex <- list(type="USDLibor", length=6, 
+
+params <- list(tradeDate=as.Date('2002-2-15'),
+               settleDate=as.Date('2002-2-19'),
+               dt=.25,
+               interpWhat="discount",
+               interpHow="loglinear")
+
+tsQuotes <- list(d1w  =0.0382,
+                 d1m  =0.0372,
+                 fut1=96.2875,
+                 fut2=96.7875,
+                 fut3=96.9875,
+                 fut4=96.6875,
+                 fut5=96.4875,
+                 fut6=96.3875,
+                 fut7=96.2875,
+                 fut8=96.0875,
+                 s3y  =0.0398,
+                 s5y  =0.0443,
+                 s10y =0.05165,
+                 s15y =0.055175)
+
+
+## when both discount and libor curves are flat.
+
+discountCurve.flat <- DiscountCurve(params, list(flat=0.05))
+termstructure <- DiscountCurve(params, list(flat=0.03))
+iborIndex.params <- list(type="USDLibor", length=6, 
                   inTermOf="Month", term=termstructure)                      
-print(FloatingRateBond(bond, gearings, spreads, caps, floors, 
-                 iborindex, curve, dateparams))
+FloatingRateBond(bond, gearings, spreads, caps, floors, 
+                 iborIndex.params, discountCurve.flat, dateparams)
 

Modified: pkg/tests/RQuantlib.Rout.save
===================================================================
--- pkg/tests/RQuantlib.Rout.save	2010-02-13 04:31:17 UTC (rev 175)
+++ pkg/tests/RQuantlib.Rout.save	2010-02-13 05:01:03 UTC (rev 176)
@@ -221,43 +221,66 @@
  2008-11-30   1.4375
  2008-11-30 100.0000
 > ## bond.cpp FloatingRateBond, following test-suite/bonds.cpp
+> 
 > bond <- list(faceAmount=100, issueDate=as.Date("2004-11-30"),
 +              maturityDate=as.Date("2008-11-30"), redemption=100, 
 +              effectiveDate=as.Date("2004-11-30"))
-> dateparams <- list(settlementDays=1, calendar="us", dayCounter = 1, period=3, 
+> dateparams <- list(settlementDays=1, calendar="us",
++                    dayCounter = 'ActualActual', period=2, 
 +                    businessDayConvention = 1, terminationDateConvention=1,
 +                    dateGeneration=0, endOfMonth=0, fixingDays = 1)
+> 
 > gearings <- c()
 > spreads <- c()
 > caps <- c()
 > floors <- c()
-> length2 <- list(todayDate=as.Date("2004-11-22"), riskFreeRate=0.025)
-> curve <- length2
-> termstructure <- length2
-> iborindex <- list(type="USDLibor", length=6, 
+> 
+> params <- list(tradeDate=as.Date('2002-2-15'),
++                settleDate=as.Date('2002-2-19'),
++                dt=.25,
++                interpWhat="discount",
++                interpHow="loglinear")
+> 
+> tsQuotes <- list(d1w  =0.0382,
++                  d1m  =0.0372,
++                  fut1=96.2875,
++                  fut2=96.7875,
++                  fut3=96.9875,
++                  fut4=96.6875,
++                  fut5=96.4875,
++                  fut6=96.3875,
++                  fut7=96.2875,
++                  fut8=96.0875,
++                  s3y  =0.0398,
++                  s5y  =0.0443,
++                  s10y =0.05165,
++                  s15y =0.055175)
+> 
+> 
+> ## when both discount and libor curves are flat.
+> 
+> discountCurve.flat <- DiscountCurve(params, list(flat=0.05))
+> termstructure <- DiscountCurve(params, list(flat=0.03))
+> iborIndex.params <- list(type="USDLibor", length=6, 
 +                   inTermOf="Month", term=termstructure)                      
-> print(FloatingRateBond(bond, gearings, spreads, caps, floors, 
-+                  iborindex, curve, dateparams))
+> FloatingRateBond(bond, gearings, spreads, caps, floors, 
++                  iborIndex.params, discountCurve.flat, dateparams)
 Concise summary of valuation for FloatingRateBond 
- Net present value :  99.8126 
-       clean price :  99.868 
-       dirty price :  99.868 
+ Net present value :  80.54557 
+       clean price :  92.55 
+       dirty price :  92.55 
     accrued coupon :  0 
-             yield :  0.025315 
+             yield :  0.050517 
         cash flows : 
-       Date    Amount
- 2005-03-30   0.82535
- 2005-07-29   0.83232
- 2005-11-30   0.85292
- 2006-03-30   0.82535
- 2006-07-31   0.84607
- 2006-11-30   0.83917
- 2007-03-30   0.82541
- 2007-07-30   0.83911
- 2007-11-30   0.84613
- 2008-03-31   0.83911
- 2008-07-30   0.83226
- 2008-11-28   0.83232
- 2008-11-28 100.00000
+       Date   Amount
+ 2005-05-31   1.4851
+ 2005-11-30   1.4947
+ 2006-05-30   1.4783
+ 2006-11-30   1.5029
+ 2007-05-30   1.4783
+ 2007-11-30   1.5031
+ 2008-05-30   1.4797
+ 2008-11-28   1.4783
+ 2008-11-28 100.0000
 > 
 > 



More information about the Rquantlib-commits mailing list