示例#1
0
        public void testAccessViolation()
        {
            // Testing dynamic cast of coupon in Black pricer...

            SavedSettings backup = new SavedSettings();

            Date todaysDate = new Date(7, Month.April, 2010);
            Date settlementDate = new Date(9, Month.April, 2010);
            Settings.setEvaluationDate(todaysDate);
            Calendar calendar = new TARGET();

            Handle<YieldTermStructure> rhTermStructure = new Handle<YieldTermStructure>(
                Utilities.flatRate(settlementDate, 0.04875825, new Actual365Fixed()));

            double volatility = 0.10;
            Handle<OptionletVolatilityStructure> vol= new Handle<OptionletVolatilityStructure>(
                new ConstantOptionletVolatility(2,
                                                       calendar,
                                                       BusinessDayConvention.ModifiedFollowing,
                                                       volatility,
                                                       new Actual365Fixed()));

            IborIndex index3m =new USDLibor(new Period(3,TimeUnit.Months), rhTermStructure);

            Date payDate = new Date(20, Month.December, 2013);
            Date startDate = new Date(20, Month.September, 2013);
            Date endDate = new Date(20, Month.December, 2013);
            double spread = 0.0115;
            IborCouponPricer pricer = new BlackIborCouponPricer(vol);
            FloatingRateCoupon coupon = new FloatingRateCoupon(100,payDate, startDate, endDate, 2,
                                                index3m, 1.0 , spread / 100);
            coupon.setPricer(pricer);

            try
            {
                // this caused an access violation in version 1.0
                coupon.amount();
            }
            catch (Exception )
            {
                // ok; proper exception thrown
            }
        }
 public override void setPricer(FloatingRateCouponPricer pricer)
 {
     base.setPricer(pricer);
     underlying_.setPricer(pricer);
 }
示例#3
0
 public void visit(FloatingRateCoupon c)
 {
     c.setPricer(pricer_);
 }