Example #1
0
        public Swaption value()
        {
            Date     evaluationDate = Settings.evaluationDate();
            Calendar fixingCalendar = swapIndex_.fixingCalendar();

            fixingDate_ = fixingCalendar.advance(evaluationDate, optionTenor_, optionConvention_);

            if (exerciseDate_ == null)
            {
                exercise_ = new EuropeanExercise(fixingDate_);
            }
            else
            {
                if (exerciseDate_ <= fixingDate_)
                {
                    throw new ArgumentException(
                              "exercise date (" + exerciseDate_ + ") must be less " +
                              "than or equal to fixing date (" + fixingDate_ + ")");
                }
                exercise_ = new EuropeanExercise(exerciseDate_);
            }

            double usedStrike;

            if (strike_ == null)
            {
                // ATM on the forecasting curve
                if (!swapIndex_.forwardingTermStructure().empty())
                {
                    throw new ArgumentException(
                              "no forecasting term structure set to " + swapIndex_.name());
                }
                VanillaSwap temp =
                    swapIndex_.underlyingSwap(fixingDate_);
                temp.setPricingEngine(new DiscountingSwapEngine(
                                          swapIndex_.forwardingTermStructure()));
                usedStrike = temp.fairRate();
            }
            else
            {
                usedStrike = strike_.Value;
            }

            BusinessDayConvention bdc = swapIndex_.fixedLegConvention();

            underlyingSwap_ = new MakeVanillaSwap(swapIndex_.tenor(),
                                                  swapIndex_.iborIndex(),
                                                  usedStrike)
                              .withEffectiveDate(swapIndex_.valueDate(fixingDate_))
                              .withFixedLegCalendar(swapIndex_.fixingCalendar())
                              .withFixedLegDayCount(swapIndex_.dayCounter())
                              .withFixedLegConvention(bdc)
                              .withFixedLegTerminationDateConvention(bdc);

            Swaption swaption = new Swaption(underlyingSwap_, exercise_, delivery_);

            swaption.setPricingEngine(engine_);
            return(swaption);
        }
Example #2
0
        public SwapSpreadIndex(String familyName,
                               SwapIndex swapIndex1,
                               SwapIndex swapIndex2,
                               double gearing1 = 1.0,
                               double gearing2 = -1.0)
            : base(familyName, swapIndex1.tenor(), // does not make sense, but we have to provide one
                   swapIndex1.fixingDays(), swapIndex1.currency(), swapIndex1.fixingCalendar(), swapIndex1.dayCounter())
        {
            swapIndex1_ = swapIndex1;
            swapIndex2_ = swapIndex2;
            gearing1_   = gearing1;
            gearing2_   = gearing2;

            swapIndex1_.registerWith(update);
            swapIndex2_.registerWith(update);

            name_ = swapIndex1_.name() + "(" + gearing1 + ") + "
                    + swapIndex2_.name() + "(" + gearing1 + ")";

            Utils.QL_REQUIRE(swapIndex1_.fixingDays() == swapIndex2_.fixingDays(), () =>
                             "index1 fixing days ("
                             + swapIndex1_.fixingDays() + ")"
                             + "must be equal to index2 fixing days ("
                             + swapIndex2_.fixingDays() + ")");

            Utils.QL_REQUIRE(swapIndex1_.fixingCalendar() == swapIndex2_.fixingCalendar(), () =>
                             "index1 fixingCalendar ("
                             + swapIndex1_.fixingCalendar() + ")"
                             + "must be equal to index2 fixingCalendar ("
                             + swapIndex2_.fixingCalendar() + ")");

            Utils.QL_REQUIRE(swapIndex1_.currency() == swapIndex2_.currency(), () =>
                             "index1 currency (" + swapIndex1_.currency() + ")"
                             + "must be equal to index2 currency ("
                             + swapIndex2_.currency() + ")");

            Utils.QL_REQUIRE(swapIndex1_.dayCounter() == swapIndex2_.dayCounter(), () =>
                             "index1 dayCounter ("
                             + swapIndex1_.dayCounter() + ")"
                             + "must be equal to index2 dayCounter ("
                             + swapIndex2_.dayCounter() + ")");

            Utils.QL_REQUIRE(swapIndex1_.fixedLegTenor() == swapIndex2_.fixedLegTenor(), () =>
                             "index1 fixedLegTenor ("
                             + swapIndex1_.fixedLegTenor() + ")"
                             + "must be equal to index2 fixedLegTenor ("
                             + swapIndex2_.fixedLegTenor());

            Utils.QL_REQUIRE(swapIndex1_.fixedLegConvention() == swapIndex2_.fixedLegConvention(), () =>
                             "index1 fixedLegConvention ("
                             + swapIndex1_.fixedLegConvention() + ")"
                             + "must be equal to index2 fixedLegConvention ("
                             + swapIndex2_.fixedLegConvention());
        }