startDate() публичный Метод

public startDate ( ) : Date
Результат Date
Пример #1
0
            //===========================================================================//
            //                            GFunctionWithShifts                            //
            //===========================================================================//
            public GFunctionWithShifts(CmsCoupon coupon, Handle <Quote> meanReversion)
            {
                meanReversion_   = meanReversion;
                calibratedShift_ = 0.03;
                tmpRs_           = 10000000.0;
                accuracy_        = 1.0e-14;

                SwapIndex   swapIndex = coupon.swapIndex();
                VanillaSwap swap      = swapIndex.underlyingSwap(coupon.fixingDate());

                swapRateValue_ = swap.fairRate();

                objectiveFunction_ = new ObjectiveFunction(this, swapRateValue_);

                Schedule schedule = swap.fixedSchedule();
                Handle <YieldTermStructure> rateCurve = swapIndex.forwardingTermStructure();
                DayCounter dc = swapIndex.dayCounter();

                swapStartTime_   = dc.yearFraction(rateCurve.link.referenceDate(), schedule.startDate());
                discountAtStart_ = rateCurve.link.discount(schedule.startDate());

                double paymentTime = dc.yearFraction(rateCurve.link.referenceDate(), coupon.date());

                shapedPaymentTime_ = shapeOfShift(paymentTime);

                List <CashFlow> fixedLeg = new List <CashFlow>(swap.fixedLeg());
                int             n        = fixedLeg.Count;

                shapedSwapPaymentTimes_ = new List <double>();
                swapPaymentDiscounts_   = new List <double>();
                accruals_ = new List <double>();

                for (int i = 0; i < n; ++i)
                {
                    Coupon coupon1 = fixedLeg[i] as Coupon;
                    accruals_.Add(coupon1.accrualPeriod());
                    Date   paymentDate     = new Date(coupon1.date().serialNumber());
                    double swapPaymentTime = dc.yearFraction(rateCurve.link.referenceDate(), paymentDate);
                    shapedSwapPaymentTimes_.Add(shapeOfShift(swapPaymentTime));
                    swapPaymentDiscounts_.Add(rateCurve.link.discount(paymentDate));
                }
                discountRatio_ = swapPaymentDiscounts_.Last() / discountAtStart_;
            }
Пример #2
0
        public RangeAccrualFloatersCoupon(Date paymentDate,
                                          double nominal,
                                          IborIndex index,
                                          Date startDate,
                                          Date endDate,
                                          int fixingDays,
                                          DayCounter dayCounter,
                                          double gearing,
                                          double spread,
                                          Date refPeriodStart,
                                          Date refPeriodEnd,
                                          Schedule observationsSchedule,
                                          double lowerTrigger,
                                          double upperTrigger)
            : base(paymentDate, nominal, startDate, endDate, fixingDays, index, gearing, spread, refPeriodStart, refPeriodEnd,
                   dayCounter)
        {
            observationsSchedule_ = observationsSchedule;
            lowerTrigger_         = lowerTrigger;
            upperTrigger_         = upperTrigger;

            Utils.QL_REQUIRE(lowerTrigger_ < upperTrigger, () => "lowerTrigger_>=upperTrigger");
            Utils.QL_REQUIRE(observationsSchedule_.startDate() == startDate, () => "incompatible start date");
            Utils.QL_REQUIRE(observationsSchedule_.endDate() == endDate, () => "incompatible end date");

            observationDates_ = new List <Date>(observationsSchedule_.dates());
            observationDates_.RemoveAt(observationDates_.Count - 1); //remove end date
            observationDates_.RemoveAt(0);                           //remove start date
            observationsNo_ = observationDates_.Count;

            Handle <YieldTermStructure> rateCurve = index.forwardingTermStructure();
            Date referenceDate = rateCurve.link.referenceDate();

            startTime_        = dayCounter.yearFraction(referenceDate, startDate);
            endTime_          = dayCounter.yearFraction(referenceDate, endDate);
            observationTimes_ = new List <double>();
            for (int i = 0; i < observationsNo_; i++)
            {
                observationTimes_.Add(dayCounter.yearFraction(referenceDate, observationDates_[i]));
            }
        }
Пример #3
0
            public GFunctionExactYield(CmsCoupon coupon)
            {
                SwapIndex   swapIndex = coupon.swapIndex();
                VanillaSwap swap      = swapIndex.underlyingSwap(coupon.fixingDate());

                Schedule schedule = swap.fixedSchedule();
                Handle <YieldTermStructure> rateCurve = swapIndex.forwardingTermStructure();

                DayCounter dc = swapIndex.dayCounter();

                double swapStartTime        = dc.yearFraction(rateCurve.link.referenceDate(), schedule.startDate());
                double swapFirstPaymentTime = dc.yearFraction(rateCurve.link.referenceDate(), schedule.date(1));

                double paymentTime = dc.yearFraction(rateCurve.link.referenceDate(), coupon.date());

                delta_ = (paymentTime - swapStartTime) / (swapFirstPaymentTime - swapStartTime);

                List <CashFlow> fixedLeg = new List <CashFlow>(swap.fixedLeg());
                int             n        = fixedLeg.Count;

                accruals_ = new List <double>();
                for (int i = 0; i < n; ++i)
                {
                    Coupon coupon1 = fixedLeg[i] as Coupon;
                    accruals_.Add(coupon1.accrualPeriod());
                }
            }
