Example #1
0
        public ConvertibleFixedCouponBond(Exercise exercise,
                                          double conversionRatio,
                                          DividendSchedule dividends,
                                          CallabilitySchedule callability,
                                          Handle <Quote> creditSpread,
                                          Date issueDate,
                                          int settlementDays,
                                          List <double> coupons,
                                          DayCounter dayCounter,
                                          Schedule schedule,
                                          double redemption = 100)
            : base(
                exercise, conversionRatio, dividends, callability, creditSpread, issueDate, settlementDays, schedule,
                redemption)
        {
            // !!! notional forcibly set to 100
            cashflows_ = new FixedRateLeg(schedule)
                         .withCouponRates(coupons, dayCounter)
                         .withNotionals(100.0)
                         .withPaymentAdjustment(schedule.businessDayConvention());

            addRedemptionsToCashflows(new List <double>()
            {
                redemption
            });

            Utils.QL_REQUIRE(redemptions_.Count == 1, () => "multiple redemptions created");

            option_ = new option(this, exercise, conversionRatio, dividends, callability, creditSpread, cashflows_,
                                 dayCounter, schedule,
                                 issueDate, settlementDays, redemption);
        }
Example #2
0
        //! fixed-rate bond

        /*! \ingroup instruments
         *
         *  \test calculations are tested by checking results against
         *        cached values.
         */


        //! simple annual compounding coupon rates
        public FixedRateBond(int settlementDays, double faceAmount, Schedule schedule, List <double> coupons,
                             DayCounter accrualDayCounter, BusinessDayConvention paymentConvention = BusinessDayConvention.Following,
                             double redemption         = 100, Date issueDate = null, Calendar paymentCalendar = null,
                             Period exCouponPeriod     = null,
                             Calendar exCouponCalendar = null,
                             BusinessDayConvention exCouponConvention = BusinessDayConvention.Unadjusted,
                             bool exCouponEndOfMonth = false)
            : base(settlementDays, paymentCalendar ?? schedule.calendar(),
                   issueDate)
        {
            frequency_    = schedule.tenor().frequency();
            dayCounter_   = accrualDayCounter;
            maturityDate_ = schedule.endDate();

            cashflows_ = new FixedRateLeg(schedule)
                         .withCouponRates(coupons, accrualDayCounter)
                         .withExCouponPeriod(exCouponPeriod,
                                             exCouponCalendar,
                                             exCouponConvention,
                                             exCouponEndOfMonth)
                         .withPaymentCalendar(calendar_)
                         .withNotionals(faceAmount)
                         .withPaymentAdjustment(paymentConvention);

            addRedemptionsToCashflows(new List <double>()
            {
                redemption
            });

            Utils.QL_REQUIRE(cashflows().Count != 0, () => "bond with no cashflows!");
            Utils.QL_REQUIRE(redemptions_.Count == 1, () => "multiple redemptions created");
        }
        public AmortizingFixedRateBond(
            int settlementDays,
            Calendar calendar,
            double faceAmount,
            Date startDate,
            Period bondTenor,
            Frequency sinkingFrequency,
            double coupon,
            DayCounter accrualDayCounter,
            BusinessDayConvention paymentConvention = BusinessDayConvention.Following,
            Date issueDate = null)
            : base(settlementDays, calendar, issueDate)
        {
            frequency_  = sinkingFrequency;
            dayCounter_ = accrualDayCounter;

            Utils.QL_REQUIRE(bondTenor.length() > 0, () =>
                             "bond tenor must be positive. "
                             + bondTenor + " is not allowed.");

            maturityDate_ = startDate + bondTenor;
            schedule_     = sinkingSchedule(startDate, bondTenor, sinkingFrequency, calendar);
            cashflows_    = new FixedRateLeg(schedule_)
                            .withCouponRates(coupon, accrualDayCounter)
                            .withNotionals(sinkingNotionals(bondTenor, sinkingFrequency, coupon, faceAmount))
                            .withPaymentAdjustment(paymentConvention).value();

            addRedemptionsToCashflows();
        }
        public AmortizingFixedRateBond(
            int settlementDays,
            List <double> notionals,
            Schedule schedule,
            List <InterestRate> coupons,
            DayCounter accrualDayCounter,
            BusinessDayConvention paymentConvention = BusinessDayConvention.Following,
            Date issueDate = null)
            : base(settlementDays, schedule.calendar(), issueDate)
        {
            frequency_  = schedule.tenor().frequency();
            dayCounter_ = accrualDayCounter;
            schedule_   = schedule;

            maturityDate_ = schedule.endDate();

            cashflows_ = new FixedRateLeg(schedule)
                         .withCouponRates(coupons)
                         .withNotionals(notionals)
                         .withPaymentAdjustment(paymentConvention).value();


            addRedemptionsToCashflows();

            Utils.QL_REQUIRE(!cashflows().empty(), () => "bond with no cashflows!");
        }
