Package org.jquantlib.testsuite.util

Examples of org.jquantlib.testsuite.util.Flag


        QL.info("Testing notification of date handles...");

        final Date me1 = Date.todaysDate();
        final RelinkableHandle<Date> h = new RelinkableHandle<Date>(me1);

        final Flag f = new Flag();
        h.addObserver(f);

        final Date weekAgo = Date.todaysDate().sub(7);
        final Date me2 = weekAgo;

        h.linkTo(me2);
        if (!f.isUp()) {
            fail("Observer was not notified of date change");
        }

        if (h.currentLink() != weekAgo) {
            fail("Failed to hard link to another object");
View Full Code Here


        QL.info("Testing notification of date handles using operation Date#subAssign().");

        final Date me1 = Date.todaysDate();
        final RelinkableHandle<Date> h = new RelinkableHandle<Date>(me1);

        final Flag f = new Flag();
        h.addObserver(f);

        me1.subAssign(1);
        if (!f.isUp()) {
            fail("Observer was not notified of date change");
        }
    }
View Full Code Here

        QL.info("Testing ntification of date handles using operation Date#sub().");

        final Date me1 = Date.todaysDate();
        final RelinkableHandle<Date> h = new RelinkableHandle<Date>(me1);

        final Flag f = new Flag();
        h.addObserver(f);

        me1.sub(1);
        if (f.isUp()) {
            fail("Observer was notified of date change whilst it was not expected");
        }
    }
View Full Code Here

                      Discount.class, LogLinear.class, IterativeBootstrap.class,
                      vars.settlementDays,
                      vars.calendar,
                          vars.instruments,
                          new Actual360());
      final Flag f = new Flag();
      vars.termStructure.addObserver(f);

      for (int i=0; i<vars.deposits+vars.swaps; i++) {
          /*@Time*/ final double testTime = new Actual360().yearFraction(vars.settlement, vars.instruments[i].latestDate());
          /*@DiscountFactor*/ final double discount = vars.termStructure.discount(testTime);
          f.lower();
          vars.rates[i].setValue(vars.rates[i].value()*1.01);
          if (!f.isUp())
              throw new RuntimeException("Observer was not notified of underlying rate change");
          if (vars.termStructure.discount(testTime,true) == discount)
            throw new RuntimeException("rate change did not trigger recalculation");
          vars.rates[i].setValue(vars.rates[i].value()/1.01);
      }

      f.lower();
      new Settings().setEvaluationDate(vars.calendar.advance(vars.today, 15, TimeUnit.Days));
      if (!f.isUp())
        throw new RuntimeException("Observer was not notified of date change");
  }
View Full Code Here

                          "    estimated rate: ", estimatedRate, "\n",
                          "    expected rate:  ", expectedRate));
          }
      }

      final Flag f = new Flag();
      vars.termStructure.addObserver(f);
      f.lower();

      index.addFixing(vars.today, 0.0425);

      if (!f.isUp())
          throw new RuntimeException("Observer was not notified of rate fixing");

      for (int i=0; i<vars.swaps; i++) {
          final Period tenor = new Period(swapData[i].n, swapData[i].units);
View Full Code Here

                    }
                } );

        final YieldTermStructure implied = new ImpliedTermStructure<YieldTermStructure>(h, newSettlement);

        final Flag flag = new Flag();
        implied.addObserver(flag);

        // TODO: initialization needed (dependent of PiecewiseYieldCurve)
        // h.setLink(termStructure);

        // -------------------------------------------------------------------------------------------------------------
        // FIXME: This code was added instead. Please remove when PiecewiseYieldCurve becomes ready
        //
        final Quote quote = new SimpleQuote(100.0);
        final Flag anotherFlag = new Flag();
        quote.addObserver(anotherFlag);
        h.linkTo(new FlatForward(today, new Handle<Quote>(quote), new Actual360()));
        if (!anotherFlag.isUp()) {
            fail("Observer was not notified of term structure change");
        }

        if (!flag.isUp()) {
            fail("Observer was not notified of term structure change");
View Full Code Here

  public void testObservable() {

      QL.info("Testing observability of quotes...");

      final SimpleQuote me = new SimpleQuote(0.0);
      final Flag f = new Flag();
      me.addObserver(f);
      me.setValue(3.14);
      if (!f.isUp()) {
            fail("Observer was not notified of quote change");
        }
  }
View Full Code Here

    QL.info("Testing observability of quote handles...");

      final SimpleQuote me1 = new SimpleQuote(0.0);
      final RelinkableHandle<Quote> h = new RelinkableHandle(me1);

      final Flag f = new Flag();
      h.addObserver(f);

      me1.setValue(3.14);
      if (!f.isUp()) {
            fail("Observer was not notified of quote change");
        }

      f.lower();
      final SimpleQuote me2 = new SimpleQuote(0.0);

      h.linkTo(me2);
      if (!f.isUp()) {
            fail("Observer was not notified of quote change");
        }
  }
View Full Code Here

        // define Stock
        final RelinkableHandle<Quote> h = new RelinkableHandle<Quote>(new SimpleQuote(iniPrice));
        final Instrument s = new Stock(h);

        // attach an Observer to Stock
        final Flag priceChange = new Flag();
        s.addObserver(priceChange);

        // verify initial price
        if (iniPrice != s.NPV()) {
            fail("stock quote valuation failed");
        }

        // set a new price
        h.linkTo(new SimpleQuote(newPrice));

        // Observer must detect price change
        if (!priceChange.isUp()) {
            fail("Observer was not notified of instrument change");
        }

        if (newPrice != s.NPV()) {
            fail("stock quote havent changed value");
View Full Code Here

        final SimpleQuote me1 = new SimpleQuote(0.0);
        final RelinkableHandle<Quote>  h = new RelinkableHandle<Quote>(me1);
        final Instrument s = new Stock(h);

        final Flag f = new Flag();
        s.addObserver(f); //f.registerWith(s);

        s.NPV();
        me1.setValue(3.14);
        if (!f.isUp()) {
            fail("Observer was not notified of instrument change");
        }

        s.NPV();
        f.lower();
        final SimpleQuote me2 = new SimpleQuote(0.0);

        h.linkTo(me2);
        if (!f.isUp()) {
            fail("Observer was not notified of instrument change");
        }

        f.lower();
        s.freeze();
        s.NPV();
        me2.setValue(2.71);
        if (f.isUp()) {
            fail("Observer was notified of frozen instrument change");
        }

        s.NPV();
        s.unfreeze();
        if (!f.isUp()) {
            fail("Observer was not notified of instrument change");
        }
    }
View Full Code Here

TOP

Related Classes of org.jquantlib.testsuite.util.Flag

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.