示例#1
0
文件: ECB.cs 项目: akasolace/qlnet
        /*! returns the ECB code for the given date
         (e.g. MAR10 for March xxth, 2010).

         \warning It raises an exception if the input
                  date is not an ECB date
          */
        public static string code( Date ecbDate )
        {
            Utils.QL_REQUIRE(isECBdate(ecbDate),() => ecbDate + " is not a valid ECB date");

            string ECBcode = string.Empty;
            int y = ecbDate.year() % 100;
            string padding = string.Empty;
            if (y < 10)
            padding = "0";
            switch(ecbDate.month()) {
              case (int)Month.January:
            ECBcode += "JAN" + padding + y;
            break;
              case (int)Month.February:
            ECBcode += "FEB" + padding + y;
            break;
              case (int)Month.March:
            ECBcode += "MAR" + padding + y;
            break;
              case (int)Month.April:
            ECBcode += "APR" + padding + y;
            break;
              case (int)Month.May:
            ECBcode += "MAY" + padding + y;
            break;
              case (int)Month.June:
            ECBcode += "JUN" + padding + y;
            break;
              case (int)Month.July:
            ECBcode += "JUL" + padding + y;
            break;
              case (int)Month.August:
            ECBcode += "AUG" + padding + y;
            break;
              case (int)Month.September:
            ECBcode += "SEP" + padding + y;
            break;
              case (int)Month.October:
            ECBcode += "OCT" + padding + y;
            break;
              case (int)Month.November:
            ECBcode += "NOV" + padding + y;
            break;
              case (int)Month.December:
            ECBcode += "DEC" + padding + y;
            break;
              default:
            Utils.QL_FAIL("not an ECB month (and it should have been)");
            break;
            }

            #if(QL_EXTRA_SAFETY_CHECKS)
            QL_ENSURE(isECBcode(ECBcode.str()),
                  "the result " << ECBcode.str() <<
                  " is an invalid ECB code");
            #endif
            return ECBcode;
        }
示例#2
0
            public override int dayCount(Date d1, Date d2)
            {
                int s1, s2;

                s1 = d1.Day + MonthOffset[d1.month()-1] + (d1.year() * 365);
                s2 = d2.Day + MonthOffset[d2.month()-1] + (d2.year() * 365);

                if (d1.month() == (int)Month.Feb && d1.Day == 29)
                {
                    --s1;
                }

                if (d2.month() == (int)Month.Feb && d2.Day == 29)
                {
                    --s2;
                }

                return s2 - s1;
            }
示例#3
0
文件: Schedule.cs 项目: Yenyenx/qlnet
 Date previousTwentieth(Date d, DateGeneration.Rule rule)
 {
     Date result = new Date(20, d.month(), d.year());
      if (result > d)
     result -= new Period(1, TimeUnit.Months);
      if (rule == DateGeneration.Rule.TwentiethIMM ||
      rule == DateGeneration.Rule.OldCDS ||
      rule == DateGeneration.Rule.CDS)
      {
     int m = result.month();
     if (m % 3 != 0)
     { // not a main IMM nmonth
        int skip = m % 3;
        result -= new Period(skip, TimeUnit.Months);
     }
      }
      return result;
 }