Ejemplo n.º 1
0
            public double rpv01(PiecewiseconstantHazardRate creditCurve, CdsPriceType cleanOrDirty)
            {
                double pv = 0.0;

                for (int i = 0; i < _nPayments; i++)
                {
                    CdsCoupon c = _cds.getCoupon(i);
                    double    q = Math.Exp(-creditCurve.getRT_(c.getEffEnd()));
                    pv += c.getYearFrac() * _paymentDF[i] * q;
                }

                if (_cds.isPayAccOnDefault())
                {
                    double accPV = 0.0;
                    for (int i = 0; i < _nPayments; i++)
                    {
                        accPV += calculateSinglePeriodAccrualOnDefault(i, creditCurve);
                    }
                    pv += accPV;
                }

                pv /= _valuationDF;

                if (cleanOrDirty == CdsPriceType.CLEAN)
                {
                    pv -= _cds.getAccruedYearFraction();
                }
                return(pv);
            }
Ejemplo n.º 2
0
 //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
 //ORIGINAL LINE: @SuppressWarnings("unused") private CdsCoupon(CdsCoupon other)
 private CdsCoupon(CdsCoupon other)
 {
     _paymentTime = other._paymentTime;
     _yearFrac    = other._yearFrac;
     _effStart    = other._effStart;
     _effEnd      = other._effEnd;
     _ycRatio     = other._ycRatio;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Make a set of CDSCoupon used by <seealso cref="CdsAnalytic"/> given a trade date and the schedule of the accrual periods.
        /// </summary>
        /// <param name="tradeDate"> The trade date </param>
        /// <param name="leg"> schedule of the accrual periods </param>
        /// <param name="protectionFromStartOfDay"> If true the protection is from the start of day and the effective accrual
        ///  start and end dates are one day less. The exception is the  accrual end date which has one day
        ///  added (if  protectionFromStartOfDay = true) in ISDAPremiumLegSchedule to compensate for this, so the
        ///  accrual end date is just the CDS maturity.
        ///  The effect of having protectionFromStartOfDay = true is to add an extra day of protection. </param>
        /// <param name="accrualDCC"> The day count used to compute accrual periods </param>
        /// <param name="curveDCC">  Day count used on curve (NOTE ISDA uses ACT/365 (fixed) and it is not recommended to change this) </param>
        /// <seealso cref= CdsAnalytic </seealso>
        /// <returns> A set of CDSCoupon </returns>
        public static CdsCoupon[] makeCoupons(DateTime tradeDate, IsdaPremiumLegSchedule leg, bool protectionFromStartOfDay, Enums.DayCount accrualDCC, Enums.DayCount curveDCC)
        {
            int n = leg.NumPayments;

            CdsCoupon[] res = new CdsCoupon[n];
            for (int i = 0; i < n; i++)
            {
                DateTime[] dates = leg.getAccPaymentDateTriplet(i);
                res[i] = new CdsCoupon(tradeDate, dates[0], dates[1], dates[2], protectionFromStartOfDay, accrualDCC, curveDCC);
            }
            return(res);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Make a set of CDSCoupon used by <seealso cref="CdsAnalytic"/> given a trade date and a set of <seealso cref="CdsCouponDes"/>.
        /// </summary>
        /// <param name="tradeDate"> The trade date </param>
        /// <param name="couponsDes"> Description of CDS accrual periods with DateTime </param>
        /// <param name="protectionFromStartOfDay"> If true the protection is from the start of day and the effective accrual
        ///  start and end dates are one day less. The exception is the accrual end date which should have one day
        ///  added (if  protectionFromStartOfDay = true) in the CDSCouponDes to compensate for this, so the
        ///  accrual end date is just the CDS maturity.
        ///  The effect of having protectionFromStartOfDay = true is to add an extra day of protection. </param>
        /// <param name="curveDCC"> Day count used on curve (NOTE ISDA uses ACT/365 (fixed) and it is not recommended to change this) </param>
        /// <returns> A set of CDSCoupon </returns>
        public static CdsCoupon[] makeCoupons(DateTime tradeDate, CdsCouponDes[] couponsDes, bool protectionFromStartOfDay, Enums.DayCount curveDCC)
        {
            int n     = couponsDes.Length;
            int count = 0;

            while (DateTime.Compare(tradeDate, couponsDes[count].getPaymentDate()) > 0)
            {
                count++;
            }
            int nCoupons = n - count;

            CdsCoupon[] coupons = new CdsCoupon[nCoupons];
            for (int i = 0; i < nCoupons; i++)
            {
                coupons[i] = new CdsCoupon(tradeDate, couponsDes[i + count], protectionFromStartOfDay, curveDCC);
            }
            return(coupons);
        }
Ejemplo n.º 5
0
        public bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (obj == null)
            {
                return(false);
            }
            if (this.GetType() != obj.GetType())
            {
                return(false);
            }
            CdsCoupon other = (CdsCoupon)obj;

            if (_effEnd != other._effEnd)
            {
                return(false);
            }
            if (_effStart != other._effStart)
            {
                return(false);
            }
            if ((long)_paymentTime != (long)other._paymentTime)
            {
                return(false);
            }
            if ((long)_ycRatio != (long)other._ycRatio)
            {
                return(false);
            }
            if ((long)_yearFrac != (long)other._yearFrac)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 6
0
            public Pricer(
                CDS cds,
                YieldTermStructure yieldCurve,
                double[] creditCurveKnots,
                double fractionalSpread,
                double pointsUpfront)
            {
                _cds           = cds;
                _fracSpread    = fractionalSpread;
                _pointsUpfront = pointsUpfront;

                // protection leg
                _proLegIntPoints = DoublesScheduleGenerator.getIntegrationsPoints(
                    cds.getEffectiveProtectionStart(),
                    cds.getProtectionEnd(),
                    yieldCurve.t.ToArray(),
                    creditCurveKnots);
                _nProPoints = _proLegIntPoints.Length;
                double lgd = cds.getLGD();

                _valuationDF     = Math.Exp(-yieldCurve.getRT_(cds.getCashSettleTime()));
                _lgdDF           = lgd / _valuationDF;
                _proYieldCurveRT = new double[_nProPoints];
                _proDF           = new double[_nProPoints];
                for (int i = 0; i < _nProPoints; i++)
                {
                    _proYieldCurveRT[i] = yieldCurve.getRT_(_proLegIntPoints[i]);
                    _proDF[i]           = Math.Exp(-_proYieldCurveRT[i]);
                }

                // premium leg
                _nPayments = cds.getNumPayments();
                _paymentDF = new double[_nPayments];
                for (int i = 0; i < _nPayments; i++)
                {
                    _paymentDF[i] = Math.Exp(-yieldCurve.getRT_(cds.getCoupon(i).getPaymentTime()));
                }

                if (cds.isPayAccOnDefault())
                {
                    double   tmp = cds.getNumPayments() == 1 ? cds.getEffectiveProtectionStart() : cds.getAccStart();
                    double[] integrationSchedule = DoublesScheduleGenerator.getIntegrationsPoints(
                        tmp, cds.getProtectionEnd(), yieldCurve.t.ToArray(), creditCurveKnots);

                    _accRate          = new double[_nPayments];
                    _offsetAccStart   = new double[_nPayments];
                    _premLegIntPoints = new double[_nPayments][];
                    _premDF           = new double[_nPayments][];
                    _rt     = new double[_nPayments][];
                    _premDt = new double[_nPayments][];
                    for (int i = 0; i < _nPayments; i++)
                    {
                        CdsCoupon c = cds.getCoupon(i);
                        _offsetAccStart[i] = c.getEffStart();
                        double offsetAccEnd = c.getEffEnd();
                        _accRate[i] = c.getYFRatio();
                        double start = Math.Max(_offsetAccStart[i], cds.getEffectiveProtectionStart());
                        if (start >= offsetAccEnd)
                        {
                            continue;
                        }
                        _premLegIntPoints[i] = DoublesScheduleGenerator.truncateSetInclusive(start, offsetAccEnd, integrationSchedule);
                        int n = _premLegIntPoints[i].Length;
                        _rt[i]     = new double[n];
                        _premDF[i] = new double[n];
                        for (int k = 0; k < n; k++)
                        {
                            _rt[i][k]     = yieldCurve.getRT_(_premLegIntPoints[i][k]);
                            _premDF[i][k] = Math.Exp(-_rt[i][k]);
                        }
                        _premDt[i] = new double[n - 1];

                        for (int k = 1; k < n; k++)
                        {
                            double dt = _premLegIntPoints[i][k] - _premLegIntPoints[i][k - 1];
                            _premDt[i][k - 1] = dt;
                        }
                    }
                }
                else
                {
                    _accRate          = null;
                    _offsetAccStart   = null;
                    _premDF           = null;
                    _premDt           = null;
                    _rt               = null;
                    _premLegIntPoints = null;
                }
            }