[Rquantlib-commits] r174 - in pkg: R man src tests

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Feb 13 05:12:53 CET 2010


Author: knguyen
Date: 2010-02-13 05:12:52 +0100 (Sat, 13 Feb 2010)
New Revision: 174

Modified:
   pkg/R/bond.R
   pkg/man/ConvertibleFloatingCouponBond.Rd
   pkg/man/FittedBondCurve.Rd
   pkg/man/ZeroCouponBond.Rd
   pkg/src/bonds.cpp
   pkg/tests/RQuantlib.R
   pkg/tests/RQuantlib.Rout.save
Log:
code cleaning. Remove depreciated ZeroBond codes

Modified: pkg/R/bond.R
===================================================================
--- pkg/R/bond.R	2010-02-08 21:45:45 UTC (rev 173)
+++ pkg/R/bond.R	2010-02-13 04:12:52 UTC (rev 174)
@@ -27,7 +27,9 @@
 
 ZeroCouponBond.default <- function(bond,
                                    discountCurve,
-                                   dateparams=list(settlementDays=1,
+                                   dateparams=list(
+                                     refDate=bond$issueDate,
+                                     settlementDays=1,
                                      calendar='us',
                                      businessDayConvention='Following')) {
     val <- 0 
@@ -38,29 +40,16 @@
     if (is.null(dateparams$settlementDays)) {dateparams$settlementDays=1}
     if (is.null(dateparams$calendar)) {dateparams$calendar='us'}
     if (is.null(dateparams$businessDayConvention)) {dateparams$businessDayConvention='Following'}    
-    
+    if (is.null(dateparams$refDate)) {dateparams$refDate=bond$issueDate}
     dateparams <- matchParams(dateparams)
 
-    if (class(discountCurve)=="DiscountCurve"){
-        val <- .Call("QL_ZeroBondWithRebuiltCurve",
-                  bond, c(discountCurve$table$date), 
-                  discountCurve$table$zeroRates, dateparams,
-                  PACKAGE="RQuantLib")
-    }
-    else{
-        if (length(discountCurve)==2){
-            val <- .Call("QL_ZBond1", 
-                     bond, discountCurve, dateparams,
-                     PACKAGE="RQuantLib")
-        }
-        if (length(discountCurve)==3){
-             val <- .Call("QL_ZBond2", 
-                    bond, discountCurve[[1]], 
-                    discountCurve[[2]], discountCurve[[3]],
-                    dateparams,
-                    PACKAGE="RQuantLib")      
-        }
-    }
+    
+    val <- .Call("QL_ZeroBondWithRebuiltCurve",
+                 bond, c(discountCurve$table$date), 
+                 discountCurve$table$zeroRates, dateparams,
+                 PACKAGE="RQuantLib")
+    
+
     val$cashFlow <- as.data.frame(val$cashFlow)
     class(val) <- c("ZeroCouponBond", "Bond")    
     val
@@ -130,6 +119,7 @@
                                   rates,
                                   discountCurve,
                                   dateparams=list(
+                                    
                                     settlementDays=1,
                                     calendar='us',
                                     businessDayConvention='Following',
@@ -267,6 +257,7 @@
                                      index,
                                      curve,
                                      dateparams=list(
+                                       refDate=bond$issueDate-2,
                                        settlementDays=1,
                                        calendar='us',
                                        businessDayConvention='Following',
@@ -297,6 +288,7 @@
     if (is.null(dateparams$dateGeneration)){dateparams$dateGeneration='Backward'}        
     if (is.null(dateparams$endOfMonth)){dateparams$endOfMonth=0}        
     if (is.null(dateparams$fixingDays)){dateparams$fixingDays=2}
+    if (is.null(dateparams$refDate)) {dateparams$refDate=bond$issueDate-2}
     
     dateparams <- matchParams(dateparams)
     if (class(curve)=="DiscountCurve"){
@@ -581,15 +573,23 @@
     val   
 }
 
-FittedBondCurve <- function(curveparams, lengths, coupons, dateparams){
+FittedBondCurve <- function(curveparams,
+                            lengths,
+                            coupons,
+                            marketQuotes,
+                            dateparams){
     UseMethod("FittedBondCurve")
 }
 
-FittedBondCurve.default <- function(curveparams, lengths, coupons, dateparams){
+FittedBondCurve.default <- function(curveparams,
+                                    lengths,
+                                    coupons,
+                                    marketQuotes,
+                                    dateparams){
     val <- 0
     dateparams <- matchParams(dateparams)
     val <- .Call("QL_FittedBondCurve", curveparams,
-                 lengths, coupons, dateparams, PACKAGE="RQuantLib")
+                 lengths, coupons, marketQuotes, dateparams, PACKAGE="RQuantLib")
 
     class(val) <- c("DiscountCurve")
     val$table <- as.data.frame(val$table)

Modified: pkg/man/ConvertibleFloatingCouponBond.Rd
===================================================================
--- pkg/man/ConvertibleFloatingCouponBond.Rd	2010-02-08 21:45:45 UTC (rev 173)
+++ pkg/man/ConvertibleFloatingCouponBond.Rd	2010-02-13 04:12:52 UTC (rev 174)
@@ -103,11 +103,10 @@
                dt=.25,
                interpWhat="discount",
                interpHow="loglinear")
-times <- seq(0,10,.1)
 
 
-dividendYield <- DiscountCurve(params, list(flat=0.02), times)
-riskFreeRate <- DiscountCurve(params, list(flat=0.05), times)
+dividendYield <- DiscountCurve(params, list(flat=0.02))
+riskFreeRate <- DiscountCurve(params, list(flat=0.05))
 
 dividendSchedule <- data.frame(Type=character(0), Amount=numeric(0),
                             Rate = numeric(0), Date = as.Date(character(0)))
@@ -118,46 +117,48 @@
                 rff = riskFreeRate, volatility=0.15)
 
 today <- Sys.Date()
-bondparams <- list(exercise="am", faceAmount=100, divSch = dividendSchedule, 
-                   callSch = callabilitySchedule, redemption=100, 
-                   creditSpread=0.005, conversionRatio = 0.0000000001, 
+bondparams <- list(exercise="am", faceAmount=100,
+                   divSch = dividendSchedule, 
+                   callSch = callabilitySchedule,
+                   redemption=100,
+                   creditSpread=0.005,
+                   conversionRatio = 0.0000000001, 
                    issueDate=as.Date(today+2), 
                    maturityDate=as.Date(today+3650))
 dateparams <- list(settlementDays=3, 
-                   dayCounter="Actual360", 
-                   period = "Once", calendar = "us", 
-                   businessDayConvention="Following"
-                   )
+                   dayCounter="ActualActual", 
+                   period = "Semiannual", calendar = "us", 
+                   businessDayConvention="Following")
 
 lengths <- c(2,4,6,8,10,12,14,16,18,20,22,24,26,28,30)
 coupons <- c( 0.0200, 0.0225, 0.0250, 0.0275, 0.0300,
               0.0325, 0.0350, 0.0375, 0.0400, 0.0425,
               0.0450, 0.0475, 0.0500, 0.0525, 0.0550 )
+marketQuotes <- rep(100, length(lengths))
 curvedateparams <- list(settlementDays=0, period="Annual", 
-                   dayCounter="SimpleDayCounter", 
+                   dayCounter="ActualActual", 
                   businessDayConvention ="Unadjusted")
 curveparams <- list(method="ExponentialSplinesFitting", 
                     origDate = Sys.Date())
-curve <- FittedBondCurve(curveparams, lengths, coupons, curvedateparams)
+curve <- FittedBondCurve(curveparams, lengths, coupons, marketQuotes, curvedateparams)
 iborindex <- list(type="USDLibor", length=6, 
                   inTermOf="Month", term=curve)   
 spreads <- c()
-ConvertibleFloatingCouponBond(bondparams, iborindex,spreads, process, dateparams)
+#ConvertibleFloatingCouponBond(bondparams, iborindex, spreads, process, dateparams)
 
 
 #example using default values
-ConvertibleFloatingCouponBond(bondparams, iborindex,spreads, process)
+#ConvertibleFloatingCouponBond(bondparams, iborindex,spreads, process)
 
 dateparams <- list(settlementDays=3,                    
-                   period = "Once", 
-                   businessDayConvention="Unadjusted"
-                   )
+                   period = "Semiannual", 
+                   businessDayConvention="Unadjusted")
 
 bondparams <- list(                  
                    creditSpread=0.005, conversionRatio = 0.0000000001, 
                    issueDate=as.Date(today+2), 
                    maturityDate=as.Date(today+3650))
-ConvertibleFloatingCouponBond(bondparams, iborindex,
-spreads, process, dateparams)
+#ConvertibleFloatingCouponBond(bondparams, iborindex,
+#spreads, process, dateparams)
 
 }

Modified: pkg/man/FittedBondCurve.Rd
===================================================================
--- pkg/man/FittedBondCurve.Rd	2010-02-08 21:45:45 UTC (rev 173)
+++ pkg/man/FittedBondCurve.Rd	2010-02-13 04:12:52 UTC (rev 174)
@@ -10,7 +10,7 @@
 }
 
 \usage{
-FittedBondCurve(curveparams, lengths, coupons, dateparams)
+FittedBondCurve(curveparams, lengths, coupons, marketQuotes, dateparams)
 }
 
 \arguments{
@@ -23,6 +23,7 @@
 }
 \item{lengths}{an numeric vector, length of the bonds in year}
 \item{coupons}{a numeric vector, coupon rate of the bonds}
+\item{marketQuotes}{a numeric vector, market price of the bonds}
 \item{dateparams}{(Optional) a named list, QuantLib's date parameters of the bond. 
   \tabular{ll}{
     \code{settlementDays} \tab (Optional) a double, settlement days. \cr 
@@ -63,12 +64,13 @@
 coupons <- c( 0.0200, 0.0225, 0.0250, 0.0275, 0.0300,
               0.0325, 0.0350, 0.0375, 0.0400, 0.0425,
               0.0450, 0.0475, 0.0500, 0.0525, 0.0550 )
+marketQuotes <- rep(100, length(lengths))
 dateparams <- list(settlementDays=0, period="Annual", 
-                   dayCounter="SimpleDayCounter", 
+                   dayCounter="ActualActual", 
                   businessDayConvention ="Unadjusted")
 curveparams <- list(method="ExponentialSplinesFitting", 
                     origDate = Sys.Date())
-curve <- FittedBondCurve(curveparams, lengths, coupons, dateparams)
+curve <- FittedBondCurve(curveparams, lengths, coupons, marketQuotes, dateparams)
 library(zoo)
 z <- zoo(curve$table$zeroRates, order.by=curve$table$date)
 plot(z)

Modified: pkg/man/ZeroCouponBond.Rd
===================================================================
--- pkg/man/ZeroCouponBond.Rd	2010-02-08 21:45:45 UTC (rev 173)
+++ pkg/man/ZeroCouponBond.Rd	2010-02-13 04:12:52 UTC (rev 174)
@@ -90,22 +90,23 @@
 
 
 \examples{
-# simple call with unnamed parameters
-bond <- list(faceAmount=100, issueDate=as.Date("2004-11-30"),
+# Simple call with all parameter and a flat curve
+bond <- list(faceAmount=100,issueDate=as.Date("2004-11-30"),
              maturityDate=as.Date("2008-11-30"), redemption=100 )
 
-dateparams <-list(settlementDays=1, calendar="us", businessDayConvention=4)
+dateparams <-list(settlementDays=1, calendar="us", businessDayConvention='Unadjusted')
 
-discountCurve <- list(todayDate=as.Date("2004-11-04"), riskFreeRate=0.03)
 
-ZeroCouponBond(bond, discountCurve, dateparams)
+discountCurve.param <- list(tradeDate=as.Date('2002-2-15'),
+                           settleDate=as.Date('2002-2-15'),
+                           dt=0.25,
+                           interpWhat='discount', interpHow='loglinear')
+discountCurve.flat <- DiscountCurve(discountCurve.param, list(flat=0.05))
 
-params <- list(tradeDate=as.Date('2002-2-15'),
-               settleDate=as.Date('2002-2-19'),
-               dt=.25,
-               interpWhat="discount",
-               interpHow="loglinear")
+ZeroCouponBond(bond, discountCurve.flat, dateparams)
 
+
+# The same bond with a discount curve constructed from market quotes
 tsQuotes <- list(d1w  =0.0382,
                  d1m  =0.0372,
                  fut1=96.2875,
@@ -120,34 +121,17 @@
                  s5y  =0.0443,
                  s10y =0.05165,
                  s15y =0.055175)
-
-times <- seq(0,10,.1)
-discountCurve <- list(params, tsQuotes, times)
-
-# depreciated
+discountCurve <- DiscountCurve(discountCurve.param, tsQuotes)
 ZeroCouponBond(bond, discountCurve, dateparams)
 
-# construct a curve
-curves <- DiscountCurve(params, tsQuotes, times)
-ZeroCouponBond(bond, curves, dateparams)
 
-#construct a flat curve
-flatquote <- list(flat=0.04)
-flatCurve <- DiscountCurve(params, flatquote, times)
-dateparams <-list(settlementDays=1, calendar="us", 
-                  businessDayConvention="Following")
-
-ZeroCouponBond(bond, flatCurve, dateparams)
-
 #examples with default arguments
-curve <- DiscountCurve(params, tsQuotes)
-ZeroCouponBond(bond, curve, dateparams)
-ZeroCouponBond(bond, curve)
+ZeroCouponBond(bond, discountCurve)
 
 bond <- list(issueDate=as.Date("2004-11-30"),
-maturityDate=as.Date("2008-11-30"))
+             maturityDate=as.Date("2008-11-30"))
 dateparams <-list(settlementDays=1)
-ZeroCouponBond(bond, curve, dateparams)
+ZeroCouponBond(bond, discountCurve, dateparams)
 
 }
 \keyword{misc}

Modified: pkg/src/bonds.cpp
===================================================================
--- pkg/src/bonds.cpp	2010-02-08 21:45:45 UTC (rev 173)
+++ pkg/src/bonds.cpp	2010-02-13 04:12:52 UTC (rev 174)
@@ -140,8 +140,8 @@
         double settlementDays = misc.getDoubleValue("settlementDays");
         std::string cal = misc.getStringValue("calendar");
         double businessDayConvention = misc.getDoubleValue("businessDayConvention");
-      
-
+        QuantLib::Date refDate(dateFromR(misc.getDateValue("refDate")));      
+        Settings::instance().evaluationDate() = refDate;                               
         
         /*
           test-suite/bonds.cpp
@@ -208,50 +208,8 @@
     return rl;
 }
 
-RcppExport SEXP QL_ZBond1(SEXP bondparam, SEXP discountCurve, SEXP dateparams){
-    SEXP rl = R_NilValue;
-    char *exceptionMesg = NULL;
-    try{
-        RcppParams curve(discountCurve);
-        Rate riskFreeRate = curve.getDoubleValue("riskFreeRate");
-        RcppDate today_Date = curve.getDateValue("todayDate");       
-        QuantLib::Date today(dateFromR(today_Date));
 
-        boost::shared_ptr<SimpleQuote> rRate(new SimpleQuote(riskFreeRate));
-        Settings::instance().evaluationDate() = today;
-        Handle<YieldTermStructure> discountCurve(flatRate(today,rRate,Actual360()));
 
-        rl = ZeroBond(bondparam, discountCurve, dateparams);
-    } catch(std::exception& ex) {
-        exceptionMesg = copyMessageToR(ex.what());
-    } catch(...) {
-        exceptionMesg = copyMessageToR("unknown reason");
-    }    
-    if(exceptionMesg != NULL)
-        Rf_error(exceptionMesg);
-    
-    return rl;
-}
-RcppExport SEXP QL_ZBond2(SEXP bondparam, SEXP params, 
-                          SEXP tsQuotes, SEXP times,
-                          SEXP dateparams){
-    SEXP rl = R_NilValue;
-    char *exceptionMesg = NULL;
-    try{
-        
-        Handle<YieldTermStructure> discountCurve(
-                                 buildTermStructure(params, tsQuotes, times));
-      
-        rl = ZeroBond(bondparam, discountCurve, dateparams);
-    } catch(std::exception& ex) {
-        exceptionMesg = copyMessageToR(ex.what());
-    } catch(...) {
-        exceptionMesg = copyMessageToR("unknown reason");
-    }    
-    if(exceptionMesg != NULL)
-        Rf_error(exceptionMesg);   
-    return rl;
-}
 
 
 
@@ -283,6 +241,8 @@
         double dateGeneration = misc.getDoubleValue("dateGeneration");
         double endOfMonthRule = misc.getDoubleValue("endOfMonth");
 
+
+
         //extract coupon rates vector
         RcppVector<double> RcppVec(ratesVec); 
         std::vector<double> rates(RcppVec.stlVector());
@@ -573,6 +533,7 @@
         double endOfMonthRule = misc.getDoubleValue("endOfMonth");
         double fixingDays = misc.getDoubleValue("fixingDays");
 
+        
 
         //build schedule
         BusinessDayConvention bdc = getBusinessDayConvention(businessDayConvention);
@@ -809,7 +770,8 @@
    SEXP rl=R_NilValue;
    char* exceptionMesg=NULL;
    try {
-       
+
+               
        Handle<YieldTermStructure> ibor_curve(rebuildCurveFromZeroRates(iborDateSexp,
                                                                    iborzeroSexp));       
        Handle<YieldTermStructure> curve(rebuildCurveFromZeroRates(dateSexp,
@@ -854,8 +816,8 @@
 }
 
 RcppExport SEXP QL_ZeroBondWithRebuiltCurve(SEXP bond,
-                                       SEXP dateSexp, SEXP zeroSexp,
-                                       SEXP dateparams){
+                                            SEXP dateSexp, SEXP zeroSexp,
+                                            SEXP dateparams){
     SEXP rl=R_NilValue;
     char* exceptionMesg=NULL;
     try{
@@ -1755,18 +1717,22 @@
 }
 */
 RcppExport SEXP QL_FittedBondCurve(SEXP curveparams, SEXP lengthVec,
-                                   SEXP couponVec,
+                                   SEXP couponVec,SEXP marketVec,
                                    SEXP dateparams){
     SEXP rl=R_NilValue;
     char* exceptionMesg=NULL;
     try {
 
-        //extract length and coupon vector
+
+        //extract length, coupon and market prices vector
         RcppVector<int> RcppVec(lengthVec); 
         std::vector<int> lengths(RcppVec.stlVector());
         RcppVector<double> RcppVec1(couponVec);
         std::vector<double> coupons(RcppVec1.stlVector());
+        RcppVector<double> RcppVec2(marketVec);
+        std::vector<double> marketQuotes(RcppVec2.stlVector());
 
+
         RcppParams misc(dateparams);      
         double settlementDays = misc.getDoubleValue("settlementDays");
         double dayCounter = misc.getDoubleValue("dayCounter");
@@ -1777,18 +1743,13 @@
         std::string method = curvepam.getStringValue("method");
         RcppDate oDate = curvepam.getDateValue("origDate");
         QuantLib::Date origDate(dateFromR(oDate));
+        Settings::instance().evaluationDate() = origDate;
 
-
         const Size numberOfBonds = lengths.size();
-        Real cleanPrice[numberOfBonds];
-        
-        for (Size i=0; i<=numberOfBonds; i++) {
-            cleanPrice[i]=100.0;
-        }
 
         std::vector< boost::shared_ptr<SimpleQuote> > quote;
-        for (Size i=0; i<numberOfBonds; i++) {
-            boost::shared_ptr<SimpleQuote> cp(new SimpleQuote(cleanPrice[i]));
+        for (Size i=0; i<numberOfBonds; i++) {            
+            boost::shared_ptr<SimpleQuote> cp(new SimpleQuote(marketQuotes[i]));
             quote.push_back(cp);
         }
 
@@ -1797,20 +1758,20 @@
             quoteHandle[i].linkTo(quote[i]);
         }
 
-        Calendar calendar = NullCalendar();
+        Calendar calendar =  UnitedStates(UnitedStates::GovernmentBond);
         BusinessDayConvention bdc = getBusinessDayConvention(businessDayConvention);
         DayCounter dc = getDayCounter(dayCounter);
         Frequency freq = getFrequency(frequency);
         Real redemption = 100;
 
         std::vector<boost::shared_ptr<FixedRateBondHelper> > instrumentsA;
-
+        
         for (Size j=0; j<lengths.size(); j++) {
 
             Date dated = origDate;
             Date issue = origDate;
             Date maturity = calendar.advance(issue, lengths[j], Years);
-
+            
             Schedule schedule(dated, maturity, Period(freq), calendar,
                               bdc, bdc,
                               DateGeneration::Backward, false);
@@ -1876,8 +1837,8 @@
             curve = ts3;
         }
         
+        
 
-
 	// Return discount, forward rate, and zero coupon curves
         int numCol = 3;
         std::vector<std::string> colNames(numCol);
@@ -1887,21 +1848,24 @@
 
 
         RcppFrame frame(colNames);
-        Date current = origDate;
-        int n = curve->maxDate() - origDate;
+        Date current = curve->referenceDate();;
+        int n = curve->maxDate() - curve->referenceDate();
+        std::cout << n << std::endl;
         for (int i = 0; i<n;i++){
-        std::vector<ColDatum> row(numCol);
+            std::vector<ColDatum> row(numCol);
             Date d = current; 
             row[0].setDateValue(RcppDate(d.month(),
                                          d.dayOfMonth(),
                                          d.year()));
             
-            double zrate = curve->zeroRate(current, ActualActual(),
-                                            Continuous);
+            double zrate = curve->zeroRate(current, 
+                                           ActualActual(),
+                                           Continuous);
             row[1].setDoubleValue(zrate);                        
-
+            
             double discount = curve->discount(current);
             row[2].setDoubleValue(discount);
+
             frame.addRow(row);
             current++;
         }

Modified: pkg/tests/RQuantlib.R
===================================================================
--- pkg/tests/RQuantlib.R	2010-02-08 21:45:45 UTC (rev 173)
+++ pkg/tests/RQuantlib.R	2010-02-13 04:12:52 UTC (rev 174)
@@ -63,12 +63,22 @@
 print( AsianOption("geometric", "put", underlying=80, strike=85, div=-0.03, riskFree=0.05, maturity=0.25, vol=0.2))
 
 # simple call with unnamed parameters
-bond <- list(faceAmount=100, issueDate=as.Date("2004-11-30"),
+
+bond <- list(faceAmount=100,issueDate=as.Date("2004-11-30"),
              maturityDate=as.Date("2008-11-30"), redemption=100 )
-dateparams <-list(settlementDays=1, calendar="us", businessDayConvention=4)
-discountCurve <- list(todayDate=as.Date("2004-11-04"), riskFreeRate=0.03)
-print(ZeroCouponBond(bond, discountCurve, dateparams))
 
+dateparams <-list(settlementDays=1, calendar="us", businessDayConvention='Unadjusted')
+
+
+discountCurve.param <- list(tradeDate=as.Date('2002-2-15'),
+                           settleDate=as.Date('2002-2-15'),
+                           dt=0.25,
+                           interpWhat='discount', interpHow='loglinear')
+discountCurve <- DiscountCurve(discountCurve.param, list(flat=0.05))
+
+ZeroCouponBond(bond, discountCurve, dateparams)
+
+
 ## bond.cpp: examples from Fixed Income page of Matlab
 ZeroYield(95, 100, as.Date("1993-6-24"), as.Date("1993-11-1"))
 
@@ -112,150 +122,3 @@
 print(FloatingRateBond(bond, gearings, spreads, caps, floors, 
                  iborindex, curve, dateparams))
 
-## CallableBond, following Example/CallableBond
-#set-up a HullWhite according to example from QuantLib
-HullWhite <- list(term = 0.055, alpha = 0.03, sigma = 0.01,
-                  gridIntervals = 40)
-
-#callability schedule dataframe
-Price <- rep(as.double(100),24)
-Type <- rep(as.character("C"), 24)
-Date <- seq(as.Date("2006-09-15"), by = '3 months', length = 24)
-callSch <- data.frame(Price, Type, Date)
-callSch$Type <- as.character(callSch$Type)
-
-bondparams <- list(faceAmount=100, issueDate = as.Date("2004-09-16"),
-                   maturityDate=as.Date("2012-09-16"), redemption=100,
-                   callSch = callSch)
-dateparams <- list(settlementDays=3, calendar="us", 
-                   dayCounter = "ActualActual", 
-                   period="Quarterly", 
-                   businessDayConvention = "Unadjusted", 
-                   terminationDateConvention= "Unadjusted")
-coupon <- c(0.0465)
-
-CallableBond(bondparams, HullWhite, coupon, dateparams)
-
-## ConvertibleFixedCouponBond, test-suite/convertiblebond.cpp for ConvertibleFixedCouponBond
-
-#set up arguments to build a pricing engine.
-today <- as.Date("2009-08-01")
-
-params <- list(tradeDate=today-2,
-               settleDate=today,
-               dt=.25,
-               interpWhat="discount",
-               interpHow="loglinear")
-times <- seq(0,10,.1)
-
-dividendYield <- DiscountCurve(params, list(flat=0.02), times)
-riskFreeRate <- DiscountCurve(params, list(flat=0.05), times)
-
-dividendSchedule <- data.frame(Type=character(0), Amount=numeric(0),
-                            Rate = numeric(0), Date = as.Date(character(0)))
-callabilitySchedule <- data.frame(Price = numeric(0), Type=character(0),
-                          Date = as.Date(character(0)))
-
-process <- list(underlying=50, divYield = dividendYield,
-                rff = riskFreeRate, volatility=0.15)
-
-
-bondparams <- list(exercise="am", faceAmount=100, divSch = dividendSchedule, 
-                   callSch = callabilitySchedule, redemption=100, 
-                   creditSpread=0.005, conversionRatio = 0.0000000001, 
-                   issueDate=as.Date(today+2), 
-                   maturityDate=as.Date(today+3650))
-dateparams <- list(settlementDays=3, 
-                   dayCounter="Actual360", 
-                   period = "Once", calendar = "us", 
-                   businessDayConvention="Following", 
-                   todayDate=as.Date(today))
-coupon <- c(0.05)
-ConvertibleFixedCouponBond(bondparams, coupon, process, dateparams)
-
-## ConvertibleFloatingCouponBond, test-suite/convertiblebond.cpp for ConvertibleZeroCouponBond
-
-today <- as.Date("2009-08-01")
-
-params <- list(tradeDate=today-2,
-               settleDate=today,
-               dt=.25,
-               interpWhat="discount",
-               interpHow="loglinear")
-times <- seq(0,10,.1)
-
-
-dividendYield <- DiscountCurve(params, list(flat=0.02), times)
-riskFreeRate <- DiscountCurve(params, list(flat=0.05), times)
-
-dividendSchedule <- data.frame(Type=character(0), Amount=numeric(0),
-                            Rate = numeric(0), Date = as.Date(character(0)))
-callabilitySchedule <- data.frame(Price = numeric(0), Type=character(0),
-                          Date = as.Date(character(0)))
-
-process <- list(underlying=50, divYield = dividendYield,
-                rff = riskFreeRate, volatility=0.15)
-
-
-bondparams <- list(exercise="am", faceAmount=100, divSch = dividendSchedule, 
-                   callSch = callabilitySchedule, redemption=100, 
-                   creditSpread=0.005, conversionRatio = 0.0000000001, 
-                   issueDate=as.Date(today+2), 
-                   maturityDate=as.Date(today+3650))
-dateparams <- list(settlementDays=3, 
-                   dayCounter="Actual360", 
-                   period = "Once", calendar = "us", 
-                   businessDayConvention="Following", 
-                   todayDate=as.Date(today))
-
-lengths <- c(2,4,6,8,10,12,14,16,18,20,22,24,26,28,30)
-coupons <- c( 0.0200, 0.0225, 0.0250, 0.0275, 0.0300,
-              0.0325, 0.0350, 0.0375, 0.0400, 0.0425,
-              0.0450, 0.0475, 0.0500, 0.0525, 0.0550 )
-curvedateparams <- list(settlementDays=0, period="Annual", 
-                   dayCounter="SimpleDayCounter", 
-                  businessDayConvention ="Unadjusted")
-curveparams <- list(method="ExponentialSplinesFitting", 
-                    origDate = today)
-curve <- FittedBondCurve(curveparams, lengths, coupons, curvedateparams)
-iborindex <- list(type="USDLibor", length=6, 
-                  inTermOf="Month", term=curve)   
-spreads <- c()
-ConvertibleFloatingCouponBond(bondparams, iborindex,spreads, process, dateparams)
-
-## ConvertibleZeroCouponBond, test-suite/convertiblebond.cpp for ConvertibleZeroCouponBond
-today <- as.Date("2009-08-01")
-params <- list(tradeDate=today-2,
-               settleDate=today,
-               dt=.25,
-               interpWhat="discount",
-               interpHow="loglinear")
-times <- seq(0,10,.1)
-
-
-dividendYield <- DiscountCurve(params, list(flat=0.02), times)
-riskFreeRate <- DiscountCurve(params, list(flat=0.05), times)
-
-dividendSchedule <- data.frame(Type=character(0), Amount=numeric(0),
-                            Rate = numeric(0), Date = as.Date(character(0)))
-callabilitySchedule <- data.frame(Price = numeric(0), Type=character(0),
-                          Date = as.Date(character(0)))
-
-process <- list(underlying=50, divYield = dividendYield,
-                rff = riskFreeRate, volatility=0.15)
-
-
-bondparams <- list(exercise="am", faceAmount=100, divSch = dividendSchedule, 
-                   callSch = callabilitySchedule, redemption=100, 
-                   creditSpread=0.005, conversionRatio = 0.0000000001, 
-                   issueDate=as.Date(today+2), 
-                   maturityDate=as.Date(today+3650))
-dateparams <- list(settlementDays=3, 
-                   dayCounter="Actual360", 
-                   period = "Once", calendar = "us", 
-                   businessDayConvention="Following", 
-                   todayDate=as.Date(today))
-
-ConvertibleZeroCouponBond(bondparams, process, dateparams)
-
-

Modified: pkg/tests/RQuantlib.Rout.save
===================================================================
--- pkg/tests/RQuantlib.Rout.save	2010-02-08 21:45:45 UTC (rev 173)
+++ pkg/tests/RQuantlib.Rout.save	2010-02-13 04:12:52 UTC (rev 174)
@@ -124,21 +124,31 @@
  4.6922 -0.8031  0.0594  6.8662  0.0580 -9.2039  8.0309 
 > 
 > # simple call with unnamed parameters
-> bond <- list(faceAmount=100, issueDate=as.Date("2004-11-30"),
+> 
+> bond <- list(faceAmount=100,issueDate=as.Date("2004-11-30"),
 +              maturityDate=as.Date("2008-11-30"), redemption=100 )
-> dateparams <-list(settlementDays=1, calendar="us", businessDayConvention=4)
-> discountCurve <- list(todayDate=as.Date("2004-11-04"), riskFreeRate=0.03)
-> print(ZeroCouponBond(bond, discountCurve, dateparams))
+> 
+> dateparams <-list(settlementDays=1, calendar="us", businessDayConvention='Unadjusted')
+> 
+> 
+> discountCurve.param <- list(tradeDate=as.Date('2002-2-15'),
++                            settleDate=as.Date('2002-2-15'),
++                            dt=0.25,
++                            interpWhat='discount', interpHow='loglinear')
+> discountCurve <- DiscountCurve(discountCurve.param, list(flat=0.05))
+> 
+> ZeroCouponBond(bond, discountCurve, dateparams)
 Concise summary of valuation for ZeroCouponBond 
- Net present value :  88.34535 
-       clean price :  88.537 
-       dirty price :  88.537 
+ Net present value :  71.21519 
+       clean price :  81.884 
+       dirty price :  81.884 
     accrued coupon :  0 
-             yield :  0.030455 
+             yield :  0.050516 
         cash flows : 
        Date Amount
  2008-11-30    100
 > 
+> 
 > ## bond.cpp: examples from Fixed Income page of Matlab
 > ZeroYield(95, 100, as.Date("1993-6-24"), as.Date("1993-11-1"))
 $yield
@@ -189,20 +199,20 @@
     accrued coupon :  0 
              yield :  0.030455 
         cash flows : 
-       Date   Amount
-  2005-03-31   0.95308
-  2005-07-29   0.94521
-  2005-11-30   0.97671
-  2006-03-31   0.95308
-  2006-07-31   0.96096
-  2006-11-30   0.96096
-  2007-03-30   0.94521
-  2007-07-31   0.96884
-  2007-11-30   0.96096
-  2008-03-31   0.96096
-  2008-07-31   0.96096
-  2008-11-30   0.96096
-  2008-11-30 100.00000
+       Date    Amount
+ 2005-03-31   0.95308
+ 2005-07-29   0.94521
+ 2005-11-30   0.97671
+ 2006-03-31   0.95308
+ 2006-07-31   0.96096
+ 2006-11-30   0.96096
+ 2007-03-30   0.94521
+ 2007-07-31   0.96884
+ 2007-11-30   0.96096
+ 2008-03-31   0.96096
+ 2008-07-31   0.96096
+ 2008-11-30   0.96096
+ 2008-11-30 100.00000
 > 
 > ## bond.cpp FloatingRateBond, following test-suite/bonds.cpp
 > bond <- list(faceAmount=100, issueDate=as.Date("2004-11-30"),
@@ -229,236 +239,19 @@
     accrued coupon :  0 
              yield :  0.025315 
         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-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
 > 
-> ## CallableBond, following Example/CallableBond
-> #set-up a HullWhite according to example from QuantLib
-> HullWhite <- list(term = 0.055, alpha = 0.03, sigma = 0.01,
-+                   gridIntervals = 40)
 > 
-> #callability schedule dataframe
-> Price <- rep(as.double(100),24)
-> Type <- rep(as.character("C"), 24)
-> Date <- seq(as.Date("2006-09-15"), by = '3 months', length = 24)
-> callSch <- data.frame(Price, Type, Date)
-> callSch$Type <- as.character(callSch$Type)
-> 
-> bondparams <- list(faceAmount=100, issueDate = as.Date("2004-09-16"),
-+                    maturityDate=as.Date("2012-09-16"), redemption=100,
-+                    callSch = callSch)
-> dateparams <- list(settlementDays=3, calendar="us", 
-+                    dayCounter = "ActualActual", 
-+                    period="Quarterly", 
-+                    businessDayConvention = "Unadjusted", 
-+                    terminationDateConvention= "Unadjusted")
-> coupon <- c(0.0465)
-> 
-> CallableBond(bondparams, HullWhite, coupon, dateparams)
-Concise summary of valuation for CallableBond 
- Net present value :  92.58479 
-       clean price :  91.683 
-       dirty price :  92.585 
-    accrued coupon :  0.90205 
-             yield :  0.059916 
-        cash flows : 
-       Date   Amount
- 2004-12-16   1.1561
- 2005-03-16   1.1460
- 2005-06-16   1.1721
- 2005-09-16   1.1721
- 2005-12-16   1.1593
- 2006-03-16   1.1466
- 2006-06-16   1.1721
- 2006-09-16   1.1721
- 2006-12-16   1.1593
- 2007-03-16   1.1466
- 2007-06-16   1.1721
- 2007-09-16   1.1721
- 2007-12-16   1.1593
- 2008-03-16   1.1567
- 2008-06-16   1.1689
- 2008-09-16   1.1689
- 2008-12-16   1.1561
- 2009-03-16   1.1460
- 2009-06-16   1.1721
- 2009-09-16   1.1721
- 2009-12-16   1.1593
- 2010-03-16   1.1466
- 2010-06-16   1.1721
- 2010-09-16   1.1721
- 2010-12-16   1.1593
- 2011-03-16   1.1466
- 2011-06-16   1.1721
- 2011-09-16   1.1721
- 2011-12-16   1.1593
- 2012-03-16   1.1567
- 2012-06-16   1.1689
- 2012-09-16   1.1689
- 2012-09-16 100.0000
-> 
-> ## ConvertibleFixedCouponBond, test-suite/convertiblebond.cpp for ConvertibleFixedCouponBond
-> 
[TRUNCATED]

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


More information about the Rquantlib-commits mailing list