Esempio n. 1
0
        public void testImplied()
        {
            // ("Testing consistency of implied term structure...");

             CommonVars vars = new CommonVars();

             double tolerance = 1.0e-10;
             Date today = Settings.evaluationDate();
             Date newToday = today + new Period(3, TimeUnit.Years);
             Date newSettlement = vars.calendar.advance(newToday, vars.settlementDays, TimeUnit.Days);
             Date testDate = newSettlement + new Period(5, TimeUnit.Years);
             YieldTermStructure implied = new ImpliedTermStructure(new Handle<YieldTermStructure>(vars.termStructure), newSettlement);
             double baseDiscount = vars.termStructure.discount(newSettlement);
             double discount = vars.termStructure.discount(testDate);
             double impliedDiscount = implied.discount(testDate);
             if (Math.Abs(discount - baseDiscount * impliedDiscount) > tolerance)
            Console.WriteLine("unable to reproduce discount from implied curve\n"
                + "    calculated: " + baseDiscount * impliedDiscount + "\n"
                + "    expected:   " + discount);
        }
Esempio n. 2
0
        public void testImpliedObs()
        {
            // ("Testing observability of implied term structure...");

             CommonVars vars = new CommonVars();

             Date today = Settings.evaluationDate();
             Date newToday = today + new Period(3, TimeUnit.Years);
             Date newSettlement = vars.calendar.advance(newToday, vars.settlementDays, TimeUnit.Days);
             RelinkableHandle<YieldTermStructure> h = new RelinkableHandle<YieldTermStructure>();
             YieldTermStructure implied = new ImpliedTermStructure(h, newSettlement);
             Flag flag = new Flag();
             implied.registerWith(flag.update);
             h.linkTo(vars.termStructure);
             if (!flag.isUp())
            Console.WriteLine("Observer was not notified of term structure change");
        }