Example #5
0
        private double calculateYield()
        {
            // We create a bond cashflow from issue to maturity just
            // to calculate effective rate ( the rate that discount _marketValue )
            Schedule schedule = new Schedule(_issueDate, _maturityDate, new Period(_payFrequency),
                                             _calendar, BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted,
                                             DateGeneration.Rule.Backward, false);


            List <CashFlow> cashflows = new FixedRateLeg(schedule)
                                        .withCouponRates(_couponRate, _dCounter)
                                        .withPaymentCalendar(_calendar)
                                        .withNotionals(_faceValue)
                                        .withPaymentAdjustment(BusinessDayConvention.Unadjusted);

            // Add single redemption for yield calculation
            Redemption r = new Redemption(_faceValue, _maturityDate);

            cashflows.Add(r);

            // Calculate Amortizing Yield ( Effective Rate )
            Date testDate = CashFlows.previousCashFlowDate(cashflows, false, _tradeDate);

            return(CashFlows.yield(cashflows, _marketValue, _dCounter, Compounding.Simple, _payFrequency,
                                   false, testDate));
        }
Example #6
0
        // constructor
        public VanillaSwap(Type type, double nominal,
                           Schedule fixedSchedule, double fixedRate, DayCounter fixedDayCount,
                           Schedule floatSchedule, IborIndex iborIndex, double spread, DayCounter floatingDayCount,
                           BusinessDayConvention?paymentConvention = null) :
            base(2)
        {
            type_             = type;
            nominal_          = nominal;
            fixedSchedule_    = fixedSchedule;
            fixedRate_        = fixedRate;
            fixedDayCount_    = fixedDayCount;
            floatingSchedule_ = floatSchedule;
            iborIndex_        = iborIndex;
            spread_           = spread;
            floatingDayCount_ = floatingDayCount;

            if (paymentConvention.HasValue)
            {
                paymentConvention_ = paymentConvention.Value;
            }
            else
            {
                paymentConvention_ = floatingSchedule_.businessDayConvention();
            }

            legs_[0] = new FixedRateLeg(fixedSchedule)
                       .withCouponRates(fixedRate, fixedDayCount)
                       .withPaymentAdjustment(paymentConvention_)
                       .withNotionals(nominal);

            legs_[1] = new IborLeg(floatSchedule, iborIndex)
                       .withPaymentDayCounter(floatingDayCount)
                       //.withFixingDays(iborIndex.fixingDays())
                       .withSpreads(spread)
                       .withNotionals(nominal)
                       .withPaymentAdjustment(paymentConvention_);

            foreach (var cf in legs_[1])
            {
                cf.registerWith(update);
            }

            switch (type_)
            {
            case Type.Payer:
                payer_[0] = -1.0;
                payer_[1] = +1.0;
                break;

            case Type.Receiver:
                payer_[0] = +1.0;
                payer_[1] = -1.0;
                break;

            default:
                Utils.QL_FAIL("Unknown vanilla-swap type");
                break;
            }
        }
        public OvernightIndexedSwap(Type type,
                                    double fixedNominal,
                                    Schedule fixedSchedule,
                                    double fixedRate,
                                    DayCounter fixedDC,
                                    double overnightNominal,
                                    Schedule overnightSchedule,
                                    OvernightIndex overnightIndex,
                                    double spread) :
            base(2)
        {
            type_                      = type;
            fixedNominal_              = fixedNominal;
            overnightNominal_          = overnightNominal;
            fixedPaymentFrequency_     = fixedSchedule.tenor().frequency();
            overnightPaymentFrequency_ = overnightSchedule.tenor().frequency();
            fixedRate_                 = fixedRate;
            fixedDC_                   = fixedDC;
            overnightIndex_            = overnightIndex;
            spread_                    = spread;

            if (fixedDC_ == null)
            {
                fixedDC_ = overnightIndex_.dayCounter();
            }

            legs_[0] = new FixedRateLeg(fixedSchedule)
                       .withCouponRates(fixedRate_, fixedDC_)
                       .withNotionals(fixedNominal_);

            legs_[1] = new OvernightLeg(overnightSchedule, overnightIndex_)
                       .withNotionals(overnightNominal_)
                       .withSpreads(spread_);

            for (int j = 0; j < 2; ++j)
            {
                for (int i = 0; i < legs_[j].Count; i++)
                {
                    legs_[j][i].registerWith(update);
                }
            }

            switch (type_)
            {
            case Type.Payer:
                payer_[0] = -1.0;
                payer_[1] = +1.0;
                break;

            case Type.Receiver:
                payer_[0] = +1.0;
                payer_[1] = -1.0;
                break;

            default:
                Utils.QL_FAIL("Unknown overnight-swap type");
                break;
            }
        }
