Beispiel #1
0
RcppExport SEXP endOfMonth(SEXP calSexp, SEXP dateSexp){

    try {
        boost::shared_ptr<QuantLib::Calendar> pcal( getCalendar(Rcpp::as<std::string>(calSexp)) );

        Rcpp::DateVector dates  = Rcpp::DateVector(dateSexp);
        int n = dates.size();
        std::vector<QuantLib::Date> eom(n);

        for (int i=0; i<n; i++) {
            QuantLib::Date day( dateFromR(dates[i]) );
            eom[i] = pcal->endOfMonth(day);
            dates[i] = Rcpp::Date(eom[i].month(), eom[i].dayOfMonth(), eom[i].year());
        }
       
        return Rcpp::wrap(dates);

    } catch(std::exception &ex) { 
        forward_exception_to_r(ex); 
    } catch(...) { 
        ::Rf_error("c++ exception (unknown reason)"); 
    }

    return R_NilValue;
}
Beispiel #2
0
// [[Rcpp::export]]
std::vector<bool> isEndOfMonth(std::string calendar, std::vector<QuantLib::Date> dates) {
    boost::shared_ptr<QuantLib::Calendar> pcal(getCalendar(calendar));
    int n = dates.size();
    std::vector<bool> eom(n);
    for (int i=0; i<n; i++) {
        eom[i] = pcal->isEndOfMonth(dates[i]);
    }
    return eom;
}
Beispiel #3
0
int
main(int argc, char ** argv)
{
   char * fn;
   int ix;

   if (3 > argc)
      return fprintf(stderr, "Specify library file name and copy file name(s).\n"), 1;
   if (openout(argv[1])) return 16;

   if (getdir(cards * 80)) return 20;

   for (ix = 2; argv[ix]; ix++)
   {
      char * dot;
      char * slash;
      char * name;
      int namelen;
      int ismacro = 1;                /* Assume file is macro        */
      char * s;

      fn = argv[ix];
      f = fopen(fn, "r");
      if (!f) return fprintf(stderr, "Cannot open %s:  %s\n", fn, strerror(errno)), 16;

      slash = strrchr(fn, '/');
      name = slash ? slash + 1 : fn;
      namelen = strlen(name);

      dot = strrchr(name, '.');
      if (dot)
      {
         namelen = dot - name;
         if (!strcmp(dot + 1, "copy")) ismacro = 0;
      }

      s = gline();
      if (!s) continue;
      if (!ismacro && memcmp(s, "*COPY ", 6)) ismacro = 1;   /* Not stacked copy */
      if (ismacro)
      {
         loadname(name, namelen);
         if (doline(line)) return 20;
      }
      else if (newmember(s)) return 20;
      for (;;)
      {
         s = gline();
         if (!s) break;
         if (!ismacro && !memcmp(s, "*COPY ", 6))
         {
            if (eom()) return 20;
            if (newmember(s)) return 20;
            continue;
         }
         if (doline(line)) return 20;
      }
      if (eom()) return 20;
   }
   if (wrapup(dirs, dir)) return 16;
   printf("%s %d files %d members.\n",
      fno, ix - 2, members);
   return 0;
}