Beispiel #1
0
 public CmsSpreadCoupon(Date paymentDate, double nominal, Date startDate, Date endDate, uint fixingDays, SwapSpreadIndex index) : this(NQuantLibcPINVOKE.new_CmsSpreadCoupon__SWIG_6(Date.getCPtr(paymentDate), nominal, Date.getCPtr(startDate), Date.getCPtr(endDate), fixingDays, SwapSpreadIndex.getCPtr(index)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(SwapSpreadIndex obj)
 {
     return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr);
 }
Beispiel #3
0
 public CmsSpreadCoupon(Date paymentDate, double nominal, Date startDate, Date endDate, uint fixingDays, SwapSpreadIndex index, double gearing, double spread, Date refPeriodStart, Date refPeriodEnd) : this(NQuantLibcPINVOKE.new_CmsSpreadCoupon__SWIG_2(Date.getCPtr(paymentDate), nominal, Date.getCPtr(startDate), Date.getCPtr(endDate), fixingDays, SwapSpreadIndex.getCPtr(index), gearing, spread, Date.getCPtr(refPeriodStart), Date.getCPtr(refPeriodEnd)), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
 public CappedFlooredCmsSpreadCoupon(Date paymentDate, double nominal, Date startDate, Date endDate, uint fixingDays, SwapSpreadIndex index, double gearing, double spread, double cap) : this(NQuantLibcPINVOKE.new_CappedFlooredCmsSpreadCoupon__SWIG_5(Date.getCPtr(paymentDate), nominal, Date.getCPtr(startDate), Date.getCPtr(endDate), fixingDays, SwapSpreadIndex.getCPtr(index), gearing, spread, cap), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
 public CappedFlooredCmsSpreadCoupon(Date paymentDate, double nominal, Date startDate, Date endDate, uint fixingDays, SwapSpreadIndex index, double gearing, double spread, double cap, double floor, Date refPeriodStart, Date refPeriodEnd, DayCounter dayCounter, bool isInArrears) : this(NQuantLibcPINVOKE.new_CappedFlooredCmsSpreadCoupon__SWIG_0(Date.getCPtr(paymentDate), nominal, Date.getCPtr(startDate), Date.getCPtr(endDate), fixingDays, SwapSpreadIndex.getCPtr(index), gearing, spread, cap, floor, Date.getCPtr(refPeriodStart), Date.getCPtr(refPeriodEnd), DayCounter.getCPtr(dayCounter), isInArrears), true)
 {
     if (NQuantLibcPINVOKE.SWIGPendingException.Pending)
     {
         throw NQuantLibcPINVOKE.SWIGPendingException.Retrieve();
     }
 }
Beispiel #6
0
        public void testFixings()
        {
            TestData d = new TestData();

            SwapIndex       cms10y   = new EuriborSwapIsdaFixA(new Period(10, TimeUnit.Years), d.yts2, d.yts2);
            SwapIndex       cms2y    = new EuriborSwapIsdaFixA(new Period(2, TimeUnit.Years), d.yts2, d.yts2);
            SwapSpreadIndex cms10y2y = new SwapSpreadIndex("cms10y2y", cms10y, cms2y);

            Settings.Instance.enforcesTodaysHistoricFixings = false;

            try
            {
                cms10y2y.fixing(d.refDate - 1);
                QAssert.Fail("fixing on refDate did not throwed an error.");
            }
            catch
            {
            }

            try
            {
                cms10y2y.fixing(d.refDate);
            }
            catch
            {
                QAssert.Fail("fixing on refDate throwed an error.");
            }

            QAssert.IsTrue(cms10y2y.fixing(d.refDate) ==
                           cms10y.fixing(d.refDate) - cms2y.fixing(d.refDate));
            cms10y.addFixing(d.refDate, 0.05);
            QAssert.IsTrue(cms10y2y.fixing(d.refDate) ==
                           cms10y.fixing(d.refDate) - cms2y.fixing(d.refDate));
            cms2y.addFixing(d.refDate, 0.04);
            QAssert.IsTrue(cms10y2y.fixing(d.refDate) ==
                           cms10y.fixing(d.refDate) - cms2y.fixing(d.refDate));
            Date futureFixingDate = new TARGET().adjust(d.refDate + new Period(1, TimeUnit.Years));

            QAssert.IsTrue(cms10y2y.fixing(futureFixingDate) ==
                           cms10y.fixing(futureFixingDate) -
                           cms2y.fixing(futureFixingDate));
            IndexManager.Instance.clearHistories();

            Settings.Instance.enforcesTodaysHistoricFixings = true;
            try
            {
                cms10y2y.fixing(d.refDate);
                QAssert.Fail("fixing on refDate did not throwed an error.");
            }
            catch
            {
            }

            cms10y.addFixing(d.refDate, 0.05);

            try
            {
                cms10y2y.fixing(d.refDate);
                QAssert.Fail("fixing on refDate did not throwed an error.");
            }
            catch
            {
            }
            cms2y.addFixing(d.refDate, 0.04);

            QAssert.IsTrue(cms10y2y.fixing(d.refDate) ==
                           cms10y.fixing(d.refDate) - cms2y.fixing(d.refDate));
            IndexManager.Instance.clearHistories();
        }
Beispiel #7
0
        public void testCouponPricing()
        {
            TestData d   = new TestData();
            double   tol = 1E-6; // abs tolerance coupon rate

            SwapIndex       cms10y   = new EuriborSwapIsdaFixA(new Period(10, TimeUnit.Years), d.yts2, d.yts2);
            SwapIndex       cms2y    = new EuriborSwapIsdaFixA(new Period(2, TimeUnit.Years), d.yts2, d.yts2);
            SwapSpreadIndex cms10y2y = new SwapSpreadIndex("cms10y2y", cms10y, cms2y);

            Date      valueDate = cms10y2y.valueDate(d.refDate);
            Date      payDate   = valueDate + new Period(1, TimeUnit.Years);
            CmsCoupon cpn1a     = new CmsCoupon(10000.0, payDate, valueDate, payDate, cms10y.fixingDays(), cms10y,
                                                1.0, 0.0, null, null, new Actual360(), false);
            CmsCoupon cpn1b = new CmsCoupon(10000.0, payDate, valueDate, payDate, cms2y.fixingDays(),
                                            cms2y, 1.0, 0.0, null, null, new Actual360(), false);
            CmsSpreadCoupon cpn1 = new CmsSpreadCoupon(
                10000.0, payDate, valueDate, payDate, cms10y2y.fixingDays(),
                cms10y2y, 1.0, 0.0, null, null, new Actual360(), false);

            QAssert.IsTrue(cpn1.fixingDate() == d.refDate);
            cpn1a.setPricer(d.cmsPricerLn);
            cpn1b.setPricer(d.cmsPricerLn);
            cpn1.setPricer(d.cmsspPricerLn);
            QAssert.IsTrue(cpn1.rate() == cpn1a.rate() - cpn1b.rate());
            cms10y.addFixing(d.refDate, 0.05);
            QAssert.IsTrue(cpn1.rate() == cpn1a.rate() - cpn1b.rate());
            cms2y.addFixing(d.refDate, 0.03);
            QAssert.IsTrue(cpn1.rate() == cpn1a.rate() - cpn1b.rate());
            IndexManager.Instance.clearHistories();

            CmsCoupon cpn2a = new CmsCoupon(10000.0, new Date(23, Month.February, 2029),
                                            new Date(23, Month.February, 2028), new Date(23, Month.February, 2029), 2,
                                            cms10y, 1.0, 0.0, null, null, new Actual360(), false);
            CmsCoupon cpn2b = new CmsCoupon(10000.0, new Date(23, Month.February, 2029),
                                            new Date(23, Month.February, 2028), new Date(23, Month.February, 2029), 2,
                                            cms2y, 1.0, 0.0, null, null, new Actual360(), false);

            CappedFlooredCmsSpreadCoupon plainCpn =
                new CappedFlooredCmsSpreadCoupon(
                    new Date(23, Month.February, 2029), 10000.0, new Date(23, Month.February, 2028),
                    new Date(23, Month.February, 2029), 2, cms10y2y, 1.0, 0.0, null,
                    null, null, null, new Actual360(), false);
            CappedFlooredCmsSpreadCoupon cappedCpn =
                new CappedFlooredCmsSpreadCoupon(
                    new Date(23, Month.February, 2029), 10000.0, new Date(23, Month.February, 2028),
                    new Date(23, Month.February, 2029), 2, cms10y2y, 1.0, 0.0, 0.03,
                    null, null, null, new Actual360(), false);
            CappedFlooredCmsSpreadCoupon flooredCpn =
                new CappedFlooredCmsSpreadCoupon(
                    new Date(23, Month.February, 2029), 10000.0, new Date(23, Month.February, 2028),
                    new Date(23, Month.February, 2029), 2, cms10y2y, 1.0, 0.0, null,
                    0.01, null, null, new Actual360(), false);
            CappedFlooredCmsSpreadCoupon collaredCpn =
                new CappedFlooredCmsSpreadCoupon(
                    new Date(23, Month.February, 2029), 10000.0, new Date(23, Month.February, 2028),
                    new Date(23, Month.February, 2029), 2, cms10y2y, 1.0, 0.0, 0.03, 0.01,
                    null, null, new Actual360(), false);

            cpn2a.setPricer(d.cmsPricerLn);
            cpn2b.setPricer(d.cmsPricerLn);
            plainCpn.setPricer(d.cmsspPricerLn);
            cappedCpn.setPricer(d.cmsspPricerLn);
            flooredCpn.setPricer(d.cmsspPricerLn);
            collaredCpn.setPricer(d.cmsspPricerLn);

            QAssert.IsTrue(
                Math.Abs(plainCpn.rate() - mcReferenceValue(cpn2a, cpn2b, Double.MaxValue,
                                                            -Double.MaxValue, d.swLn,
                                                            d.correlation.currentLink().value())) <
                tol);
            QAssert.IsTrue(
                Math.Abs(cappedCpn.rate() - mcReferenceValue(cpn2a, cpn2b, 0.03,
                                                             -Double.MaxValue, d.swLn,
                                                             d.correlation.currentLink().value())) <
                tol);
            QAssert.IsTrue(
                Math.Abs(flooredCpn.rate() -
                         mcReferenceValue(cpn2a, cpn2b, Double.MaxValue, 0.01, d.swLn,
                                          d.correlation.currentLink().value())) <

                tol);
            QAssert.IsTrue(
                Math.Abs(collaredCpn.rate() -
                         mcReferenceValue(cpn2a, cpn2b, 0.03, 0.01, d.swLn,
                                          d.correlation.currentLink().value())) <
                tol);

            cpn2a.setPricer(d.cmsPricerSln);
            cpn2b.setPricer(d.cmsPricerSln);
            plainCpn.setPricer(d.cmsspPricerSln);
            cappedCpn.setPricer(d.cmsspPricerSln);
            flooredCpn.setPricer(d.cmsspPricerSln);
            collaredCpn.setPricer(d.cmsspPricerSln);

            QAssert.IsTrue(
                Math.Abs(plainCpn.rate() - mcReferenceValue(cpn2a, cpn2b, Double.MaxValue,
                                                            -Double.MaxValue, d.swSln,
                                                            d.correlation.currentLink().value())) <
                tol);
            QAssert.IsTrue(
                Math.Abs(cappedCpn.rate() - mcReferenceValue(cpn2a, cpn2b, 0.03,
                                                             -Double.MaxValue, d.swSln,
                                                             d.correlation.currentLink().value())) <
                tol);
            QAssert.IsTrue(
                Math.Abs(flooredCpn.rate() -
                         mcReferenceValue(cpn2a, cpn2b, Double.MaxValue, 0.01, d.swSln,
                                          d.correlation.currentLink().value())) <

                tol);
            QAssert.IsTrue(
                Math.Abs(collaredCpn.rate() -
                         mcReferenceValue(cpn2a, cpn2b, 0.03, 0.01, d.swSln,
                                          d.correlation.currentLink().value())) <
                tol);

            cpn2a.setPricer(d.cmsPricerN);
            cpn2b.setPricer(d.cmsPricerN);
            plainCpn.setPricer(d.cmsspPricerN);
            cappedCpn.setPricer(d.cmsspPricerN);
            flooredCpn.setPricer(d.cmsspPricerN);
            collaredCpn.setPricer(d.cmsspPricerN);

            QAssert.IsTrue(
                Math.Abs(plainCpn.rate() - mcReferenceValue(cpn2a, cpn2b, Double.MaxValue,
                                                            -Double.MaxValue, d.swN,
                                                            d.correlation.currentLink().value())) <
                tol);
            QAssert.IsTrue(
                Math.Abs(cappedCpn.rate() - mcReferenceValue(cpn2a, cpn2b, 0.03,
                                                             -Double.MaxValue, d.swN,
                                                             d.correlation.currentLink().value())) <
                tol);
            QAssert.IsTrue(Math.Abs(flooredCpn.rate() -
                                    mcReferenceValue(cpn2a, cpn2b, Double.MaxValue, 0.01,
                                                     d.swN, d.correlation.currentLink().value())) <

                           tol);
            QAssert.IsTrue(Math.Abs(collaredCpn.rate() -
                                    mcReferenceValue(cpn2a, cpn2b, 0.03, 0.01, d.swN,
                                                     d.correlation.currentLink().value())) <
                           tol);
        }