Exemplo n.º 1
0
        public void testFSpreadedObs()
        {
            // ("Testing observability of forward-spreaded term structure...");

             CommonVars vars = new CommonVars();

             SimpleQuote me = new SimpleQuote(0.01);
             Handle<Quote> mh = new Handle<Quote>(me);
             RelinkableHandle<YieldTermStructure> h = new RelinkableHandle<YieldTermStructure>(); //(vars.dummyTermStructure);
             YieldTermStructure spreaded = new ForwardSpreadedTermStructure(h, mh);
             Flag flag = new Flag();
             spreaded.registerWith(flag.update);
             h.linkTo(vars.termStructure);
             if (!flag.isUp())
            Console.WriteLine("Observer was not notified of term structure change");
             flag.lower();
             me.setValue(0.005);
             if (!flag.isUp())
            Console.WriteLine("Observer was not notified of spread change");
        }
Exemplo n.º 2
0
        public void testFSpreaded()
        {
            //("Testing consistency of forward-spreaded term structure...");
             CommonVars vars = new CommonVars();

             double tolerance = 1.0e-10;
             Quote me = new SimpleQuote(0.01);
             Handle<Quote> mh = new Handle<Quote>(me);
             YieldTermStructure spreaded = new ForwardSpreadedTermStructure(new Handle<YieldTermStructure>(vars.termStructure), mh);
             Date testDate = vars.termStructure.referenceDate() + new Period(5, TimeUnit.Years);
             DayCounter tsdc = vars.termStructure.dayCounter();
             DayCounter sprdc = spreaded.dayCounter();
             double forward = vars.termStructure.forwardRate(testDate, testDate, tsdc, Compounding.Continuous,
                                                         Frequency.NoFrequency).rate();
             double spreadedForward = spreaded.forwardRate(testDate, testDate, sprdc, Compounding.Continuous,
                                                         Frequency.NoFrequency).rate();
             if (Math.Abs(forward - (spreadedForward - me.value())) > tolerance)
            Console.WriteLine("unable to reproduce forward from spreaded curve\n"
                + "    calculated: "
                + (spreadedForward - me.value()) + "\n"
                + "    expected:   " + forward);
        }