Package org.jquantlib.instruments

Examples of org.jquantlib.instruments.Instrument$Results


        final double iniPrice = 3.56;
        final double newPrice = iniPrice*1.0214; // changed +2.14%

        // 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


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


        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.instruments.Instrument$Results

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.