Exemplo n.º 1
0
        public void testCatBondInDoomScenario()
        {
            // Testing floating-rate cat bond in a doom scenario (certain default)

            CommonVars vars = new CommonVars();

            Date today = new Date(22, Month.November, 2004);

            Settings.setEvaluationDate(today);

            int settlementDays = 1;

            Handle <YieldTermStructure> riskFreeRate  = new Handle <YieldTermStructure>(Utilities.flatRate(today, 0.025, new Actual360()));
            Handle <YieldTermStructure> discountCurve = new Handle <YieldTermStructure>(Utilities.flatRate(today, 0.03, new Actual360()));

            IborIndex index      = new USDLibor(new Period(6, TimeUnit.Months), riskFreeRate);
            int       fixingDays = 1;

            double tolerance = 1.0e-6;

            IborCouponPricer pricer = new BlackIborCouponPricer(new Handle <OptionletVolatilityStructure>());

            Schedule sch = new Schedule(new Date(30, Month.November, 2004),
                                        new Date(30, Month.November, 2008),
                                        new Period(Frequency.Semiannual),
                                        new UnitedStates(UnitedStates.Market.GovernmentBond),
                                        BusinessDayConvention.ModifiedFollowing, BusinessDayConvention.ModifiedFollowing,
                                        DateGeneration.Rule.Backward, false);

            List <KeyValuePair <Date, double> > events = new List <KeyValuePair <Date, double> >();

            events.Add(new KeyValuePair <Date, double>(new Date(30, Month.November, 2004), 1000));
            CatRisk doomCatRisk = new EventSet(events,
                                               new Date(30, Month.November, 2004), new Date(30, Month.November, 2008));

            EventPaymentOffset paymentOffset = new NoOffset();
            NotionalRisk       notionalRisk  = new DigitalNotionalRisk(paymentOffset, 100);

            FloatingCatBond catBond = new FloatingCatBond(settlementDays, vars.faceAmount, sch,
                                                          index, new ActualActual(ActualActual.Convention.ISMA),
                                                          notionalRisk,
                                                          BusinessDayConvention.ModifiedFollowing, fixingDays,
                                                          new List <double>(), new List <double>(),
                                                          new List <double?>(), new List <double?>(),
                                                          false,
                                                          100.0, new Date(30, Month.November, 2004));

            IPricingEngine catBondEngine = new MonteCarloCatBondEngine(doomCatRisk, discountCurve);

            catBond.setPricingEngine(catBondEngine);
            Utils.setCouponPricer(catBond.cashflows(), pricer);

            double price = catBond.cleanPrice();

            QAssert.AreEqual(0, price);

            double lossProbability       = catBond.lossProbability();
            double exhaustionProbability = catBond.exhaustionProbability();
            double expectedLoss          = catBond.expectedLoss();

            QAssert.AreEqual(1.0, lossProbability, tolerance);
            QAssert.AreEqual(1.0, exhaustionProbability, tolerance);
            QAssert.AreEqual(1.0, expectedLoss, tolerance);
        }
