Exemple #1
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);
        }
Exemple #2
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);
        }