Ejemplo n.º 1
0
        public CDS(double Coupon, double notional, DateTime maturity, DateTime firstpaymentday, DateTime tradedate,
                   DateTime formerpaymentday, string frequency, double recovery, int settlement, int Cashsettlement)
        {
            //  Product Setup
            OMLib.Conventions.DayCount.Actual360 AccuralDCC = new OMLib.Conventions.DayCount.Actual360();
            OMLib.Conventions.DayCount.Actual365 curveDCC   = new OMLib.Conventions.DayCount.Actual365();
            Calendar calendar = new UnitedStates();

            formerpaymentday = calendar.adjust(formerpaymentday, BusinessDayConvention.Following);
            int accrued = AccuralDCC.DayCount(formerpaymentday, calendar.adjust(tradedate, BusinessDayConvention.Following)) + 1;

            this.accruedday       = accrued;
            this.marketvalue      = new double();
            this.accruedamt       = notional * Coupon * accrued / 360;
            this.Notional         = notional;
            this._payAccOnDefault = true;
            OMLib.Conventions.BusinessDayConvention convention = new OMLib.Conventions.BusinessDayConvention(Enums.BusinessDayConvention.ModifiedFollowing, tradedate);
            this.tradedate = calendar.adjust(tradedate, BusinessDayConvention.ModifiedFollowing); /*convention.AdjustedDate;*/

            this.Recovery         = recovery;
            convention            = new OMLib.Conventions.BusinessDayConvention(Enums.BusinessDayConvention.ModifiedFollowing, firstpaymentday);
            this.firstpaymentdate = CdsAnalyticFactory.getNextIMMDate(tradedate);   /*convention.AdjustedDate;*/

            convention             = new OMLib.Conventions.BusinessDayConvention(Enums.BusinessDayConvention.ModifiedFollowing, formerpaymentday);
            this.formerpaymentdate = CdsAnalyticFactory.getPrevIMMDate(tradedate);//calendar.adjust(formerpaymentday,BusinessDayConvention.ModifiedFollowing); /*convention.AdjustedDate;*/
            this.Maturity          = maturity;
            this.PremiumRate       = Coupon;
            this.Frequency         = frequency;
            this.Cashsettlement    = Cashsettlement;
            DateTime valueDate = calendar.adjust(tradedate.AddDays(Cashsettlement));

            convention            = new OMLib.Conventions.BusinessDayConvention(Enums.BusinessDayConvention.ModifiedFollowing, tradedate.AddDays(3));
            this.evalDate         = calendar.adjust(tradedate.AddDays(settlement), BusinessDayConvention.ModifiedFollowing); /*convention.AdjustedDate;*/
            this.Payment_Schedule = PremiumDates(this.Maturity, CdsAnalyticFactory.getNextIMMDate(tradedate), this.Frequency);
            QLNet.Calendar.OrthodoxImpl cal             = new Calendar.OrthodoxImpl();
            IsdaPremiumLegSchedule      paymentSchedule = new IsdaPremiumLegSchedule(formerpaymentdate, maturity, payment_interval, StubConvention.SHORT_INITIAL, QLNet.BusinessDayConvention.ModifiedFollowing, cal, true);

            _coupons = CdsCoupon.makeCoupons(tradedate, paymentSchedule, true, ACT_360, ACT_365);
            OMLib.Conventions.DayCount.Actual365 CurveDCC = new OMLib.Conventions.DayCount.Actual365();

            DateTime effectiveStartDate = tradedate;

            _accStart = DateTime.Compare(formerpaymentdate, tradedate) < 0 ?-CurveDCC.YearFraction(formerpaymentdate, tradedate) :
                        CurveDCC.YearFraction(tradedate, formerpaymentdate);
            _cashSettlementTime       = CurveDCC.YearFraction(tradedate, valueDate);
            _effectiveProtectionStart = DateTime.Compare(effectiveStartDate, tradedate) < 0 ?
                                        -CurveDCC.YearFraction(effectiveStartDate, tradedate) :
                                        CurveDCC.YearFraction(tradedate, effectiveStartDate);
            _protectionEnd = CurveDCC.YearFraction(tradedate, maturity);


            DateTime accStart = paymentSchedule.getAccStartDate(0);
        }
