Package org.jquantlib.quotes

Examples of org.jquantlib.quotes.SimpleQuote


        final DayCounter dc = new Actual360();
        new Settings().setEvaluationDate(Date.todaysDate());
        final Date today = new Settings().evaluationDate();

        final SimpleQuote           spot  = new SimpleQuote(0.0);
        final SimpleQuote           qRate = new SimpleQuote(0.0);
        final YieldTermStructure    qTS   = Utilities.flatRate(qRate, dc);
        final SimpleQuote           rRate = new SimpleQuote(0.0);
        final YieldTermStructure    rTS   = Utilities.flatRate(rRate, dc);
        final SimpleQuote           vol   = new SimpleQuote(0.0);
        final BlackVolTermStructure volTS = Utilities.flatVol(vol, dc);

        final SimpleQuote jumpIntensity = new SimpleQuote(0.0);
        final SimpleQuote meanLogJump   = new SimpleQuote(0.0);
        final SimpleQuote jumpVol       = new SimpleQuote(0.0);

        final Merton76Process stochProcess = new Merton76Process(
                new Handle<Quote>(spot),
                new Handle<YieldTermStructure>(qTS),
                new Handle<YieldTermStructure>(rTS),
                new Handle<BlackVolTermStructure>(volTS),
                new Handle<Quote>(jumpIntensity),
                new Handle<Quote>(meanLogJump),
                new Handle<Quote>(jumpVol));

        // The jumpdiffusionengine greeks are very sensitive to the convergence level.
        // A tolerance of 1.0e-08 is usually sufficient to get reasonable results
        final PricingEngine engine = new JumpDiffusionEngine(stochProcess, 1e-08);

        for (final Type type : types) {
            for (final double strike : strikes) {
                for (final double element : jInt) {
                    jumpIntensity.setValue(element);
                    for (final double element2 : mLJ) {
                        meanLogJump.setValue(element2);
                        for (final double element3 : jV) {
                            jumpVol.setValue(element3);
                            for (final double residualTime : residualTimes) {
                                final Date exDate = today.add((int) (residualTime * 360 + 0.5));
                                final Exercise exercise = new EuropeanExercise(exDate);

                                for (int kk = 0; kk < 1; kk++) {
View Full Code Here


        // 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");
        }
View Full Code Here

  @Test
  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

  @Test
  public void testObservableHandle() {

    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

          final Date dated = today;
          final Date issue = dated;
          final Date maturity = calendar.advance(issue, length, TimeUnit.Years);

          final SimpleQuote rate = new SimpleQuote(0.0);
          final Handle<YieldTermStructure> discountCurve = new Handle<YieldTermStructure>(Utilities.flatRate(today, rate, bondDayCount));

          final Schedule sch = new Schedule(
                  dated, maturity,
              new Period(frequency), calendar,
              accrualConvention, accrualConvention,
              Rule.Backward, false);

          final FixedRateBond bond = new FixedRateBond(
                  settlementDays, faceAmount, sch,
              new double[] { coupon },
              bondDayCount, paymentConvention,
              redemption, issue);

          final PricingEngine bondEngine = new DiscountingBondEngine(discountCurve);
          bond.setPricingEngine(bondEngine);

          for (final double yield : yields) {

            rate.setValue(yield);

            final double price = bond.cleanPrice(yield, bondDayCount, Compounding.Continuous, frequency);
            final double calculatedPrice = bond.cleanPrice();

            if (Math.abs(price-calculatedPrice) > tolerance) {
View Full Code Here

        final Date today = new Settings().evaluationDate();

        final DayCounter dc = new Actual360();

        final SimpleQuote           spot  = new SimpleQuote(0.0);
        final SimpleQuote           qRate = new SimpleQuote(0.0);
        final YieldTermStructure    qTS   = Utilities.flatRate(today, qRate, dc);
        final SimpleQuote           rRate = new SimpleQuote(0.0);
        final YieldTermStructure    rTS   = Utilities.flatRate(today, rRate, dc);
        final SimpleQuote           vol   = new SimpleQuote(0.0);
        final BlackVolTermStructure volTS = Utilities.flatVol(today, vol, dc);

        final double /* @Real */tolerance = 1.0e-4;

        for (final AmericanOptionData value : values) {

            final StrikedTypePayoff payoff = new PlainVanillaPayoff(value.type, value.strike);

            final int daysToExpiry = (int) (value.t * 360 + 0.5);
            final Date exDate = today.clone().addAssign(daysToExpiry);
            final Exercise exercise = new AmericanExercise(today, exDate);

            spot.setValue(value.s);
            qRate.setValue(value.q);
            rRate.setValue(value.r);
            vol.setValue(value.v);

            final BlackScholesMertonProcess stochProcess = new BlackScholesMertonProcess(
                    new Handle<Quote>(spot),
                    new Handle<YieldTermStructure>(qTS),
                    new Handle<YieldTermStructure>(rTS),
View Full Code Here

        final Date today = new Settings().evaluationDate();

        final DayCounter dc = new Actual360();

        final SimpleQuote           spot  = new SimpleQuote(0.0);
        final SimpleQuote           qRate = new SimpleQuote(0.0);
        final YieldTermStructure    qTS   = Utilities.flatRate(today, qRate, dc);
        final SimpleQuote           rRate = new SimpleQuote(0.0);
        final YieldTermStructure    rTS   = Utilities.flatRate(today, rRate, dc);
        final SimpleQuote           vol   = new SimpleQuote(0.0);
        final BlackVolTermStructure volTS = Utilities.flatVol(today, vol, dc);

        final double /* @Real */tolerance = 3.0e-3;

        for (final AmericanOptionData value : values) {
            final StrikedTypePayoff payoff = new PlainVanillaPayoff(value.type, value.strike);
            final Date exDate = today.add(timeToDays(value.t));
            final Exercise exercise = new AmericanExercise(today, exDate);

            spot.setValue(value.s);
            qRate.setValue(value.q);
            rRate.setValue(value.r);
            vol.setValue(value.v);

            final BlackScholesMertonProcess stochProcess = new BlackScholesMertonProcess(
                    new Handle<Quote>(spot),
                    new Handle<YieldTermStructure>(qTS),
                    new Handle<YieldTermStructure>(rTS),
View Full Code Here

        final Date today = new Settings().evaluationDate();

        final DayCounter dc = new Actual360();

        final SimpleQuote           spot  = new SimpleQuote(0.0);
        final SimpleQuote           qRate = new SimpleQuote(0.0);
        final YieldTermStructure    qTS   = Utilities.flatRate(today, qRate, dc);
        final SimpleQuote           rRate = new SimpleQuote(0.0);
        final YieldTermStructure    rTS   = Utilities.flatRate(today, rRate, dc);
        final SimpleQuote           vol   = new SimpleQuote(0.0);
        final BlackVolTermStructure volTS = Utilities.flatVol(today, vol, dc);

        final double tolerance = 1.0e-3;

        for (final AmericanOptionData juValue : juValues) {

            final StrikedTypePayoff payoff = new PlainVanillaPayoff(juValue.type, juValue.strike);
            final Date exDate = today.add(timeToDays(juValue.t));
            final Exercise exercise = new AmericanExercise(today, exDate);

            spot.setValue(juValue.s);
            qRate.setValue(juValue.q);
            rRate.setValue(juValue.r);
            vol.setValue(juValue.v);

            final BlackScholesMertonProcess stochProcess = new BlackScholesMertonProcess(
                    new Handle<Quote>(spot),
                    new Handle<YieldTermStructure>(qTS),
                    new Handle<YieldTermStructure>(rTS),
View Full Code Here

        for (final AmericanOptionData juValue : juValues) {

            final DayCounter dc = new Actual360();

            final SimpleQuote           spot  = new SimpleQuote(0.0);
            final SimpleQuote           qRate = new SimpleQuote(0.0);
            final YieldTermStructure    qTS   = Utilities.flatRate(today, qRate, dc);
            final SimpleQuote           rRate = new SimpleQuote(0.0);
            final YieldTermStructure    rTS   = Utilities.flatRate(today, rRate, dc);
            final SimpleQuote           vol   = new SimpleQuote(0.0);
            final BlackVolTermStructure volTS = Utilities.flatVol(today, vol, dc);

            final StrikedTypePayoff payoff = new PlainVanillaPayoff(juValue.type, juValue.strike);
            final Date exDate = today.add(timeToDays(juValue.t));
            final Exercise exercise = new AmericanExercise(today, exDate);

            spot.setValue(juValue.s);
            qRate.setValue(juValue.q);
            rRate.setValue(juValue.r);
            vol.setValue(juValue.v);

            final BlackScholesMertonProcess stochProcess = new BlackScholesMertonProcess(
                    new Handle<Quote>(spot),
                    new Handle<YieldTermStructure>(qTS),
                    new Handle<YieldTermStructure>(rTS),
View Full Code Here

        final double vols[] = { 0.11, 0.50, 1.20 };

        final DayCounter dc = new Actual360();
        final Date today = new Settings().evaluationDate();

        final SimpleQuote           spot  = new SimpleQuote(0.0);
        final SimpleQuote           qRate = new SimpleQuote(0.0);
        final YieldTermStructure    qTS   = Utilities.flatRate(today, qRate, dc);
        final SimpleQuote           rRate = new SimpleQuote(0.0);
        final YieldTermStructure    rTS   = Utilities.flatRate(today, rRate, dc);
        final SimpleQuote           vol   = new SimpleQuote(0.0);
        final BlackVolTermStructure volTS = Utilities.flatVol(today, vol, dc);

        for (final Type type : types) {
            for (final double strike : strikes) {
                for (final int year : years) {

                    final Date exDate = today.add(new Period(year, TimeUnit.Years));
                    final Exercise exercise = new AmericanExercise(today, exDate);
                    final StrikedTypePayoff payoff = new PlainVanillaPayoff(type, strike);

                    final BlackScholesMertonProcess stochProcess = new BlackScholesMertonProcess(
                            new Handle<Quote>(spot),
                            new Handle<YieldTermStructure>(qTS),
                            new Handle<YieldTermStructure>(rTS),
                            new Handle<BlackVolTermStructure>(volTS));

                    PricingEngine engine = null;
                    try {
                        final Constructor<? extends PricingEngine> c = klass.getConstructor(GeneralizedBlackScholesProcess.class);
                        engine = c.newInstance(stochProcess);
                    } catch (final Exception e) {
                        e.printStackTrace();
                        fail("failed to create pricing engine");
                    }

                    final VanillaOption option = new VanillaOption(payoff, exercise);
                    option.setPricingEngine(engine);

                    for (final double u : underlyings) {
                        for (final double q : qRates) {
                            for (final double r : rRates) {
                                for (final double v : vols) {
                                    spot.setValue(u);
                                    qRate.setValue(q);
                                    rRate.setValue(r);
                                    vol.setValue(v);
                                    // FLOATING_POINT_EXCEPTION
                                    final double value = option.NPV();
                                    final double delta = option.delta();
                                    final double gamma = option.gamma();
                                    //final double theta = option.theta();
View Full Code Here

TOP

Related Classes of org.jquantlib.quotes.SimpleQuote

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.