Changeset 217
- Timestamp:
- 06/28/08 09:30:09 (1 year ago)
- Files:
-
- trunk/QLNet/QLNet/Error.cs (modified) (1 diff)
- trunk/QLNet/QLNet/Time/Date.cs (modified) (1 diff)
- trunk/QLNet/QLNet/Time/Schedule.cs (modified) (8 diffs)
- trunk/QLNet/QLNet/Types.cs (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/QLNet/QLNet/Error.cs
r61 r217 29 29 public static ArgumentException UnknownBusinessDayConvention(BusinessDayConvention c) { 30 30 return new ArgumentException("Unknown business-day convention: " + c); } 31 public static ArgumentException UnknownDateGenerationRule(DateGeneration.Rule r) {32 return new ArgumentException("Unknown DateGeneration rule: " + r); }33 31 34 32 public static ApplicationException MissingImplementation() { trunk/QLNet/QLNet/Time/Date.cs
r205 r217 41 41 public int Day { get { return date.Day; } } 42 42 public int Month { get { return date.Month; } } 43 public int month() { return date.Month; } 43 44 public int Year { get { return date.Year; } } 45 public int year() { return date.Year; } 44 46 public int DayOfYear { get { return date.DayOfYear; } } 45 47 public int weekday() { return (int)date.DayOfWeek + 1; } // QL compatible definition trunk/QLNet/QLNet/Time/Schedule.cs
r214 r217 120 120 ") is later than or equal to termination date (" + terminationDate__ + ")"); 121 121 122 if (tenor_. units() == 0)122 if (tenor_.length() == 0) 123 123 rule_ = DateGeneration.Rule.Zero; 124 else if (tenor_. units() < 0)124 else if (tenor_.length() < 0) 125 125 throw new ArgumentException("Non positive tenor (" + tenor_ + ") is not allowed"); 126 126 127 // though firstDate_ and nextToLastDate are always provided128 127 if (firstDate_ != null) { 129 128 switch (rule_) { … … 134 133 + "), termination date (" + terminationDate__ + ")]"); 135 134 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; 136 139 case DateGeneration.Rule.Zero: 137 case DateGeneration.Rule.ThirdWednesday: 140 case DateGeneration.Rule.Twentieth: 141 case DateGeneration.Rule.TwentiethIMM: 138 142 throw new ArgumentException("First date is incompatible with " + rule_ + " date generation rule"); 139 143 default: 140 throw Error.UnknownDateGenerationRule(rule_);144 throw new ArgumentException("Unknown DateGeneration rule: " + rule_); 141 145 } 142 146 } … … 150 154 + "), termination date (" + terminationDate__ + ")]"); 151 155 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; 152 160 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"); 155 164 default: 156 throw Error.UnknownDateGenerationRule(rule_);165 throw new ArgumentException("Unknown DateGeneration rule: " + rule_); 157 166 } 158 167 } … … 200 209 break; 201 210 211 case DateGeneration.Rule.Twentieth: 212 case DateGeneration.Rule.TwentiethIMM: 202 213 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"); 204 216 goto case DateGeneration.Rule.Forward; // fall through 205 217 … … 212 224 isRegular_.Add(temp == firstDate_); 213 225 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 215 235 exitDate = terminationDate__; 216 236 if (nextToLastDate_ != null) … … 228 248 if (endOfMonth_ && calendar_.isEndOfMonth(seed)) 229 249 convention_ = BusinessDayConvention.Preceding; 250 230 251 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 } 233 259 } 234 260 break; 235 261 236 262 default: 237 throw Error.UnknownDateGenerationRule(rule_);263 throw new ArgumentException("Unknown DateGeneration rule: " + rule_); 238 264 } 239 265 … … 246 272 adjustedDates_.Add(calendar_.adjust(d, convention_)); 247 273 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) 250 279 adjustedDates_[adjustedDates_.Count - 1] = calendar_.adjust(originalDates_.Last(), terminationDateConvention_); 251 280 } … … 284 313 i_++; 285 314 } 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; 286 330 } 287 331 } trunk/QLNet/QLNet/Types.cs
r178 r217 131 131 Forward, /*!< Forward from effective date to termination date. */ 132 132 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 } 135 140 }; 136 141