390 {
391
392
393
394 std::sort(instruments.begin(), instruments.end(), QuantLib::detail::BootstrapHelperSorter());
395
396
397 Real accuracy =
curveConfig_->bootstrapConfig().accuracy();
398 Real globalAccuracy =
curveConfig_->bootstrapConfig().globalAccuracy();
399 bool dontThrow =
curveConfig_->bootstrapConfig().dontThrow();
400 Size maxAttempts =
curveConfig_->bootstrapConfig().maxAttempts();
401 Real maxFactor =
curveConfig_->bootstrapConfig().maxFactor();
402 Real minFactor =
curveConfig_->bootstrapConfig().minFactor();
403 Size dontThrowSteps =
curveConfig_->bootstrapConfig().dontThrowSteps();
404
405 QuantLib::ext::shared_ptr<YieldTermStructure> yieldts;
410 typedef PiecewiseYieldCurve<ZeroYield, Linear, QuantExt::IterativeBootstrap> my_curve;
411 yieldts = QuantLib::ext::make_shared<my_curve>(
413 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
414 minFactor, dontThrowSteps));
415 } break;
417 typedef PiecewiseYieldCurve<ZeroYield, LogLinear, QuantExt::IterativeBootstrap> my_curve;
418 yieldts = QuantLib::ext::make_shared<my_curve>(
420 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
421 minFactor, dontThrowSteps));
422 } break;
424 typedef PiecewiseYieldCurve<ZeroYield, Cubic, QuantExt::IterativeBootstrap> my_curve;
425 yieldts = QuantLib::ext::make_shared<my_curve>(
427 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
428 minFactor, dontThrowSteps));
429 } break;
431 typedef PiecewiseYieldCurve<ZeroYield, Cubic, QuantExt::IterativeBootstrap> my_curve;
432 yieldts = QuantLib::ext::make_shared<my_curve>(
434 Cubic(CubicInterpolation::Kruger, true, CubicInterpolation::SecondDerivative, 0.0,
435 CubicInterpolation::FirstDerivative),
436 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
437 minFactor, dontThrowSteps));
438 } break;
440 typedef PiecewiseYieldCurve<ZeroYield, ConvexMonotone, QuantExt::IterativeBootstrap> my_curve;
441 yieldts = QuantLib::ext::make_shared<my_curve>(
443 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
444 minFactor, dontThrowSteps));
445 } break;
447 typedef PiecewiseYieldCurve<ZeroYield, Cubic, QuantExt::IterativeBootstrap> my_curve;
448 yieldts = QuantLib::ext::make_shared<my_curve>(
450 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
451 minFactor, dontThrowSteps));
452 } break;
454 typedef PiecewiseYieldCurve<ZeroYield, Cubic, QuantExt::IterativeBootstrap> my_curve;
455 yieldts = QuantLib::ext::make_shared<my_curve>(
457 Cubic(CubicInterpolation::Spline, false, CubicInterpolation::SecondDerivative, 0.0,
458 CubicInterpolation::SecondDerivative, 0.0),
459 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor, minFactor,
460 dontThrowSteps));
461 } break;
463 typedef PiecewiseYieldCurve<ZeroYield, QuantExt::Quadratic, QuantExt::IterativeBootstrap> my_curve;
464 yieldts =
465 QuantLib::ext::make_shared<my_curve>(
467 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
468 minFactor, dontThrowSteps));
469 } break;
471 typedef PiecewiseYieldCurve<ZeroYield, QuantExt::LogQuadratic, QuantExt::IterativeBootstrap> my_curve;
472 yieldts = QuantLib::ext::make_shared<my_curve>(
474 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
475 minFactor, dontThrowSteps));
476 } break;
478 typedef PiecewiseYieldCurve<ZeroYield, LogCubic, QuantExt::IterativeBootstrap> my_curve;
479 yieldts = QuantLib::ext::make_shared<my_curve>(
481 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
482 minFactor, dontThrowSteps));
483 } break;
485 typedef PiecewiseYieldCurve<ZeroYield, LogCubic, QuantExt::IterativeBootstrap> my_curve;
486 yieldts = QuantLib::ext::make_shared<my_curve>(
488 LogCubic(CubicInterpolation::Kruger, true, CubicInterpolation::SecondDerivative, 0.0,
489 CubicInterpolation::FirstDerivative),
490 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor, minFactor,
491 dontThrowSteps));
492 } break;
494 typedef PiecewiseYieldCurve<ZeroYield, LogCubic, QuantExt::IterativeBootstrap> my_curve;
495 yieldts = QuantLib::ext::make_shared<my_curve>(
497 LogCubic(CubicInterpolation::Spline, false, CubicInterpolation::SecondDerivative, 0.0,
498 CubicInterpolation::SecondDerivative, 0.0),
499 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor, minFactor,
500 dontThrowSteps));
501 } break;
503 typedef PiecewiseYieldCurve<ZeroYield, DefaultLogMixedLinearCubic, QuantExt::IterativeBootstrap> my_curve;
504 yieldts = QuantLib::ext::make_shared<my_curve>(
506 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
507 minFactor, dontThrowSteps));
508 } break;
510 typedef PiecewiseYieldCurve<ZeroYield, MonotonicLogMixedLinearCubic, QuantExt::IterativeBootstrap> my_curve;
511 yieldts = QuantLib::ext::make_shared<my_curve>(
513 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
514 minFactor, dontThrowSteps));
515 } break;
517 typedef PiecewiseYieldCurve<ZeroYield, KrugerLogMixedLinearCubic, QuantExt::IterativeBootstrap> my_curve;
518 yieldts = QuantLib::ext::make_shared<my_curve>(
520 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
521 minFactor, dontThrowSteps));
522 } break;
524 typedef PiecewiseYieldCurve<ZeroYield, LogMixedLinearCubic, QuantExt::IterativeBootstrap> my_curve;
525 yieldts = QuantLib::ext::make_shared<my_curve>(
528 CubicInterpolation::Spline, false, CubicInterpolation::SecondDerivative, 0.0,
529 CubicInterpolation::SecondDerivative, 0.0),
530 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
531 minFactor, dontThrowSteps));
532 } break;
533 default:
535 }
536 break;
540 typedef PiecewiseYieldCurve<Discount, Linear, QuantExt::IterativeBootstrap> my_curve;
541 yieldts = QuantLib::ext::make_shared<my_curve>(
543 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
544 minFactor, dontThrowSteps));
545 } break;
547 typedef PiecewiseYieldCurve<Discount, LogLinear, QuantExt::IterativeBootstrap> my_curve;
548 yieldts = QuantLib::ext::make_shared<my_curve>(
550 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
551 minFactor, dontThrowSteps));
552 } break;
554 typedef PiecewiseYieldCurve<Discount, Cubic, QuantExt::IterativeBootstrap> my_curve;
555 yieldts = QuantLib::ext::make_shared<my_curve>(
557 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
558 minFactor, dontThrowSteps));
559 } break;
561 typedef PiecewiseYieldCurve<Discount, Cubic, QuantExt::IterativeBootstrap> my_curve;
562 yieldts = QuantLib::ext::make_shared<my_curve>(
564 Cubic(CubicInterpolation::Kruger, true, CubicInterpolation::SecondDerivative, 0.0,
565 CubicInterpolation::FirstDerivative),
566 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
567 minFactor, dontThrowSteps));
568 } break;
570 typedef PiecewiseYieldCurve<Discount, ConvexMonotone, QuantExt::IterativeBootstrap> my_curve;
571 yieldts = QuantLib::ext::make_shared<my_curve>(
573 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
574 minFactor, dontThrowSteps));
575 } break;
577 typedef PiecewiseYieldCurve<Discount, Cubic, QuantExt::IterativeBootstrap> my_curve;
578 yieldts = QuantLib::ext::make_shared<my_curve>(
580 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
581 minFactor, dontThrowSteps));
582 } break;
584 typedef PiecewiseYieldCurve<Discount, Cubic, QuantExt::IterativeBootstrap> my_curve;
585 yieldts = QuantLib::ext::make_shared<my_curve>(
587 Cubic(CubicInterpolation::Spline, false, CubicInterpolation::SecondDerivative, 0.0,
588 CubicInterpolation::SecondDerivative, 0.0),
589 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
590 minFactor, dontThrowSteps));
591 } break;
593 typedef PiecewiseYieldCurve<Discount, QuantExt::Quadratic, QuantExt::IterativeBootstrap> my_curve;
594 yieldts = QuantLib::ext::make_shared<my_curve>(
596 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
597 minFactor, dontThrowSteps));
598 } break;
600 typedef PiecewiseYieldCurve<Discount, QuantExt::LogQuadratic, QuantExt::IterativeBootstrap> my_curve;
601 yieldts = QuantLib::ext::make_shared<my_curve>(
603 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
604 minFactor, dontThrowSteps));
605 } break;
607 typedef PiecewiseYieldCurve<Discount, LogCubic, QuantExt::IterativeBootstrap> my_curve;
608 yieldts = QuantLib::ext::make_shared<my_curve>(
610 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
611 minFactor, dontThrowSteps));
612 } break;
614 typedef PiecewiseYieldCurve<Discount, LogCubic, QuantExt::IterativeBootstrap> my_curve;
615 yieldts = QuantLib::ext::make_shared<my_curve>(
617 QuantLib::LogCubic(CubicInterpolation::Kruger, true, CubicInterpolation::SecondDerivative, 0.0,
618 CubicInterpolation::FirstDerivative),
619 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor, minFactor,
620 dontThrowSteps));
621 } break;
623 typedef PiecewiseYieldCurve<Discount,LogCubic, QuantExt::IterativeBootstrap> my_curve;
624 yieldts = QuantLib::ext::make_shared<my_curve>(
626 LogCubic(CubicInterpolation::Spline, false, CubicInterpolation::SecondDerivative, 0.0,
627 CubicInterpolation::SecondDerivative, 0.0),
628 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor, minFactor,
629 dontThrowSteps));
630 } break;
632 typedef PiecewiseYieldCurve<Discount, DefaultLogMixedLinearCubic, QuantExt::IterativeBootstrap> my_curve;
633 yieldts = QuantLib::ext::make_shared<my_curve>(
635 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
636 minFactor, dontThrowSteps));
637 } break;
639 typedef PiecewiseYieldCurve<Discount, MonotonicLogMixedLinearCubic, QuantExt::IterativeBootstrap> my_curve;
640 yieldts = QuantLib::ext::make_shared<my_curve>(
642 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
643 minFactor, dontThrowSteps));
644 } break;
646 typedef PiecewiseYieldCurve<Discount, KrugerLogMixedLinearCubic, QuantExt::IterativeBootstrap> my_curve;
647 yieldts = QuantLib::ext::make_shared<my_curve>(
649 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
650 minFactor, dontThrowSteps));
651 } break;
653 typedef PiecewiseYieldCurve<Discount, LogMixedLinearCubic, QuantExt::IterativeBootstrap> my_curve;
654 yieldts = QuantLib::ext::make_shared<my_curve>(
657 CubicInterpolation::Spline, false, CubicInterpolation::SecondDerivative, 0.0,
658 CubicInterpolation::SecondDerivative, 0.0),
659 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
660 minFactor, dontThrowSteps));
661 } break;
662 default:
664 }
665 break;
669 typedef PiecewiseYieldCurve<ForwardRate, Linear, QuantExt::IterativeBootstrap> my_curve;
670 yieldts = QuantLib::ext::make_shared<my_curve>(
672 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
673 minFactor, dontThrowSteps));
674 } break;
676 typedef PiecewiseYieldCurve<ForwardRate, LogLinear, QuantExt::IterativeBootstrap> my_curve;
677 yieldts = QuantLib::ext::make_shared<my_curve>(
679 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
680 minFactor, dontThrowSteps));
681 } break;
683 typedef PiecewiseYieldCurve<ForwardRate, Cubic, QuantExt::IterativeBootstrap> my_curve;
684 yieldts = QuantLib::ext::make_shared<my_curve>(
686 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
687 minFactor, dontThrowSteps));
688 } break;
690 typedef PiecewiseYieldCurve<ForwardRate, Cubic, QuantExt::IterativeBootstrap> my_curve;
691 yieldts = QuantLib::ext::make_shared<my_curve>(
693 Cubic(CubicInterpolation::Kruger, true, CubicInterpolation::SecondDerivative, 0.0,
694 CubicInterpolation::FirstDerivative),
695 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
696 minFactor, dontThrowSteps));
697 } break;
699 typedef PiecewiseYieldCurve<ForwardRate, ConvexMonotone, QuantExt::IterativeBootstrap> my_curve;
700 yieldts = QuantLib::ext::make_shared<my_curve>(
702 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
703 minFactor, dontThrowSteps));
704 } break;
706 typedef PiecewiseYieldCurve<ForwardRate, Cubic, QuantExt::IterativeBootstrap> my_curve;
707 yieldts = QuantLib::ext::make_shared<my_curve>(
709 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
710 minFactor, dontThrowSteps));
711 } break;
713 typedef PiecewiseYieldCurve<ForwardRate, Cubic, QuantExt::IterativeBootstrap> my_curve;
714 yieldts = QuantLib::ext::make_shared<my_curve>(
716 Cubic(CubicInterpolation::Spline, false, CubicInterpolation::SecondDerivative, 0.0,
717 CubicInterpolation::SecondDerivative, 0.0),
718 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
719 minFactor, dontThrowSteps));
720 } break;
722 typedef PiecewiseYieldCurve<ForwardRate, QuantExt::Quadratic, QuantExt::IterativeBootstrap> my_curve;
723 yieldts = QuantLib::ext::make_shared<my_curve>(
725 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
726 minFactor, dontThrowSteps));
727 } break;
729 typedef PiecewiseYieldCurve<ForwardRate, QuantExt::LogQuadratic, QuantExt::IterativeBootstrap> my_curve;
730 yieldts = QuantLib::ext::make_shared<my_curve>(
732 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
733 minFactor, dontThrowSteps));
734 } break;
736 typedef PiecewiseYieldCurve<ForwardRate, LogCubic, QuantExt::IterativeBootstrap> my_curve;
737 yieldts = QuantLib::ext::make_shared<my_curve>(
739 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor, minFactor,
740 dontThrowSteps));
741 } break;
743 typedef PiecewiseYieldCurve<ForwardRate, LogCubic, QuantExt::IterativeBootstrap> my_curve;
744 yieldts = QuantLib::ext::make_shared<my_curve>(
746 LogCubic(CubicInterpolation::Kruger, true, CubicInterpolation::SecondDerivative, 0.0,
747 CubicInterpolation::FirstDerivative),
748 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor, minFactor,
749 dontThrowSteps));
750 } break;
752 typedef PiecewiseYieldCurve<ForwardRate, LogCubic, QuantExt::IterativeBootstrap> my_curve;
753 yieldts = QuantLib::ext::make_shared<my_curve>(
755 LogCubic(CubicInterpolation::Spline, false, CubicInterpolation::SecondDerivative, 0.0,
756 CubicInterpolation::SecondDerivative, 0.0),
757 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor, minFactor,
758 dontThrowSteps));
759 } break;
761 typedef PiecewiseYieldCurve<ForwardRate, DefaultLogMixedLinearCubic, QuantExt::IterativeBootstrap> my_curve;
762 yieldts = QuantLib::ext::make_shared<my_curve>(
764 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
765 minFactor, dontThrowSteps));
766 } break;
768 typedef PiecewiseYieldCurve<ForwardRate, MonotonicLogMixedLinearCubic, QuantExt::IterativeBootstrap> my_curve;
769 yieldts = QuantLib::ext::make_shared<my_curve>(
771 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
772 minFactor, dontThrowSteps));
773 } break;
775 typedef PiecewiseYieldCurve<ForwardRate, KrugerLogMixedLinearCubic, QuantExt::IterativeBootstrap> my_curve;
776 yieldts = QuantLib::ext::make_shared<my_curve>(
778 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
779 minFactor, dontThrowSteps));
780 } break;
782 typedef PiecewiseYieldCurve<ForwardRate, LogMixedLinearCubic, QuantExt::IterativeBootstrap> my_curve;
783 yieldts = QuantLib::ext::make_shared<my_curve>(
786 CubicInterpolation::Spline, false, CubicInterpolation::SecondDerivative, 0.0,
787 CubicInterpolation::SecondDerivative, 0.0),
788 my_curve::bootstrap_type(accuracy, globalAccuracy, dontThrow, maxAttempts, maxFactor,
789 minFactor, dontThrowSteps));
790 } break;
791 default:
793 }
794 break;
795 default:
796 QL_FAIL("Interpolation variable not recognised.");
797 }
798
801 else {
802
803
804
805
806
807
808 vector<Date> dates(instruments.size() + 1,
asofDate_);
809 vector<Real> zeros(instruments.size() + 1, 0.0);
810 vector<Real> discounts(instruments.size() + 1, 1.0);
811 vector<Real> forwards(instruments.size() + 1, 0.0);
812
814 yieldts->enableExtrapolation();
815 }
816 for (Size i = 0; i < instruments.size(); i++) {
817 dates[i + 1] = instruments[i]->pillarDate();
818 zeros[i + 1] = yieldts->zeroRate(dates[i + 1],
zeroDayCounter_, Continuous);
819 discounts[i + 1] = yieldts->discount(dates[i + 1]);
820 forwards[i + 1] = yieldts->forwardRate(dates[i + 1], dates[i + 1],
zeroDayCounter_, Continuous);
821 }
822 zeros[0] = zeros[1];
823 forwards[0] = forwards[1];
830 else
831 QL_FAIL("Interpolation variable not recognised.");
832 }
833
834
836 calibrationInfo_ = QuantLib::ext::make_shared<PiecewiseYieldCurveCalibrationInfo>();
837 for (Size i = 0; i < instruments.size(); ++i) {
839 }
840 }
841
843}
QuantLib::ext::shared_ptr< YieldTermStructure > forwardcurve(const vector< Date > &dates, const vector< Rate > &forwards, const DayCounter &dayCounter, YieldCurve::InterpolationMethod interpolationMethod, Size n)
Create a Interpolated Forward Curve and apply interpolators.