Example #8
0
        protected override void performCalculations()
        {
            Period indexTenor = index_.tenor();
            double fixedRate = 0.04; // dummy value
            Date   startDate, maturity;

            if (includeFirstSwaplet_)
            {
                startDate = termStructure_.link.referenceDate();
                maturity  = termStructure_.link.referenceDate() + length_;
            }
            else
            {
                startDate = termStructure_.link.referenceDate() + indexTenor;
                maturity  = termStructure_.link.referenceDate() + length_;
            }
            IborIndex dummyIndex = new IborIndex("dummy",
                                                 indexTenor,
                                                 index_.fixingDays(),
                                                 index_.currency(),
                                                 index_.fixingCalendar(),
                                                 index_.businessDayConvention(),
                                                 index_.endOfMonth(),
                                                 termStructure_.link.dayCounter(),
                                                 termStructure_);

            List <double> nominals = new InitializedList <double>(1, 1.0);

            Schedule floatSchedule = new Schedule(startDate, maturity,
                                                  index_.tenor(), index_.fixingCalendar(),
                                                  index_.businessDayConvention(),
                                                  index_.businessDayConvention(),
                                                  DateGeneration.Rule.Forward, false);
            List <CashFlow> floatingLeg = new IborLeg(floatSchedule, index_)
                                          .withFixingDays(0)
                                          .withNotionals(nominals)
                                          .withPaymentAdjustment(index_.businessDayConvention());

            Schedule fixedSchedule = new Schedule(startDate, maturity, new Period(fixedLegFrequency_),
                                                  index_.fixingCalendar(),
                                                  BusinessDayConvention.Unadjusted, BusinessDayConvention.Unadjusted,
                                                  DateGeneration.Rule.Forward, false);
            List <CashFlow> fixedLeg = new FixedRateLeg(fixedSchedule)
                                       .withCouponRates(fixedRate, fixedLegDayCounter_)
                                       .withNotionals(nominals)
                                       .withPaymentAdjustment(index_.businessDayConvention());

            Swap swap = new Swap(floatingLeg, fixedLeg);

            swap.setPricingEngine(new DiscountingSwapEngine(termStructure_, false));
            double fairRate = fixedRate - (double)(swap.NPV() / (swap.legBPS(1) / 1.0e-4));

            cap_ = new Cap(floatingLeg, new InitializedList <double>(1, fairRate));

            base.performCalculations();
        }
        public YearOnYearInflationSwap(
            Type type,
            double nominal,
            Schedule fixedSchedule,
            double fixedRate,
            DayCounter fixedDayCount,
            Schedule yoySchedule,
            YoYInflationIndex yoyIndex,
            Period observationLag,
            double spread,
            DayCounter yoyDayCount,
            Calendar paymentCalendar, // inflation index does not have a calendar
            BusinessDayConvention paymentConvention = BusinessDayConvention.ModifiedFollowing)
            : base(2)
        {
            type_              = type;
            nominal_           = nominal;
            fixedSchedule_     = fixedSchedule;
            fixedRate_         = fixedRate;
            fixedDayCount_     = fixedDayCount;
            yoySchedule_       = yoySchedule;
            yoyIndex_          = yoyIndex;
            observationLag_    = observationLag;
            spread_            = spread;
            yoyDayCount_       = yoyDayCount;
            paymentCalendar_   = paymentCalendar;
            paymentConvention_ = paymentConvention;

            // N.B. fixed leg gets its calendar from the schedule!
            List <CashFlow> fixedLeg = new FixedRateLeg(fixedSchedule_)
                                       .withCouponRates(fixedRate_, fixedDayCount_) // Simple compounding by default
                                       .withNotionals(nominal_)
                                       .withPaymentAdjustment(paymentConvention_);

            List <CashFlow> yoyLeg = new yoyInflationLeg(yoySchedule_, paymentCalendar_, yoyIndex_, observationLag_)
                                     .withSpreads(spread_)
                                     .withPaymentDayCounter(yoyDayCount_)
                                     .withNotionals(nominal_)
                                     .withPaymentAdjustment(paymentConvention_);

            yoyLeg.ForEach((i, x) => x.registerWith(update));


            legs_[0] = fixedLeg;
            legs_[1] = yoyLeg;
            if (type_ == Type.Payer)
            {
                payer_[0] = -1.0;
                payer_[1] = +1.0;
            }
            else
            {
                payer_[0] = +1.0;
                payer_[1] = -1.0;
            }
        }
        /// <summary>
        /// CDS quoted as running-spread only
        /// </summary>
        /// <param name="side">Whether the protection is bought or sold.</param>
        /// <param name="notional">Notional value</param>
        /// <param name="spread">Running spread in fractional units.</param>
        /// <param name="schedule">Coupon schedule.</param>
        /// <param name="convention">Business-day convention for payment-date adjustment.</param>
        /// <param name="dayCounter">Day-count convention for accrual.</param>
        /// <param name="settlesAccrual">Whether or not the accrued coupon is due in the event of a default.</param>
        /// <param name="paysAtDefaultTime">If set to true, any payments triggered by a default event are
        /// due at default time. If set to false, they are due at the end of the accrual period.</param>
        /// <param name="protectionStart">The first date where a default event will trigger the contract.</param>
        /// <param name="claim"></param>
        /// <param name="lastPeriodDayCounter">Day-count convention for accrual in last period</param>
        /// <param name="rebatesAccrual">The protection seller pays the accrued scheduled current coupon at the start
        /// of the contract. The rebate date is not provided but computed to be two days after protection start.</param>
        public CreditDefaultSwap(Protection.Side side,
                                 double notional,
                                 double spread,
                                 Schedule schedule,
                                 BusinessDayConvention convention,
                                 DayCounter dayCounter,
                                 bool settlesAccrual             = true,
                                 bool paysAtDefaultTime          = true,
                                 Date protectionStart            = null,
                                 Claim claim                     = null,
                                 DayCounter lastPeriodDayCounter = null,
                                 bool rebatesAccrual             = true)
        {
            side_              = side;
            notional_          = notional;
            upfront_           = null;
            runningSpread_     = spread;
            settlesAccrual_    = settlesAccrual;
            paysAtDefaultTime_ = paysAtDefaultTime;
            claim_             = claim;
            protectionStart_   = protectionStart ?? schedule[0];

            Utils.QL_REQUIRE(protectionStart_ <= schedule[0] ||
                             schedule.rule() == DateGeneration.Rule.CDS ||
                             schedule.rule() == DateGeneration.Rule.CDS2015
                             , () => "protection can not start after accrual");

            leg_ = new FixedRateLeg(schedule)
                   .withLastPeriodDayCounter(lastPeriodDayCounter)
                   .withCouponRates(spread, dayCounter)
                   .withNotionals(notional)
                   .withPaymentAdjustment(convention);

            Date effectiveUpfrontDate = schedule.calendar().advance(protectionStart_, 2, TimeUnit.Days, convention);

            // '2' is used above since the protection start is assumed to be on trade_date + 1
            if (rebatesAccrual)
            {
                FixedRateCoupon firstCoupon = leg_[0] as FixedRateCoupon;

                Date rebateDate = effectiveUpfrontDate;
                accrualRebate_ = new SimpleCashFlow(firstCoupon.accruedAmount(protectionStart_), rebateDate);
            }

            upfrontPayment_ = new SimpleCashFlow(0.0, effectiveUpfrontDate);

            if (claim_ == null)
            {
                claim_ = new FaceValueClaim();
            }

            claim_.registerWith(update);
            maturity_ = schedule.dates().Last();
        }
