Changeset 209
- Timestamp:
- 06/16/08 22:31:33 (3 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/QLNet/QLNet/Termstructures/Yield/PiecewiseYieldCurve.cs
r208 r209 68 68 : base(referenceDate, instruments, dayCounter) { } 69 69 public PiecewiseYieldCurve(Date referenceDate, List<BootstrapHelper<YieldTermStructure>> instruments, 70 DayCounter dayCounter, Handle<Quote> turnOfYearEffect)71 : base(referenceDate, instruments, dayCounter, turnOfYearEffect) { }72 public PiecewiseYieldCurve(Date referenceDate, List<BootstrapHelper<YieldTermStructure>> instruments, 73 DayCounter dayCounter, Handle<Quote> turnOfYearEffect, double accuracy)74 : base(referenceDate, instruments, dayCounter, turnOfYearEffect, accuracy) { }75 public PiecewiseYieldCurve(Date referenceDate, List<BootstrapHelper<YieldTermStructure>> instruments, 76 DayCounter dayCounter, Handle<Quote> turnOfYearEffect, double accuracy, Interpolator i)77 : base(referenceDate, instruments, dayCounter, turnOfYearEffect, accuracy, i) { }70 DayCounter dayCounter, List<Handle<Quote>> jumps, List<Date> jumpDates) 71 : base(referenceDate, instruments, dayCounter, jumps, jumpDates) { } 72 public PiecewiseYieldCurve(Date referenceDate, List<BootstrapHelper<YieldTermStructure>> instruments, 73 DayCounter dayCounter, List<Handle<Quote>> jumps, List<Date> jumpDates, double accuracy) 74 : base(referenceDate, instruments, dayCounter, jumps, jumpDates, accuracy) { } 75 public PiecewiseYieldCurve(Date referenceDate, List<BootstrapHelper<YieldTermStructure>> instruments, 76 DayCounter dayCounter, List<Handle<Quote>> jumps, List<Date> jumpDates, double accuracy, Interpolator i) 77 : base(referenceDate, instruments, dayCounter, jumps, jumpDates, accuracy, i) { } 78 78 79 79 public PiecewiseYieldCurve(int settlementDays, Calendar calendar, List<BootstrapHelper<YieldTermStructure>> instruments, 80 80 DayCounter dayCounter) 81 : this(settlementDays, calendar, instruments, dayCounter, new Handle<Quote>(), 1.0e-12) { }81 : this(settlementDays, calendar, instruments, dayCounter, new List<Handle<Quote>>(), new List<Date>(), 1.0e-12) { } 82 82 //public InterpolatedYieldCurve(int settlementDays, Calendar calendar, List<BootstrapHelper<YieldTermStructure>> instruments, 83 83 // DayCounter dayCounter, Quote turnOfYearEffect) : 84 84 // this(settlementDays, calendar, instruments, dayCounter, turnOfYearEffect, 1.0e-12) { } 85 85 public PiecewiseYieldCurve(int settlementDays, Calendar calendar, List<BootstrapHelper<YieldTermStructure>> instruments, 86 DayCounter dayCounter, Handle<Quote> turnOfYearEffect, double accuracy)87 : base(settlementDays, calendar, instruments, dayCounter, turnOfYearEffect, accuracy) { }86 DayCounter dayCounter, List<Handle<Quote>> jumps, List<Date> jumpDates, double accuracy) 87 : base(settlementDays, calendar, instruments, dayCounter, jumps, jumpDates, accuracy) { } 88 88 } 89 89 … … 98 98 public List<double> times_ = new List<double>(); 99 99 100 protected Handle<Quote> turnOfYearEffect_; 100 private List<Handle<Quote>> jumps_; 101 private List<Date> jumpDates_; 102 private List<double> jumpTimes_; 103 private int nJumps_; 104 101 105 public double accuracy_; 102 106 protected Date latestReference_; 103 protected double turnOfYear_;104 107 105 108 public Interpolator interpolator_; … … 146 149 #region Constructors 147 150 public PiecewiseYieldCurve(Date referenceDate, List<BootstrapHelper<YieldTermStructure>> instruments, DayCounter dayCounter) 148 : this(referenceDate, instruments, dayCounter, new Handle<Quote>(), 1.0e-12, new Interpolator(), new BootStrap()) { } 149 public PiecewiseYieldCurve(Date referenceDate, List<BootstrapHelper<YieldTermStructure>> instruments, 150 DayCounter dayCounter, Handle<Quote> turnOfYearEffect) 151 : this(referenceDate, instruments, dayCounter, turnOfYearEffect, 1.0e-12, new Interpolator(), new BootStrap()) { } 152 public PiecewiseYieldCurve(Date referenceDate, List<BootstrapHelper<YieldTermStructure>> instruments, 153 DayCounter dayCounter, Handle<Quote> turnOfYearEffect, double accuracy) 154 : this(referenceDate, instruments, dayCounter, turnOfYearEffect, accuracy, new Interpolator(), new BootStrap()) { } 155 public PiecewiseYieldCurve(Date referenceDate, List<BootstrapHelper<YieldTermStructure>> instruments, 156 DayCounter dayCounter, Handle<Quote> turnOfYearEffect, double accuracy, Interpolator i) 157 : this(referenceDate, instruments, dayCounter, turnOfYearEffect, accuracy, i, new BootStrap()) { } 158 public PiecewiseYieldCurve(Date referenceDate, List<BootstrapHelper<YieldTermStructure>> instruments, 159 DayCounter dayCounter, Handle<Quote> turnOfYearEffect, double accuracy, 160 Interpolator i, BootStrap bootstrap) 151 : this(referenceDate, instruments, dayCounter, new List<Handle<Quote>>(), new List<Date>(), 152 1.0e-12, new Interpolator(), new BootStrap()) { } 153 public PiecewiseYieldCurve(Date referenceDate, List<BootstrapHelper<YieldTermStructure>> instruments, 154 DayCounter dayCounter, List<Handle<Quote>> jumps, List<Date> jumpDates) 155 : this(referenceDate, instruments, dayCounter, jumps, jumpDates, 1.0e-12, new Interpolator(), new BootStrap()) { } 156 public PiecewiseYieldCurve(Date referenceDate, List<BootstrapHelper<YieldTermStructure>> instruments, 157 DayCounter dayCounter, List<Handle<Quote>> jumps, 158 List<Date> jumpDates, double accuracy) 159 : this(referenceDate, instruments, dayCounter, jumps, jumpDates, accuracy, new Interpolator(), new BootStrap()) { } 160 public PiecewiseYieldCurve(Date referenceDate, List<BootstrapHelper<YieldTermStructure>> instruments, 161 DayCounter dayCounter, List<Handle<Quote>> jumps, 162 List<Date> jumpDates, double accuracy, Interpolator i) 163 : this(referenceDate, instruments, dayCounter, jumps, jumpDates, accuracy, i, new BootStrap()) { } 164 public PiecewiseYieldCurve(Date referenceDate, List<BootstrapHelper<YieldTermStructure>> instruments, 165 DayCounter dayCounter, List<Handle<Quote>> jumps, List<Date> jumpDates, 166 double accuracy, Interpolator i, BootStrap bootstrap) 161 167 : base(referenceDate, new Calendar(), dayCounter) { 162 168 instruments_ = instruments; 163 turnOfYearEffect_ = turnOfYearEffect; 169 170 jumps_ = jumps; 171 jumpDates_ = jumpDates; 172 jumpTimes_ = new InitializedList<double>(jumpDates.Count); 173 nJumps_ = jumps_.Count; 174 164 175 accuracy_ = accuracy; 165 176 interpolator_ = i; 166 177 bootstrap_ = bootstrap; 167 178 168 setTurnOfYear(); 169 turnOfYearEffect_.registerWith(update); 179 setJumps(); 180 jumps.ForEach(x => x.registerWith(update)); 181 170 182 bootstrap_.setup<Traits, Interpolator, BootStrap>(this); 171 183 } … … 177 189 // DayCounter dayCounter, Quote turnOfYearEffect) : 178 190 // this(settlementDays, calendar, instruments, dayCounter, turnOfYearEffect, 1.0e-12) { } 179 public PiecewiseYieldCurve(int settlementDays, Calendar calendar, List<BootstrapHelper<YieldTermStructure>> instruments, 180 DayCounter dayCounter, Handle<Quote> turnOfYearEffect, double accuracy) 181 : this(settlementDays, calendar, instruments, dayCounter, turnOfYearEffect, accuracy, 191 //List<Handle<Quote>> jumps = std::vector<Handle<Quote> >(), 192 //List<Date> jumpDates = std::vector<Date>(), 193 public PiecewiseYieldCurve(int settlementDays, Calendar calendar, List<BootstrapHelper<YieldTermStructure>> instruments, 194 DayCounter dayCounter, List<Handle<Quote>> jumps, List<Date> jumpDates, double accuracy) 195 : this(settlementDays, calendar, instruments, dayCounter, jumps, jumpDates, accuracy, 182 196 new Interpolator(), new BootStrap()) { } 183 197 public PiecewiseYieldCurve(int settlementDays, Calendar calendar, List<BootstrapHelper<YieldTermStructure>> instruments, 184 DayCounter dayCounter, Handle<Quote> turnOfYearEffect, double accuracy,198 DayCounter dayCounter, List<Handle<Quote>> jumps, List<Date> jumpDates, double accuracy, 185 199 Interpolator i, BootStrap bootstrap) 186 200 : base(settlementDays, calendar, dayCounter) { 187 201 instruments_ = instruments; 188 turnOfYearEffect_ = turnOfYearEffect; 202 203 jumps_ = jumps; 204 jumpDates_ = jumpDates; 205 jumpTimes_ = new InitializedList<double>(jumpDates.Count); 206 nJumps_ = jumps_.Count; 207 189 208 accuracy_ = accuracy; 190 209 interpolator_ = i; 191 210 bootstrap_ = bootstrap; 192 211 193 setTurnOfYear(); 194 turnOfYearEffect_.registerWith(update); 212 setJumps(); 213 jumps.ForEach(x => x.registerWith(update)); 214 195 215 bootstrap_.setup<Traits, Interpolator, BootStrap>(this); 196 216 } … … 216 236 // LazyObject::update(); // we do it in the TermStructure 217 237 if (referenceDate() != latestReference_) 218 set TurnOfYear();219 } 220 221 private void set TurnOfYear() {238 setJumps(); 239 } 240 241 private void setJumps() { 222 242 Date refDate = referenceDate(); 223 Date turnOfYear = new Date(31, Month.December, refDate.Year); 224 turnOfYear_ = timeFromReference(turnOfYear); 243 244 if (jumpDates_.Count != 0 && jumps_.Count != 0) { // turn of year dates 245 jumpDates_ = new InitializedList<Date>(nJumps_); 246 jumpTimes_ = new InitializedList<double>(nJumps_); 247 for (int i=0; i<nJumps_; ++i) 248 jumpDates_[i] = new Date(31, Month.December, refDate.Year + i); 249 } else { // fixed dats 250 if (!(jumpDates_.Count == nJumps_)) 251 throw new ApplicationException("mismatch between number of jumps (" + nJumps_ + 252 ") and jump dates (" + jumpDates_.Count + ")"); 253 } 254 for (int i=0; i<nJumps_; ++i) 255 jumpTimes_[i] = timeFromReference(jumpDates_[i]); 225 256 latestReference_ = refDate; 257 } 258 259 public List<Date> jumpDates() { 260 calculate(); 261 return jumpDates_; 262 } 263 264 public List<double> jumpTimes() { 265 calculate(); 266 return jumpTimes_; 226 267 } 227 268 trunk/QLNet/Test2008/T_Piecewiseyieldcurve.cs
r207 r209 502 502 503 503 vars.termStructure = new PiecewiseYieldCurve<T, I, B>(vars.settlement, vars.instruments, 504 new Actual360(), new Handle<Quote>(), 1.0e-12, interpolator);504 new Actual360(), new List<Handle<Quote>>(), new List<Date>(), 1.0e-12, interpolator); 505 505 506 506 RelinkableHandle<YieldTermStructure> curveHandle = new RelinkableHandle<YieldTermStructure>(); … … 547 547 // check bonds 548 548 vars.termStructure = new PiecewiseYieldCurve<T, I, B>(vars.settlement, vars.bondHelpers, 549 new Actual360(), new Handle<Quote>(), 1.0e-12, interpolator);549 new Actual360(), new List<Handle<Quote>>(), new List<Date>(), 1.0e-12, interpolator); 550 550 curveHandle.linkTo(vars.termStructure); 551 551 … … 574 574 // check FRA 575 575 vars.termStructure = new PiecewiseYieldCurve<T, I, B>(vars.settlement, vars.fraHelpers, 576 new Actual360(), new Handle<Quote>(), 1.0e-12, interpolator);576 new Actual360(), new List<Handle<Quote>>(), new List<Date>(), 1.0e-12, interpolator); 577 577 curveHandle.linkTo(vars.termStructure); 578 578 … … 644 644 645 645 vars.termStructure = new PiecewiseYieldCurve<T, I, B>(vars.settlement, vars.bmaHelpers, 646 new Actual360(), new Handle<Quote>(), 1.0e-12, interpolator);646 new Actual360(), new List<Handle<Quote>>(), new List<Date>(), 1.0e-12, interpolator); 647 647 648 648 RelinkableHandle<YieldTermStructure> curveHandle = new RelinkableHandle<YieldTermStructure>();