Exemplo n.º 2
0
        public void testCatBondWithDoomOnceInTenYearsProportional()
        {
            // Testing floating-rate cat bond in a doom once in 10 years scenario with proportional notional reduction

            CommonVars vars = new CommonVars();

            Date today = new Date(22, Month.November, 2004);

            Settings.setEvaluationDate(today);

            int settlementDays = 1;

            Handle <YieldTermStructure> riskFreeRate  = new Handle <YieldTermStructure>(Utilities.flatRate(today, 0.025, new Actual360()));
            Handle <YieldTermStructure> discountCurve = new Handle <YieldTermStructure>(Utilities.flatRate(today, 0.03, new Actual360()));

            IborIndex index      = new USDLibor(new Period(6, TimeUnit.Months), riskFreeRate);
            int       fixingDays = 1;

            double tolerance = 1.0e-6;

            IborCouponPricer pricer = new BlackIborCouponPricer(new Handle <OptionletVolatilityStructure>());

            Schedule sch =
                new Schedule(new Date(30, Month.November, 2004),
                             new Date(30, Month.November, 2008),
                             new Period(Frequency.Semiannual),
                             new UnitedStates(UnitedStates.Market.GovernmentBond),
                             BusinessDayConvention.ModifiedFollowing, BusinessDayConvention.ModifiedFollowing,
                             DateGeneration.Rule.Backward, false);

            List <KeyValuePair <Date, double> > events = new List <KeyValuePair <Date, double> >();

            events.Add(new KeyValuePair <Date, double>(new Date(30, Month.November, 2008), 1000));
            CatRisk doomCatRisk = new EventSet(events, new Date(30, Month.November, 2004), new Date(30, Month.November, 2044));

            CatRisk noCatRisk = new EventSet(new List <KeyValuePair <Date, double> > (),
                                             new Date(1, Month.Jan, 2000), new Date(31, Month.Dec, 2010));

            EventPaymentOffset paymentOffset = new NoOffset();
            NotionalRisk       notionalRisk  = new ProportionalNotionalRisk(paymentOffset, 500, 1500);

            FloatingCatBond catBond =
                new FloatingCatBond(settlementDays, vars.faceAmount, sch,
                                    index, new ActualActual(ActualActual.Convention.ISMA),
                                    notionalRisk,
                                    BusinessDayConvention.ModifiedFollowing, fixingDays,
                                    new List <double>(), new List <double>(),
                                    new List <double?>(), new List <double?>(),
                                    false,
                                    100.0, new Date(30, Month.November, 2004));

            IPricingEngine catBondEngine = new MonteCarloCatBondEngine(doomCatRisk, discountCurve);

            catBond.setPricingEngine(catBondEngine);
            Utils.setCouponPricer(catBond.cashflows(), pricer);

            double price                 = catBond.cleanPrice();
            double yield                 = catBond.yield(new ActualActual(ActualActual.Convention.ISMA), Compounding.Simple, Frequency.Annual);
            double lossProbability       = catBond.lossProbability();
            double exhaustionProbability = catBond.exhaustionProbability();
            double expectedLoss          = catBond.expectedLoss();

            QAssert.AreEqual(0.1, lossProbability, tolerance);
            QAssert.AreEqual(0.0, exhaustionProbability, tolerance);
            QAssert.AreEqual(0.05, expectedLoss, tolerance);

            IPricingEngine catBondEngineRF = new MonteCarloCatBondEngine(noCatRisk, discountCurve);

            catBond.setPricingEngine(catBondEngineRF);

            double riskFreePrice           = catBond.cleanPrice();
            double riskFreeYield           = catBond.yield(new ActualActual(ActualActual.Convention.ISMA), Compounding.Simple, Frequency.Annual);
            double riskFreeLossProbability = catBond.lossProbability();
            double riskFreeExpectedLoss    = catBond.expectedLoss();

            QAssert.AreEqual(0.0, riskFreeLossProbability, tolerance);
            QAssert.IsTrue(Math.Abs(riskFreeExpectedLoss) < tolerance);

            QAssert.AreEqual(riskFreePrice * 0.95, price, tolerance);
            QAssert.IsTrue(riskFreeYield < yield);
        }