Example #11
0
        public FixedLoan(Type type, double nominal,
                         Schedule fixedSchedule, double fixedRate, DayCounter fixedDayCount,
                         Schedule principalSchedule, BusinessDayConvention?paymentConvention) :
            base(2)
        {
            type_              = type;
            nominal_           = nominal;
            fixedSchedule_     = fixedSchedule;
            fixedRate_         = fixedRate;
            fixedDayCount_     = fixedDayCount;
            principalSchedule_ = principalSchedule;

            if (paymentConvention.HasValue)
            {
                paymentConvention_ = paymentConvention.Value;
            }
            else
            {
                paymentConvention_ = fixedSchedule_.businessDayConvention();
            }

            List <CashFlow> principalLeg = new PricipalLeg(principalSchedule, fixedDayCount)
                                           .withNotionals(nominal)
                                           .withPaymentAdjustment(paymentConvention_)
                                           .withSign(type == Type.Loan ? -1 : 1);

            // temporary
            for (int i = 0; i < principalLeg.Count - 1; i++)
            {
                Principal p = (Principal)principalLeg[i];
                notionals_.Add(p.nominal());
            }

            List <CashFlow> fixedLeg = new FixedRateLeg(fixedSchedule)
                                       .withCouponRates(fixedRate, fixedDayCount)
                                       .withPaymentAdjustment(paymentConvention_)
                                       .withNotionals(notionals_);


            legs_[0] = fixedLeg;
            legs_[1] = principalLeg;
            if (type_ == Type.Loan)
            {
                payer_[0] = +1;
                payer_[1] = -1;
            }
            else
            {
                payer_[0] = -1;
                payer_[1] = +1;
            }
        }
