Changeset 207
- Timestamp:
- 06/15/08 22:53:10 (5 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/QLNet/QLNet/Math/Interpolations/convexmonotoneinterpolation.cs
r202 r207 49 49 } 50 50 public double primitive(double x) { 51 double result = (quadraticity_ * quadraticHelper_.primitive(x) + (1.0 - quadraticity_) * convMonoHelper_.primitive(x)); 51 52 return (quadraticity_ * quadraticHelper_.primitive(x) + (1.0 - quadraticity_) * convMonoHelper_.primitive(x)); 52 53 } … … 618 619 return extrapolationHelper_.value(x); 619 620 } 620 return sectionHelpers_[sectionHelpers_.Keys.First(y => x < y)].value(x); 621 622 double i; 623 if (x > sectionHelpers_.Keys.Last()) 624 i = sectionHelpers_.Keys.Last(); 625 else if (x < sectionHelpers_.Keys.First()) 626 i = sectionHelpers_.Keys.First(); 627 else 628 i = sectionHelpers_.Keys.First(y => x < y); 629 return sectionHelpers_[i].value(x); 621 630 } 622 631 … … 625 634 return extrapolationHelper_.primitive(x); 626 635 } 627 return sectionHelpers_[sectionHelpers_.Keys.First(y => x < y)].primitive(x); 636 637 double i; 638 if (x >= sectionHelpers_.Keys.Last()) 639 i = sectionHelpers_.Keys.Last(); 640 else if (x <= sectionHelpers_.Keys.First()) 641 i = sectionHelpers_.Keys.First(); 642 else 643 i = sectionHelpers_.Keys.First(y => x < y); 644 return sectionHelpers_[i].primitive(x); 628 645 } 629 646 … … 718 735 public bool global { get { return true; } } 719 736 public int requiredPoints { get { return 2; } } 720 721 const int dataSizeAdjustment = 1; 737 public int dataSizeAdjustment { get { return 1; } } 722 738 } 723 739 } trunk/QLNet/QLNet/Termstructures/Iterativebootstrap.cs
r202 r207 42 42 (ts_.interpolator_.requiredPoints-1) + " required"); 43 43 44 for (int i = 0; i < n; ++i) { 45 ts_.instruments_[i].registerWith(ts_.update); 46 } 44 ts_.instruments_.ForEach(x => x.registerWith(ts_.update)); 47 45 } 48 46 … … 55 53 56 54 //prepare instruments 57 int n = ts_.instruments_.Count ;55 int n = ts_.instruments_.Count, i; 58 56 59 57 // ensure rate helpers are sorted … … 61 59 62 60 // check that there is no instruments with the same maturity 63 for (i nt i= 1; i < n; ++i) {61 for (i = 1; i < n; ++i) { 64 62 Date m1 = ts_.instruments_[i - 1].latestDate(), 65 63 m2 = ts_.instruments_[i].latestDate(); … … 68 66 69 67 // check that there is no instruments with invalid quote 70 for (int i = 0; i < n; ++i)71 if (!ts_.instruments_[i].quoteIsValid())72 throw new ArgumentException("instrument " + i + " (maturity: " + ts_.instruments_[i].latestDate() +73 ") has an invalid quote");68 i = ts_.instruments_.FindIndex(x => !x.quoteIsValid()); 69 if (i != -1) 70 throw new ArgumentException("instrument " + i + " (maturity: " + ts_.instruments_[i].latestDate() + 71 ") has an invalid quote"); 74 72 75 73 // setup instruments and register with them 76 for (int i = 0; i < n; ++i) { 77 // There is a significant interaction with observability. 78 ts_.instruments_[i].setTermStructure(ts_); 79 } 74 ts_.instruments_.ForEach(x => x.setTermStructure(ts_)); 80 75 81 76 // calculate dates and times … … 84 79 ts_.dates_[0] = ts_.initialDate(ts_); 85 80 ts_.times_[0] = ts_.timeFromReference(ts_.dates_[0]); 86 for (i nt i= 0; i < n; ++i) {81 for (i = 0; i < n; ++i) { 87 82 ts_.dates_[i + 1] = ts_.instruments_[i].latestDate(); 88 83 ts_.times_[i + 1] = ts_.timeFromReference(ts_.dates_[i + 1]); … … 107 102 ts_.interpolation_ = ts_.interpolator_.interpolate(ts_.times_, ts_.times_.Count, ts_.data_); 108 103 } 109 for (i nt i=1; i<n+1; ++i) {104 for (i=1; i<n+1; ++i) { 110 105 // calculate guess before extending interpolation to ensure that any extrapolation is performed 111 106 // using the curve bootstrapped so far and no more … … 165 160 // exit conditions 166 161 double improvement = 0.0; 167 for (i nt i=1; i<n+1; ++i)162 for (i=1; i<n+1; ++i) 168 163 improvement = Math.Max(improvement, Math.Abs(ts_.data_[i]-previousData[i])); 169 164 if (improvement<=ts_.accuracy_) // convergence reached trunk/QLNet/Test2008/T_Piecewiseyieldcurve.cs
r203 r207 467 467 } 468 468 469 470 //void PiecewiseYieldCurveTest::testLiborFixing() {471 472 // BOOST_MESSAGE(473 // "Testing use of today's LIBOR fixings in swap curve...");474 475 // CommonVars vars;476 477 // std::vector<boost::shared_ptr<RateHelper> > swapHelpers(vars.swaps);478 // boost::shared_ptr<IborIndex> euribor6m(new Euribor6M);479 480 // for (Size i=0; i<vars.swaps; i++) {481 // Handle<Quote> r(vars.rates[i+vars.deposits]);482 // swapHelpers[i] = boost::shared_ptr<RateHelper>(new483 // SwapRateHelper(r, Period(swapData[i].n, swapData[i].units),484 // vars.calendar,485 // vars.fixedLegFrequency, vars.fixedLegConvention,486 // vars.fixedLegDayCounter, euribor6m));487 // }488 489 // vars.termStructure = boost::shared_ptr<YieldTermStructure>(new490 // PiecewiseYieldCurve<Discount,LogLinear>(vars.settlement,491 // swapHelpers,492 // Actual360()));493 494 // Handle<YieldTermStructure> curveHandle =495 // Handle<YieldTermStructure>(vars.termStructure);496 497 // boost::shared_ptr<IborIndex> index(new Euribor6M(curveHandle));498 // for (Size i=0; i<vars.swaps; i++) {499 // Period tenor = swapData[i].n*swapData[i].units;500 501 // VanillaSwap swap = MakeVanillaSwap(tenor, index, 0.0)502 // .withEffectiveDate(vars.settlement)503 // .withFixedLegDayCount(vars.fixedLegDayCounter)504 // .withFixedLegTenor(Period(vars.fixedLegFrequency))505 // .withFixedLegConvention(vars.fixedLegConvention)506 // .withFixedLegTerminationDateConvention(vars.fixedLegConvention);507 508 // Rate expectedRate = swapData[i].rate/100,509 // estimatedRate = swap.fairRate();510 // Real tolerance = 1.0e-9;511 // if (std::fabs(expectedRate-estimatedRate) > tolerance) {512 // BOOST_ERROR("before LIBOR fixing:\n"513 // + swapData[i].n + " year(s) swap:\n"514 // + std::setprecision(8)515 // + " estimated rate: "516 // + io::rate(estimatedRate) + "\n"517 // + " expected rate: "518 // + io::rate(expectedRate));519 // }520 // }521 522 // Flag f;523 // f.registerWith(vars.termStructure);524 // f.lower();525 526 // index->addFixing(vars.today, 0.0425);527 528 // if (!f.isUp())529 // BOOST_ERROR("Observer was not notified of rate fixing");530 531 // for (Size i=0; i<vars.swaps; i++) {532 // Period tenor = swapData[i].n*swapData[i].units;533 534 // VanillaSwap swap = MakeVanillaSwap(tenor, index, 0.0)535 // .withEffectiveDate(vars.settlement)536 // .withFixedLegDayCount(vars.fixedLegDayCounter)537 // .withFixedLegTenor(Period(vars.fixedLegFrequency))538 // .withFixedLegConvention(vars.fixedLegConvention)539 // .withFixedLegTerminationDateConvention(vars.fixedLegConvention);540 541 // Rate expectedRate = swapData[i].rate/100,542 // estimatedRate = swap.fairRate();543 // Real tolerance = 1.0e-9;544 // if (std::fabs(expectedRate-estimatedRate) > tolerance) {545 // BOOST_ERROR("after LIBOR fixing:\n"546 // + swapData[i].n + " year(s) swap:\n"547 // + std::setprecision(8)548 // + " estimated rate: "549 // + io::rate(estimatedRate) + "\n"550 // + " expected rate: "551 // + io::rate(expectedRate));552 // }553 // }554 //}555 556 469 [TestMethod()] 557 470 public void testForwardRateDayCounter() {