Exemplo n.º 3
0
        public void testRiskFreeAgainstFloatingRateBond()
        {
            // Testing floating-rate cat bond against risk-free floating-rate bond

            CommonVars vars = new CommonVars();

            Date today = new Date(22, Month.November, 2004);

            Settings.setEvaluationDate(today);

            int settlementDays = 1;

            Handle <YieldTermStructure> riskFreeRate  = new Handle <YieldTermStructure>(Utilities.flatRate(today, 0.025, new Actual360()));
            Handle <YieldTermStructure> discountCurve = new Handle <YieldTermStructure>(Utilities.flatRate(today, 0.03, new Actual360()));

            IborIndex index      = new USDLibor(new Period(6, TimeUnit.Months), riskFreeRate);
            int       fixingDays = 1;

            double tolerance = 1.0e-6;

            IborCouponPricer pricer = new BlackIborCouponPricer(new Handle <OptionletVolatilityStructure>());

            // plain

            Schedule sch = new Schedule(new Date(30, Month.November, 2004),
                                        new Date(30, Month.November, 2008),
                                        new Period(Frequency.Semiannual),
                                        new UnitedStates(UnitedStates.Market.GovernmentBond),
                                        BusinessDayConvention.ModifiedFollowing, BusinessDayConvention.ModifiedFollowing,
                                        DateGeneration.Rule.Backward, false);

            CatRisk noCatRisk = new EventSet(new List <KeyValuePair <Date, double> >(), new Date(1, Month.Jan, 2000), new Date(31, Month.Dec, 2010));

            EventPaymentOffset paymentOffset = new NoOffset();
            NotionalRisk       notionalRisk  = new DigitalNotionalRisk(paymentOffset, 100);

            FloatingRateBond bond1 = new FloatingRateBond(settlementDays, vars.faceAmount, sch,
                                                          index, new ActualActual(ActualActual.Convention.ISMA),
                                                          BusinessDayConvention.ModifiedFollowing, fixingDays,
                                                          new List <double>(), new List <double>(),
                                                          new List <double?>(), new List <double?>(),
                                                          false,
                                                          100.0, new Date(30, Month.November, 2004));

            FloatingCatBond catBond1 = new FloatingCatBond(settlementDays, vars.faceAmount, sch,
                                                           index, new ActualActual(ActualActual.Convention.ISMA),
                                                           notionalRisk,
                                                           BusinessDayConvention.ModifiedFollowing, fixingDays,
                                                           new List <double>(), new List <double>(),
                                                           new List <double?>(), new List <double?>(),
                                                           false,
                                                           100.0, new Date(30, Month.November, 2004));

            IPricingEngine bondEngine = new DiscountingBondEngine(riskFreeRate);

            bond1.setPricingEngine(bondEngine);
            Utils.setCouponPricer(bond1.cashflows(), pricer);

            IPricingEngine catBondEngine = new MonteCarloCatBondEngine(noCatRisk, riskFreeRate);

            catBond1.setPricingEngine(catBondEngine);
            Utils.setCouponPricer(catBond1.cashflows(), pricer);

#if QL_USE_INDEXED_COUPON
            double cachedPrice1 = 99.874645;
#else
            double cachedPrice1 = 99.874646;
#endif


            double price    = bond1.cleanPrice();
            double catPrice = catBond1.cleanPrice();
            if (Math.Abs(price - cachedPrice1) > tolerance || Math.Abs(catPrice - price) > tolerance)
            {
                QAssert.Fail("failed to reproduce floating rate bond price:\n"
                             + "    floating bond: " + price + "\n"
                             + "    catBond bond: " + catPrice + "\n"
                             + "    expected:   " + cachedPrice1 + "\n"
                             + "    error:      " + (catPrice - price));
            }



            // different risk-free and discount curve

            FloatingRateBond bond2 = new FloatingRateBond(settlementDays, vars.faceAmount, sch,
                                                          index, new ActualActual(ActualActual.Convention.ISMA),
                                                          BusinessDayConvention.ModifiedFollowing, fixingDays,
                                                          new List <double>(), new List <double>(),
                                                          new List <double?>(), new List <double?>(),
                                                          false,
                                                          100.0, new Date(30, Month.November, 2004));

            FloatingCatBond catBond2 = new FloatingCatBond(settlementDays, vars.faceAmount, sch,
                                                           index, new ActualActual(ActualActual.Convention.ISMA),
                                                           notionalRisk,
                                                           BusinessDayConvention.ModifiedFollowing, fixingDays,
                                                           new List <double>(), new List <double>(),
                                                           new List <double?>(), new List <double?>(),
                                                           false,
                                                           100.0, new Date(30, Month.November, 2004));

            IPricingEngine bondEngine2 = new DiscountingBondEngine(discountCurve);
            bond2.setPricingEngine(bondEngine2);
            Utils.setCouponPricer(bond2.cashflows(), pricer);

            IPricingEngine catBondEngine2 = new MonteCarloCatBondEngine(noCatRisk, discountCurve);
            catBond2.setPricingEngine(catBondEngine2);
            Utils.setCouponPricer(catBond2.cashflows(), pricer);

#if QL_USE_INDEXED_COUPON
            double cachedPrice2 = 97.955904;
#else
            double cachedPrice2 = 97.955904;
#endif

            price    = bond2.cleanPrice();
            catPrice = catBond2.cleanPrice();
            if (Math.Abs(price - cachedPrice2) > tolerance || Math.Abs(catPrice - price) > tolerance)
            {
                QAssert.Fail("failed to reproduce floating rate bond price:\n"
                             + "    floating bond: " + price + "\n"
                             + "    catBond bond: " + catPrice + "\n"
                             + "    expected:   " + cachedPrice2 + "\n"
                             + "    error:      " + (catPrice - price));
            }

            // varying spread

            List <double> spreads = new InitializedList <double>(4);
            spreads[0] = 0.001;
            spreads[1] = 0.0012;
            spreads[2] = 0.0014;
            spreads[3] = 0.0016;

            FloatingRateBond bond3 = new FloatingRateBond(settlementDays, vars.faceAmount, sch,
                                                          index, new ActualActual(ActualActual.Convention.ISMA),
                                                          BusinessDayConvention.ModifiedFollowing, fixingDays,
                                                          new List <double>(), spreads,
                                                          new List <double?>(), new List <double?>(),
                                                          false,
                                                          100.0, new Date(30, Month.November, 2004));

            FloatingCatBond catBond3 = new FloatingCatBond(settlementDays, vars.faceAmount, sch,
                                                           index, new ActualActual(ActualActual.Convention.ISMA),
                                                           notionalRisk,
                                                           BusinessDayConvention.ModifiedFollowing, fixingDays,
                                                           new List <double>(), spreads,
                                                           new List <double?>(), new List <double?>(),
                                                           false,
                                                           100.0, new Date(30, Month.November, 2004));

            bond3.setPricingEngine(bondEngine2);
            Utils.setCouponPricer(bond3.cashflows(), pricer);

            catBond3.setPricingEngine(catBondEngine2);
            Utils.setCouponPricer(catBond3.cashflows(), pricer);

#if QL_USE_INDEXED_COUPON
            double cachedPrice3 = 98.495458;
#else
            double cachedPrice3 = 98.495459;
#endif

            price    = bond3.cleanPrice();
            catPrice = catBond3.cleanPrice();
            if (Math.Abs(price - cachedPrice3) > tolerance || Math.Abs(catPrice - price) > tolerance)
            {
                QAssert.Fail("failed to reproduce floating rate bond price:\n"
                             + "    floating bond: " + price + "\n"
                             + "    catBond bond: " + catPrice + "\n"
                             + "    expected:   " + cachedPrice2 + "\n"
                             + "    error:      " + (catPrice - price));
            }
        }