Example #12
0
        public CallableFixedRateBond(int settlementDays,
                                     double faceAmount,
                                     Schedule schedule,
                                     List <double> coupons,
                                     DayCounter accrualDayCounter,
                                     BusinessDayConvention paymentConvention = BusinessDayConvention.Following,
                                     double redemption = 100.0,
                                     Date issueDate    = null,
                                     CallabilitySchedule putCallSchedule = null)
            : base(settlementDays, schedule, accrualDayCounter, issueDate, putCallSchedule)
        {
            frequency_ = schedule.tenor().frequency();

            bool isZeroCouponBond = (coupons.Count == 1 && Utils.close(coupons[0], 0.0));

            if (!isZeroCouponBond)
            {
                cashflows_ = new FixedRateLeg(schedule)
                             .withCouponRates(coupons, accrualDayCounter)
                             .withNotionals(faceAmount)
                             .withPaymentAdjustment(paymentConvention);

                addRedemptionsToCashflows(new List <double>()
                {
                    redemption
                });
            }
            else
            {
                Date redemptionDate = calendar_.adjust(maturityDate_, paymentConvention);
                setSingleRedemption(faceAmount, redemption, redemptionDate);
            }

            // used for impliedVolatility() calculation
            SimpleQuote dummyVolQuote = new SimpleQuote(0.0);

            blackVolQuote_.linkTo(dummyVolQuote);
            blackEngine_ = new BlackCallableFixedRateBondEngine(blackVolQuote_, blackDiscountCurve_);
        }
        /// <summary>
        /// CDS quoted as upfront and running spread
        /// </summary>
        /// <param name="side">Whether the protection is bought or sold.</param>
        /// <param name="notional"> Notional value</param>
        /// <param name="upfront">Upfront in fractional units.</param>
        /// <param name="runningSpread">Running spread in fractional units.</param>
        /// <param name="schedule">Coupon schedule.</param>
        /// <param name="convention">Business-day convention for payment-date adjustment.</param>
        /// <param name="dayCounter">Day-count convention for accrual.</param>
        /// <param name="settlesAccrual">Whether or not the accrued coupon is due in the event of a default.</param>
        /// <param name="paysAtDefaultTime">If set to true, any payments triggered by a default event are
        /// due at default time. If set to false, they are due at the end of the accrual period.</param>
        /// <param name="protectionStart">The first date where a default event will trigger the contract.</param>
        /// <param name="upfrontDate">Settlement date for the upfront payment.</param>
        /// <param name="claim"></param>
        /// <param name="lastPeriodDayCounter">Day-count convention for accrual in last period</param>
        /// <param name="rebatesAccrual">The protection seller pays the accrued scheduled current coupon at the start
        /// of the contract. The rebate date is not provided but computed to be two days after protection start.</param>
        public CreditDefaultSwap(Protection.Side side,
                                 double notional,
                                 double upfront,
                                 double runningSpread,
                                 Schedule schedule,
                                 BusinessDayConvention convention,
                                 DayCounter dayCounter,
                                 bool settlesAccrual             = true,
                                 bool paysAtDefaultTime          = true,
                                 Date protectionStart            = null,
                                 Date upfrontDate                = null,
                                 Claim claim                     = null,
                                 DayCounter lastPeriodDayCounter = null,
                                 bool rebatesAccrual             = true)
        {
            side_              = side;
            notional_          = notional;
            upfront_           = upfront;
            runningSpread_     = runningSpread;
            settlesAccrual_    = settlesAccrual;
            paysAtDefaultTime_ = paysAtDefaultTime;
            claim_             = claim;
            protectionStart_   = protectionStart ?? schedule[0];

            Utils.QL_REQUIRE(protectionStart_ <= schedule[0] ||
                             schedule.rule() == DateGeneration.Rule.CDS
                             , () => "protection can not start after accrual");
            leg_ = new FixedRateLeg(schedule)
                   .withLastPeriodDayCounter(lastPeriodDayCounter)
                   .withCouponRates(runningSpread, dayCounter)
                   .withNotionals(notional)
                   .withPaymentAdjustment(convention);

            // If empty, adjust to T+3 standard settlement, alternatively add
            //  an arbitrary date to the constructor
            Date effectiveUpfrontDate = upfrontDate == null?
                                        schedule.calendar().advance(protectionStart_, 2, TimeUnit.Days, convention) : upfrontDate;

            // '2' is used above since the protection start is assumed to be
            //   on trade_date + 1
            upfrontPayment_ = new SimpleCashFlow(notional * upfront, effectiveUpfrontDate);
            Utils.QL_REQUIRE(effectiveUpfrontDate >= protectionStart_, () => "upfront can not be due before contract start");

            if (rebatesAccrual)
            {
                FixedRateCoupon firstCoupon = leg_[0] as FixedRateCoupon;
                // adjust to T+3 standard settlement, alternatively add
                //  an arbitrary date to the constructor

                Date rebateDate = effectiveUpfrontDate;

                accrualRebate_ = new SimpleCashFlow(firstCoupon.accruedAmount(protectionStart_), rebateDate);
            }

            if (claim_ == null)
            {
                claim_ = new FaceValueClaim();
            }
            claim_.registerWith(update);

            maturity_ = schedule.dates().Last();
        }
