예제 #1
0
        public void TestCallableBond()
        {
            var bond = new Bond(
                "010001",
                new Date(2012, 05, 03),
                new Date(2017, 05, 03),
                100,
                CurrencyCode.CNY,
                new FixedCoupon(0.068),
                CalendarImpl.Get("chn_ib"),
                Frequency.Annual,
                Stub.LongEnd,
                new ActActIsma(),
                new ActAct(),
                BusinessDayConvention.None,
                BusinessDayConvention.ModifiedFollowing,
                null,
                TradingMarket.ChinaInterBank
                );

            var option = new VanillaOption(new Date(2012, 05, 03),
                                           new Date(2017, 05, 03),
                                           OptionExercise.European,
                                           OptionType.Put,
                                           106.8,
                                           InstrumentType.Bond,
                                           CalendarImpl.Get("chn_ib"),
                                           new Act365(),
                                           CurrencyCode.CNY,
                                           CurrencyCode.CNY,
                                           new[] { new Date(2015, 05, 03) },
                                           new[] { new Date(2015, 05, 03) }
                                           );

            var callableBond = new CallableBond(bond, new[] { option }, new[] { PriceQuoteType.Dirty });
            var market       = TestMarket();
            var engine       = new CallableBondEngine <HullWhite>(new HullWhite(0.1, 0.01), true, 40);
            var result       = engine.Calculate(callableBond, market, PricingRequest.All);

            Assert.AreEqual(107.0198942139, result.Pv, 1e-8);
        }
예제 #2
0
        public void Test101658062_IB()
        {
            var bond = new Bond(
                "101658062.IB",
                new Date(2016, 10, 27),
                new Date(2029, 10, 27),
                100,
                CurrencyCode.CNY,
                new FixedCoupon(0.045),
                CalendarImpl.Get("chn_ib"),
                Frequency.Annual,
                Stub.LongEnd,
                new ActActIsma(),
                new ActAct(),
                BusinessDayConvention.None,
                BusinessDayConvention.ModifiedFollowing,
                null,
                TradingMarket.ChinaInterBank,
                false,
                null,
                null,
                false,
                double.NaN,
                Double.NaN,
                AmortizationType.None,
                null,
                null,
                false,
                new Dictionary <int, double> {
                { 4, 0.03 }
            }
                );

            var options = new List <VanillaOption>();
            var start   = new Date(2016, 10, 27);

            for (var k = 1; k < 16; k++)
            {
                var term     = new Term(k, Period.Year);
                var maturity = term.Next(start);
                if (maturity > bond.UnderlyingMaturityDate)
                {
                    continue;
                    ;
                }
                options.Add(new VanillaOption(start,
                                              maturity,
                                              OptionExercise.European,
                                              OptionType.Call,
                                              100,
                                              InstrumentType.Bond,
                                              CalendarImpl.Get("chn_ib"),
                                              new Act365(),
                                              CurrencyCode.CNY,
                                              CurrencyCode.CNY,
                                              new[] { maturity },
                                              new[] { maturity }
                                              ));
            }

            var callableBond = new CallableBond(bond, options.ToArray(), options.Select(x => PriceQuoteType.Clean).ToArray());
            var valueDates   = new[]
            {
                new Date(2016, 10, 28),
                new Date(2016, 11, 01),
                new Date(2016, 11, 02),
                new Date(2016, 11, 03),
                new Date(2016, 11, 04),
                new Date(2016, 11, 07),
            };

            foreach (var valueDate in valueDates)
            {
                var market = TestMarket2(valueDate);
                var engine = new CallableBondEngine <HullWhite>(new HullWhite(0.5196, 0.03157), true, 3);
                var result = engine.Calculate(callableBond, market, PricingRequest.All);
                Console.WriteLine("{0},{1}", valueDate, result.Pv);
            }
        }