Ejemplo n.º 2
0
        public List <DateTime> PremiumDates(DateTime maturity, DateTime firstpaymentdate, string freqency)
        {
            List <DateTime> date     = new List <DateTime>();
            DateTime        t        = firstpaymentdate;
            Calendar        calendar = new UnitedStates();

            date.Add(t);
            int i = 1;

            do
            {
                switch (freqency)
                {
                case "Monthly":
                    t = firstpaymentdate.AddMonths(i);
                    payment_interval = 1;
                    break;

                case "Quarterly":
                    t = firstpaymentdate.AddMonths(i * 3);
                    payment_interval = 3;
                    break;

                case "Semiyear":
                    t = firstpaymentdate.AddMonths(i * 6);
                    payment_interval = 6;
                    break;

                case "Yearly":
                    t = firstpaymentdate.AddMonths(i * 12);
                    payment_interval = 12;
                    break;

                default:
                    break;
                }
                OMLib.Conventions.BusinessDayConvention convention = new OMLib.Conventions.BusinessDayConvention(Enums.BusinessDayConvention.ModifiedFollowing, t);
                t = calendar.adjust(t, BusinessDayConvention.ModifiedFollowing);

                date.Add(t /*convention.AdjustedDate;*/);
                i++;
            } while (DateTime.Compare(date[i - 1], maturity) < 0);

            return(date);
        }
Ejemplo n.º 3
0
        public List <CashFlow> Calculation(double fixrate, double initialNotional, List <DateTime> fixedSchedule, DateTime tradedate,
                                           YieldTermStructure yt, PiecewiseconstantHazardRate piecewiseFlatHazardRate, int settlement, DateTime lastpaymentdate)
        {
            List <CashFlow> result = new List <CashFlow>();

            OMLib.Conventions.DayCount.Actual360 daycountconvention = new OMLib.Conventions.DayCount.Actual360();
            for (int i = 0; i < fixedSchedule.Count; i++)
            {
                CashFlow cf       = new CashFlow();
                Calendar calendar = new UnitedStates();
                //fixedSchedule[i] = calendar.adjust(fixedSchedule[i], BusinessDayConvention.Following);
                cf.CashFlowDate = fixedSchedule[i];
                if (i == 0)
                {
                    //The protection buyer pays the next coupon in full on the coupon date,
                    //(even if this is the next day); in return the buyer receives (from the protection seller) the accrued
                    //interest[Geoff Chaplin. Credit Derivatives.], which is paid on the cash settlement date.
                    if (lastpaymentdate != null)
                    {
                        lastpaymentdate = calendar.adjust(lastpaymentdate, BusinessDayConvention.Following);
                        cf.Amount       = (double)initialNotional * fixrate * (daycountconvention.DayCount(lastpaymentdate, fixedSchedule[i])) / 360;
                    }
                    else
                    {
                        cf.Amount = (double)initialNotional * fixrate * (daycountconvention.DayCount(tradedate, fixedSchedule[i])) / 360;
                    }
                }
                else
                {
                    //Each coupon is equal to (annual coupon/360) (# of days in accrual period).
                    //The accrual period always stretches from (previous coupon payment date) through (this coupon
                    //payment date–1), inclusive; except a contract's last accrual period, which ends with (and
                    //includes) the unadjusted maturity date.
                    if (i == fixedSchedule.Count - 1)
                    {
                        cf.Amount = (double)initialNotional * fixrate * (daycountconvention.DayCount(fixedSchedule[i - 1], fixedSchedule[i].AddDays(1))) / 360;
                    }
                    else
                    {
                        cf.Amount = (double)initialNotional * fixrate * (daycountconvention.DayCount(fixedSchedule[i - 1], fixedSchedule[i])) / 360;
                    }
                }

                //Assume all cash flows are discounted to the cash settlement date

                cf.DiscountFactor = yt.discount(fixedSchedule[i]);

                if (i == fixedSchedule.Count - 1)
                {
                    cf.Survivalprobability = piecewiseFlatHazardRate.SurvivalProb(fixedSchedule[i].AddDays(1));
                }
                else
                {
                    cf.Survivalprobability = piecewiseFlatHazardRate.SurvivalProb(fixedSchedule[i]);
                }

                result.Add(cf);
            }

            return(result);
        }