Example #14
0
        /*! simple annual compounding coupon rates
         *  with internal schedule calculation */
        public FixedRateBond(int settlementDays,
                             Calendar calendar,
                             double faceAmount,
                             Date startDate,
                             Date maturityDate,
                             Period tenor,
                             List <double> coupons,
                             DayCounter accrualDayCounter,
                             BusinessDayConvention accrualConvention = BusinessDayConvention.Following,
                             BusinessDayConvention paymentConvention = BusinessDayConvention.Following,
                             double redemption         = 100,
                             Date issueDate            = null,
                             Date stubDate             = null,
                             DateGeneration.Rule rule  = DateGeneration.Rule.Backward,
                             bool endOfMonth           = false,
                             Calendar paymentCalendar  = null,
                             Period exCouponPeriod     = null,
                             Calendar exCouponCalendar = null,
                             BusinessDayConvention exCouponConvention = BusinessDayConvention.Unadjusted,
                             bool exCouponEndOfMonth = false)
            : base(settlementDays, paymentCalendar ?? calendar,
                   issueDate)
        {
            frequency_    = tenor.frequency();
            dayCounter_   = accrualDayCounter;
            maturityDate_ = maturityDate;

            Date firstDate = null, nextToLastDate = null;

            switch (rule)
            {
            case DateGeneration.Rule.Backward:
                firstDate      = null;
                nextToLastDate = stubDate;
                break;

            case DateGeneration.Rule.Forward:
                firstDate      = stubDate;
                nextToLastDate = null;
                break;

            case DateGeneration.Rule.Zero:
            case DateGeneration.Rule.ThirdWednesday:
            case DateGeneration.Rule.Twentieth:
            case DateGeneration.Rule.TwentiethIMM:
                Utils.QL_FAIL("stub date (" + stubDate + ") not allowed with " + rule + " DateGeneration::Rule");
                break;

            default:
                Utils.QL_FAIL("unknown DateGeneration::Rule (" + rule + ")");
                break;
            }


            Schedule schedule = new Schedule(startDate, maturityDate_, tenor,
                                             calendar, accrualConvention, accrualConvention,
                                             rule, endOfMonth,
                                             firstDate, nextToLastDate);


            cashflows_ = new FixedRateLeg(schedule)
                         .withCouponRates(coupons, accrualDayCounter)
                         .withExCouponPeriod(exCouponPeriod,
                                             exCouponCalendar,
                                             exCouponConvention,
                                             exCouponEndOfMonth)
                         .withPaymentCalendar(calendar_)
                         .withNotionals(faceAmount)
                         .withPaymentAdjustment(paymentConvention);

            addRedemptionsToCashflows(new List <double>()
            {
                redemption
            });


            Utils.QL_REQUIRE(cashflows().Count != 0, () => "bond with no cashflows!");
            Utils.QL_REQUIRE(redemptions_.Count == 1, () => "multiple redemptions created");
        }
