Example #1
0
        //! \name ructors
        //@{
        //! CDS quoted as running-spread only

        /*! @param side  Whether the protection is bought or sold.
         *  @param notional  Notional value
         *  @param spread  Running spread in fractional units.
         *  @param schedule  Coupon schedule.
         *  @param paymentConvention  Business-day convention for
         *                            payment-date adjustment.
         *  @param dayCounter  Day-count convention for accrual.
         *  @param settlesAccrual  Whether or not the accrued coupon is
         *                         due in the event of a default.
         *  @param 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 protectionStart  The first date where a default
         *                          event will trigger the contract.
         */
        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)
        {
            side_              = side;
            notional_          = notional;
            upfront_           = null;
            runningSpread_     = spread;
            settlesAccrual_    = settlesAccrual;
            paysAtDefaultTime_ = paysAtDefaultTime;
            claim_             = claim;
            protectionStart_   = protectionStart ?? schedule[0];

            Utils.QL_REQUIRE(protectionStart_ <= schedule[0], () => "protection can not start after accrual");
            leg_ = new FixedRateLeg(schedule)
                   .withCouponRates(spread, dayCounter)
                   .withNotionals(notional)
                   .withPaymentAdjustment(convention);

            upfrontPayment_ = new SimpleCashFlow(0.0, schedule[0]);

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

            claim_.registerWith(update);
        }
Example #2
0
 public CreditDefaultSwap(Protection.Side side, double notional, double upfront, double spread, Schedule schedule, BusinessDayConvention paymentConvention, DayCounter dayCounter) : this(NQuantLibcPINVOKE.new_CreditDefaultSwap__SWIG_5((int)side, notional, upfront, spread, Schedule.getCPtr(schedule), (int)paymentConvention, DayCounter.getCPtr(dayCounter)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Example #3
0
 public CreditDefaultSwap(Protection.Side side, double notional, double spread, Schedule schedule, BusinessDayConvention paymentConvention, DayCounter dayCounter, bool settlesAccrual, bool paysAtDefaultTime) : this(NQuantLibcPINVOKE.new_CreditDefaultSwap__SWIG_0((int)side, notional, spread, Schedule.getCPtr(schedule), (int)paymentConvention, DayCounter.getCPtr(dayCounter), settlesAccrual, paysAtDefaultTime), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
 public CreditDefaultSwap(Protection.Side side, double notional, double upfront, double spread, Schedule schedule, BusinessDayConvention paymentConvention, DayCounter dayCounter, bool settlesAccrual, bool paysAtDefaultTime, Date protectionStart, Date upfrontDate, Claim claim, DayCounter lastPeriodDayCounter) : this(NQuantLibcPINVOKE.new_CreditDefaultSwap__SWIG_5((int)side, notional, upfront, spread, Schedule.getCPtr(schedule), (int)paymentConvention, DayCounter.getCPtr(dayCounter), settlesAccrual, paysAtDefaultTime, Date.getCPtr(protectionStart), Date.getCPtr(upfrontDate), Claim.getCPtr(claim), DayCounter.getCPtr(lastPeriodDayCounter)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Example #5
0
 public Protection.Side side()
 {
     Protection.Side ret = (Protection.Side)NQuantLibcPINVOKE.CreditDefaultSwap_side(swigCPtr);
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
     return(ret);
 }
        /// <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 #7
0
        public MakeCreditDefaultSwap(Period cdsTenor, double cdsSpread)
        {
            cdsTenor_     = cdsTenor;
            cdsSpread_    = cdsSpread;
            recoveryRate_ = 0.4;

            cdsCalendar_ = new NullCalendar();
            nominal_     = 100.0;
            side_        = Protection.Side.Buyer;

            cdsConvention_ = BusinessDayConvention.ModifiedFollowing;
            cdsRule_       = DateGeneration.Rule.Backward;
            cdsDayCount_   = new  Actual365Fixed();
        }
        /// <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 #9
0
 public MakeCreditDefaultSwap withSide(Protection.Side side)
 {
     side_ = side;
     return(this);
 }
Example #10
0
 public MakeCreditDefaultSwap withType(Protection.Side type)
 {
     side_ = type;
     return(this);
 }