Пример #4
0
        public AssetSwap(bool parAssetSwap,
                         Bond bond,
                         double bondCleanPrice,
                         double nonParRepayment,
                         double gearing,
                         IborIndex iborIndex,
                         double spread = 0.0,
                         DayCounter floatingDayCount = null,
                         Date dealMaturity           = null,
                         bool payBondCoupon          = false)
            : base(2)
        {
            bond_            = bond;
            bondCleanPrice_  = bondCleanPrice;
            nonParRepayment_ = nonParRepayment;
            spread_          = spread;
            parSwap_         = parAssetSwap;

            Schedule tempSch = new Schedule(bond_.settlementDate(),
                                            bond_.maturityDate(),
                                            iborIndex.tenor(),
                                            iborIndex.fixingCalendar(),
                                            iborIndex.businessDayConvention(),
                                            iborIndex.businessDayConvention(),
                                            DateGeneration.Rule.Backward,
                                            false); // endOfMonth

            if (dealMaturity == null)
            {
                dealMaturity = bond_.maturityDate();
            }

            Utils.QL_REQUIRE(dealMaturity <= tempSch.dates().Last(), () =>
                             "deal maturity " + dealMaturity +
                             " cannot be later than (adjusted) bond maturity " +
                             tempSch.dates().Last());
            Utils.QL_REQUIRE(dealMaturity > tempSch.dates()[0], () =>
                             "deal maturity " + dealMaturity +
                             " must be later than swap start date " +
                             tempSch.dates()[0]);

            // the following might become an input parameter
            BusinessDayConvention paymentAdjustment = BusinessDayConvention.Following;

            Date     finalDate = tempSch.calendar().adjust(dealMaturity, paymentAdjustment);
            Schedule schedule  = tempSch.until(finalDate);

            // bondCleanPrice must be the (forward) clean price
            // at the floating schedule start date
            upfrontDate_ = schedule.startDate();
            double dirtyPrice = bondCleanPrice_ +
                                bond_.accruedAmount(upfrontDate_);

            double notional = bond_.notional(upfrontDate_);

            /* In the market asset swap, the bond is purchased in return for
             * payment of the full price. The notional of the floating leg is
             * then scaled by the full price. */
            if (!parSwap_)
            {
                notional *= dirtyPrice / 100.0;
            }

            if (floatingDayCount == null)
            {
                legs_[1] = new IborLeg(schedule, iborIndex)
                           .withSpreads(spread)
                           .withGearings(gearing)
                           .withNotionals(notional)
                           .withPaymentAdjustment(paymentAdjustment);
            }
            else
            {
                legs_[1] = new IborLeg(schedule, iborIndex)
                           .withSpreads(spread)
                           .withGearings(gearing)
                           .withPaymentDayCounter(floatingDayCount)
                           .withNotionals(notional)
                           .withPaymentAdjustment(paymentAdjustment);
            }

            foreach (CashFlow c in legs_[1])
            {
                c.registerWith(update);
            }


            List <CashFlow> bondLeg = bond_.cashflows();
            // skip bond redemption
            int i;

            for (i = 0; i < bondLeg.Count && bondLeg[i].date() <= dealMaturity; ++i)
            {
                // whatever might be the choice for the discounting engine
                // bond flows on upfrontDate_ must be discarded
                bool upfrontDateBondFlows = false;
                if (!bondLeg[i].hasOccurred(upfrontDate_, upfrontDateBondFlows))
                {
                    legs_[0].Add(bondLeg[i]);
                }
            }
            // if the first skipped cashflow is not the redemption
            // and it is a coupon then add the accrued coupon
            if (i < bondLeg.Count - 1)
            {
                Coupon c = bondLeg[i] as Coupon;
                if (c != null)
                {
                    CashFlow accruedCoupon = new SimpleCashFlow(c.accruedAmount(dealMaturity), finalDate);
                    legs_[0].Add(accruedCoupon);
                }
            }
            // add the nonParRepayment_
            CashFlow nonParRepaymentFlow = new SimpleCashFlow(nonParRepayment_, finalDate);

            legs_[0].Add(nonParRepaymentFlow);

            Utils.QL_REQUIRE(!legs_[0].empty(), () => "empty bond leg to start with");

            // special flows
            if (parSwap_)
            {
                // upfront on the floating leg
                double   upfront         = (dirtyPrice - 100.0) / 100.0 * notional;
                CashFlow upfrontCashFlow = new SimpleCashFlow(upfront, upfrontDate_);
                legs_[1].Insert(0, upfrontCashFlow);
                // backpayment on the floating leg
                // (accounts for non-par redemption, if any)
                double   backPayment         = notional;
                CashFlow backPaymentCashFlow = new SimpleCashFlow(backPayment, finalDate);
                legs_[1].Add(backPaymentCashFlow);
            }
            else
            {
                // final notional exchange
                CashFlow finalCashFlow = new SimpleCashFlow(notional, finalDate);
                legs_[1].Add(finalCashFlow);
            }

            Utils.QL_REQUIRE(!legs_[0].empty(), () => "empty bond leg");

            foreach (CashFlow c in legs_[0])
            {
                c.registerWith(update);
            }

            if (payBondCoupon)
            {
                payer_[0] = -1.0;
                payer_[1] = +1.0;
            }
            else
            {
                payer_[0] = +1.0;
                payer_[1] = -1.0;
            }
        }