Assembla home | Assembla project page
 

Changeset 217

Show
Ignore:
Timestamp:
06/28/08 09:30:09 (1 year ago)
Author:
snovik
Message:

Change: QL 15131, 14090, 14073-14074

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/QLNet/QLNet/Error.cs

    r61 r217  
    2929                public static ArgumentException UnknownBusinessDayConvention(BusinessDayConvention c) { 
    3030                        return new ArgumentException("Unknown business-day convention: " + c); } 
    31                 public static ArgumentException UnknownDateGenerationRule(DateGeneration.Rule r) { 
    32                         return new ArgumentException("Unknown DateGeneration rule: " + r); } 
    3331 
    3432                public static ApplicationException MissingImplementation() { 
  • trunk/QLNet/QLNet/Time/Date.cs

    r205 r217  
    4141        public int Day { get { return date.Day; } } 
    4242        public int Month { get { return date.Month; } } 
     43        public int month() { return date.Month; } 
    4344        public int Year { get { return date.Year; } } 
     45        public int year() { return date.Year; } 
    4446        public int DayOfYear { get { return date.DayOfYear; } } 
    4547        public int weekday() { return (int)date.DayOfWeek + 1; }       // QL compatible definition 
  • trunk/QLNet/QLNet/Time/Schedule.cs

    r214 r217  
    120120                       ") is later than or equal to termination date (" + terminationDate__ + ")"); 
    121121 
    122             if (tenor_.units() == 0) 
     122            if (tenor_.length() == 0) 
    123123                rule_ = DateGeneration.Rule.Zero; 
    124             else if (tenor_.units() < 0) 
     124            else if (tenor_.length() < 0) 
    125125                throw new ArgumentException("Non positive tenor (" + tenor_ + ") is not allowed"); 
    126126 
    127             // though firstDate_ and nextToLastDate are always provided 
    128127            if (firstDate_ != null) { 
    129128                switch (rule_) { 
     
    134133                                                        + "), termination date (" + terminationDate__ + ")]"); 
    135134                        break; 
     135                    case DateGeneration.Rule.ThirdWednesday: 
     136                        if (!IMM.isIMMdate(firstDate_, false)) 
     137                            throw new ArgumentException("first date (" + firstDate_ + ") is not an IMM date"); 
     138                        break; 
    136139                    case DateGeneration.Rule.Zero: 
    137                     case DateGeneration.Rule.ThirdWednesday: 
     140                    case DateGeneration.Rule.Twentieth: 
     141                    case DateGeneration.Rule.TwentiethIMM: 
    138142                        throw new ArgumentException("First date is incompatible with " + rule_ + " date generation rule"); 
    139143                    default: 
    140                         throw Error.UnknownDateGenerationRule(rule_); 
     144                        throw new ArgumentException("Unknown DateGeneration rule: " + rule_); 
    141145                } 
    142146            } 
     
    150154                               + "), termination date (" + terminationDate__ + ")]"); 
    151155                        break; 
     156                    case DateGeneration.Rule.ThirdWednesday: 
     157                        if (!IMM.isIMMdate(firstDate_, false)) 
     158                            throw new ArgumentException("first date (" + firstDate_ + ") is not an IMM date"); 
     159                        break; 
    152160                    case DateGeneration.Rule.Zero: 
    153                     case DateGeneration.Rule.ThirdWednesday: 
    154                         throw new ArgumentException("Next to last date incompatible with " + rule_ + " date generation rule"); 
     161                    case DateGeneration.Rule.Twentieth: 
     162                    case DateGeneration.Rule.TwentiethIMM: 
     163                        throw new ArgumentException("next to last is incompatible with " + rule_ + " date generation rule"); 
    155164                    default: 
    156                         throw Error.UnknownDateGenerationRule(rule_); 
     165                        throw new ArgumentException("Unknown DateGeneration rule: " + rule_); 
    157166                } 
    158167            } 
     
    200209                    break; 
    201210 
     211                case DateGeneration.Rule.Twentieth: 
     212                case DateGeneration.Rule.TwentiethIMM: 
    202213                case DateGeneration.Rule.ThirdWednesday: 
    203                     if (endOfMonth_) throw new ArgumentException("endOfMonth convention is incompatible with " + rule_ + " date generation rule"); 
     214                    if (endOfMonth_)  
     215                        throw new ArgumentException("endOfMonth convention is incompatible with " + rule_ + " date generation rule"); 
    204216                    goto case DateGeneration.Rule.Forward;                      // fall through 
    205217 
     
    212224                        isRegular_.Add(temp == firstDate_); 
    213225                        seed = firstDate_; 
    214                     } 
     226                    } else if (rule_ == DateGeneration.Rule.Twentieth || rule_ == DateGeneration.Rule.TwentiethIMM) { 
     227                        Date next20th = nextTwentieth(effectiveDate__, rule_); 
     228                        if (next20th != effectiveDate__) { 
     229                            originalDates_.Add(next20th); 
     230                            isRegular_.Add(false); 
     231                            seed = next20th; 
     232                        } 
     233                    } 
     234 
    215235                    exitDate = terminationDate__; 
    216236                    if (nextToLastDate_ != null) 
     
    228248                    if (endOfMonth_ && calendar_.isEndOfMonth(seed)) 
    229249                        convention_ = BusinessDayConvention.Preceding; 
     250 
    230251                    if (calendar_.adjust(originalDates_.Last(), terminationDateConvention_) != calendar_.adjust(terminationDate__, terminationDateConvention_)) { 
    231                         originalDates_.Add(terminationDate__); 
    232                         isRegular_.Add(false); 
     252                        if (rule_ == DateGeneration.Rule.Twentieth || rule_ == DateGeneration.Rule.TwentiethIMM) { 
     253                            originalDates_.Add(nextTwentieth(terminationDate__, rule_)); 
     254                            isRegular_.Add(true); 
     255                        } else { 
     256                            originalDates_.Add(terminationDate__); 
     257                            isRegular_.Add(false); 
     258                        } 
    233259                    } 
    234260                    break; 
    235261 
    236262                default: 
    237                     throw Error.UnknownDateGenerationRule(rule_); 
     263                    throw new ArgumentException("Unknown DateGeneration rule: " + rule_); 
    238264            } 
    239265 
     
    246272                adjustedDates_.Add(calendar_.adjust(d, convention_)); 
    247273 
    248             // termination date is NOT adjusted as per ISDA specifications unless otherwise specified in the confirmation of the deal 
    249             if (terminationDateConvention_ != BusinessDayConvention.Unadjusted) 
     274            // termination date is NOT adjusted as per ISDA specifications, unless otherwise specified in the 
     275            // confirmation of the deal or unless we're creating a CDS schedule 
     276            if (terminationDateConvention_ != BusinessDayConvention.Unadjusted  
     277                || rule_ == DateGeneration.Rule.Twentieth 
     278                || rule_ == DateGeneration.Rule.TwentiethIMM) 
    250279                adjustedDates_[adjustedDates_.Count - 1] = calendar_.adjust(originalDates_.Last(), terminationDateConvention_); 
    251280        }  
     
    284313                i_++; 
    285314            } 
     315        } 
     316 
     317 
     318        Date nextTwentieth(Date d, DateGeneration.Rule rule) { 
     319            Date result = new Date(20, d.month(), d.year()); 
     320            if (result < d) 
     321                result += new Period(1, TimeUnit.Months); 
     322            if (rule == DateGeneration.Rule.TwentiethIMM) { 
     323                int m = result.month(); 
     324                if (m % 3 != 0) { // not a main IMM nmonth 
     325                    int skip = 3 - m % 3; 
     326                    result += new Period(skip, TimeUnit.Months); 
     327                } 
     328            } 
     329            return result; 
    286330        } 
    287331        } 
  • trunk/QLNet/QLNet/Types.cs

    r178 r217  
    131131            Forward,       /*!< Forward from effective date to termination date. */ 
    132132            Zero,          /*!< No intermediate dates between effective date and termination date. */ 
    133             ThirdWednesday /*!< All dates but effective date and termination date are taken to be on the third wednesday of their month*/ 
    134         }; 
     133            ThirdWednesday,/*!< All dates but effective date and termination date are taken to be on the third wednesday of their month*/ 
     134            Twentieth,     /*!< All dates but the effective date are taken to be the twentieth of their 
     135                                month (used for CDS schedules in emerging markets.)  The termination 
     136                                date is also modified. */ 
     137            TwentiethIMM   /*!< All dates but the effective date are taken to be the twentieth of an IMM 
     138                                month (used for CDS schedules.)  The termination date is also modified. */         
     139        } 
    135140    }; 
    136141