Example #15
0
        public CommercialPaper(Type type, double nominal,
                               Schedule fixedSchedule, double fixedRate, DayCounter fixedDayCount,
                               Schedule principalSchedule, BusinessDayConvention?paymentConvention) :
            base(2)
        {
            type_              = type;
            nominal_           = nominal;
            fixedSchedule_     = fixedSchedule;
            fixedRate_         = fixedRate;
            fixedDayCount_     = fixedDayCount;
            principalSchedule_ = principalSchedule;

            if (paymentConvention.HasValue)
            {
                paymentConvention_ = paymentConvention.Value;
            }
            else
            {
                paymentConvention_ = fixedSchedule_.businessDayConvention();
            }

            List <CashFlow> principalLeg = new PricipalLeg(principalSchedule, fixedDayCount)
                                           .withNotionals(nominal)
                                           .withPaymentAdjustment(paymentConvention_)
                                           .withSign(type == Type.Loan ? -1 : 1);

            // temporary
            for (int i = 0; i < principalLeg.Count - 1; i++)
            {
                Principal p = (Principal)principalLeg[i];
                notionals_.Add(p.nominal());
            }

            List <CashFlow> fixedLeg = new FixedRateLeg(fixedSchedule)
                                       .withCouponRates(fixedRate, fixedDayCount)
                                       .withPaymentAdjustment(paymentConvention_)
                                       .withNotionals(notionals_);

            // Discounting Pricipal
            notionals_.Clear();
            double n;

            for (int i = 0; i < fixedLeg.Count; i++)
            {
                FixedRateCoupon c = (FixedRateCoupon)fixedLeg[i];
                n = i > 0 ? notionals_.Last() : c.nominal();
                notionals_.Add(n / (1 + (c.rate() * c.dayCounter().yearFraction(c.referencePeriodStart, c.referencePeriodEnd))));
            }

            // New Leg
            List <CashFlow> discountedFixedLeg = new FixedRateLeg(fixedSchedule)
                                                 .withCouponRates(fixedRate, fixedDayCount)
                                                 .withPaymentAdjustment(paymentConvention_)
                                                 .withNotionals(notionals_);
            // Adjust Principal
            Principal p0 = (Principal)principalLeg[0];

            p0.setAmount(notionals_.Last());

            legs_[0] = discountedFixedLeg;
            legs_[1] = principalLeg;
            if (type_ == Type.Loan)
            {
                payer_[0] = +1;
                payer_[1] = -1;
            }
            else
            {
                payer_[0] = -1;
                payer_[1] = +1;
            }
        }