Package org.jquantlib.quotes

Examples of org.jquantlib.quotes.SimpleQuote


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


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

        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 NewBarrierOptionData value : values) {
            final Date exDate = today.add( timeToDays(value.t) );
            final Exercise exercise = new EuropeanExercise(exDate);

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

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

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

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

        final Quote                 underlying = new SimpleQuote(underlyingPrice);
        final Quote                 qH_SME     = new SimpleQuote(q);
        final YieldTermStructure    qTS        = Utilities.flatRate(today, qH_SME, dc);
        final Quote                 rH_SME     = new SimpleQuote(r);
        final YieldTermStructure    rTS        = Utilities.flatRate(today, rH_SME, dc);
        final SimpleQuote           volatility = new SimpleQuote(0.10);
        final BlackVolTermStructure volTS      = Utilities.flatVol(today, volatility, dc);

        final Date exDate = today.add(360);
        final Exercise exercise = new EuropeanExercise(exDate);

        for (final BarrierOptionData value : values) {
            volatility.setValue(value.volatility);
            final StrikedTypePayoff callPayoff = new PlainVanillaPayoff(Option.Type.Call, value.strike);

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

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

        final Quote                 underlying = new SimpleQuote(underlyingPrice);
        final Quote                 qH_SME     = new SimpleQuote(q);
        final YieldTermStructure    qTS        = Utilities.flatRate(today, qH_SME, dc);
        final Quote                 rH_SME     = new SimpleQuote(r);
        final YieldTermStructure    rTS        = Utilities.flatRate(today, rH_SME, dc);
        final SimpleQuote           volatility = new SimpleQuote(0.10);
        final BlackVolTermStructure volTS      = Utilities.flatVol(today, volatility, dc);

        final Date exDate = today.add(360);

        final Exercise exercise = new EuropeanExercise(exDate);

        for (final BarrierOptionData value : values) {
            volatility.setValue(value.volatility);
            final StrikedTypePayoff callPayoff = new PlainVanillaPayoff(Option.Type.Call, value.strike);

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

    final int timeSteps = 1001;
    final PricingEngine engine = new BinomialConvertibleEngine<CoxRossRubinstein>(CoxRossRubinstein.class, vars.process, timeSteps);
    final PricingEngine vanillaEngine = new BinomialVanillaEngine<CoxRossRubinstein>(CoxRossRubinstein.class, vars.process, timeSteps);

    vars.creditSpread.linkTo(new SimpleQuote(0.0));

    final double conversionStrike = vars.redemption / vars.conversionRatio;
    final StrikedTypePayoff payoff = new PlainVanillaPayoff(Option.Type.Call,
        conversionStrike);
View Full Code Here

      issueDate = calendar.advance(today, 2, TimeUnit.Days);
      maturityDate = calendar.advance(issueDate, 10, TimeUnit.Years);
      // reset to avoid inconsistencies as the schedule is backwards
      issueDate = calendar.advance(maturityDate, -10, TimeUnit.Years);

      underlying.linkTo(new SimpleQuote(50.0));
      dividendYield.linkTo(Utilities.flatRate(today, 0.02, dayCounter));
      riskFreeRate.linkTo(Utilities.flatRate(today, 0.05, dayCounter));
      volatility.linkTo(Utilities.flatVol(today, 0.15, dayCounter));

      process = new BlackScholesMertonProcess(underlying, dividendYield,
          riskFreeRate, volatility);

      creditSpread.linkTo(new SimpleQuote(0.005));

      // it fails with 1000000
      // faceAmount = 1000000.0;
      faceAmount = 100.0;
      redemption = 100.0;
View Full Code Here

        super(new PlainVanillaPayoff(type, strike), exercise, dates, dividends);

        this.cal = cal;
        this.dc = dc;

        final SimpleQuote spot = new SimpleQuote(0.0);
        this.rRate = new Handle<SimpleQuote>(new SimpleQuote(r));
        this.qRate = new Handle<SimpleQuote>(new SimpleQuote(q));
        this.vol   = new Handle<SimpleQuote>(new SimpleQuote(v));

        final Handle<YieldTermStructure> rTS = new Handle<YieldTermStructure>(flatRate(referenceDate, rRate, dc));
        final Handle<YieldTermStructure> qTS = new Handle<YieldTermStructure>(flatRate(referenceDate, qRate, dc));
        final Handle<BlackVolTermStructure> volTS = new Handle<BlackVolTermStructure>(flatVol(referenceDate, vol, cal, dc));

        // obtain stochastic process
        this.stochProcess = new BlackScholesMertonProcess(new Handle<Quote>(spot), qTS, rTS, volTS);

        // obtain a pricing engine and assign to this option :: 3 intervals a day
        final int timeSteps = (int) (exercise.lastDate().sub(referenceDate) * 3);
        final PricingEngine engine;
        try {
            final Constructor<T> baseConstructor = engineClass.getConstructor(
                    GeneralizedBlackScholesProcess.class, int.class);
            engine = baseConstructor.newInstance(stochProcess, timeSteps);
        } catch (final Exception e) {
            throw new LibraryException(e);
        }

        // assign the pricing engine to this option
        this.setPricingEngine(engine);

        // assign new values to spot, qRate, rRate and vol
        // note: this step is needed in order to notify observers
        spot.setValue(u);
    }
View Full Code Here

        super(new PlainVanillaPayoff(type, strike), exercise, dates, dividends);

        this.cal = cal;
        this.dc = dc;

        final SimpleQuote spot = new SimpleQuote(0.0);
        this.rRate = new Handle<SimpleQuote>(new SimpleQuote(r));
        this.qRate = new Handle<SimpleQuote>(new SimpleQuote(q));
        this.vol   = new Handle<SimpleQuote>(new SimpleQuote(v));
        final Handle<YieldTermStructure> rTS = new Handle<YieldTermStructure>(flatRate(referenceDate, rRate, dc));
        final Handle<YieldTermStructure> qTS = new Handle<YieldTermStructure>(flatRate(referenceDate, qRate, dc));
        final Handle<BlackVolTermStructure> volTS = new Handle<BlackVolTermStructure>(flatVol(referenceDate, vol, cal, dc));

        // obtain stochastic process
        this.stochProcess = new BlackScholesMertonProcess(new Handle<Quote>(spot), qTS, rTS, volTS);

        // obtain a pricing engine and assign to this option :: 3 intervals a day
        final int timeSteps = (int) (exercise.lastDate().sub(referenceDate) * 3);
        final PricingEngine engine = new BinomialDividendVanillaEngine<CoxRossRubinstein>(CoxRossRubinstein.class, stochProcess, timeSteps) { /* anonymous */ };

        // assign the pricing engine to this option
        this.setPricingEngine(engine);

        // assign new values to spot, qRate, rRate and vol
        // note: this step is needed in order to notify observers
        spot.setValue(u);
    }
View Full Code Here

        final DayCounter dc = new Actual360();

        QL.info("Today: " + today);

        final SimpleQuote spot = new SimpleQuote(100.0);
        final SimpleQuote qRate = new SimpleQuote(0.03);
        final YieldTermStructure qTS = Utilities.flatRate(today, qRate.value(), dc);
        final SimpleQuote rRate = new SimpleQuote(0.06);
        final YieldTermStructure rTS = Utilities.flatRate(today, rRate.value(), dc);
        final SimpleQuote vol = new SimpleQuote(0.20);
        final BlackVolTermStructure volTS = Utilities.flatVol(today, vol.value(), dc);

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

        final PricingEngine engine = new AnalyticDiscreteGeometricAveragePriceAsianEngine(stochProcess);

        final AverageType averageType = AverageType.Geometric;
        /* @Real */final double runningAccumulator = 1.0;
        /* @Size */final int pastFixings = 0;
        /* @Size */final int futureFixings = 10;
        final Option.Type type = Option.Type.Call;
        /* @Real */final double strike = 100.0;
        final StrikedTypePayoff payoff = new PlainVanillaPayoff(type, strike);

        final Date exerciseDate = today.clone().addAssign(360);
        final Exercise exercise = new EuropeanExercise(exerciseDate);

        QL.info("Exercise: " + exerciseDate);
        QL.info("Df: " + rTS.discount(exerciseDate));
        QL.info("DivDf: " + qTS.discount(exerciseDate));

        final List<Date> fixingDates = new ArrayList<Date>(futureFixings);
        final int dt = (int) (360.0 / (futureFixings) + 0.5);
        fixingDates.add(today.clone().addAssign(dt));
        for (int j = 1; j < futureFixings; j++) {
            final Date prevDate = fixingDates.get(j - 1);
            fixingDates.add(prevDate.clone().addAssign(dt));
        }

        QL.info("Average Dates:\n");
        for (final Date d : fixingDates) {
            QL.info(d.toString());
        }

        final DiscreteAveragingAsianOption option = new DiscreteAveragingAsianOption(
                averageType, runningAccumulator, pastFixings, fixingDates, payoff, exercise);
        option.setPricingEngine(engine);

        /* @Real */final double calculated = option.NPV();
        /* @Real */final double expected = 5.3425606635;

        /* @Real */final double tolerance = 1e-10;
        if (Math.abs(calculated - expected) > tolerance) {
            reportFailure("value", averageType, runningAccumulator, pastFixings, fixingDates, payoff, exercise, spot.value(),
                    qRate.value(), rRate.value(), today, vol.value(), expected, calculated, tolerance);
        }
    }
View Full Code Here

        /* @Integer */final int lengths[] = { 1, 2 };
        /* @Volatility */final double vols[] = { 0.11, 0.50, 1.20 };

        final DayCounter dc = new Actual360();

        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 BlackScholesMertonProcess process = new BlackScholesMertonProcess(
                new Handle<Quote>(spot),
                new Handle<YieldTermStructure>(qTS),
                new Handle<YieldTermStructure>(rTS),
                new Handle<BlackVolTermStructure>(volTS));

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

        for (final Type type : types) {
            for (final double strike : strikes) {
                for (final int length : lengths) {

                    final Date exerciseDate = new Date(today.dayOfMonth(), today.month(), today.year() + length);
                    final EuropeanExercise maturity = new EuropeanExercise(exerciseDate);

                    final PlainVanillaPayoff payoff = new PlainVanillaPayoff(type, strike);

                    final double runningAverage = 120;
                    final int pastFixings = 1;

                    final List<Date> fixingDates = new ArrayList<Date>();

                    final Date d = today.clone();
                    final Period THREEMONTH = new Period(3, TimeUnit.Months);
                    d.addAssign(new Period(3, TimeUnit.Months));
                    for (d.addAssign(THREEMONTH); d.le(maturity.lastDate()); d.addAssign(THREEMONTH)) {
                        fixingDates.add(d.clone());
                    }

                    final PricingEngine engine = new AnalyticDiscreteGeometricAveragePriceAsianEngine(process);

                    final DiscreteAveragingAsianOption option = new DiscreteAveragingAsianOption(
                            AverageType.Geometric, runningAverage, pastFixings, fixingDates, payoff, maturity);
                    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);

                                    final double value = option.NPV();
                                    final Map<String, Double> calculated = new HashMap<String, Double>();
                                    calculated.put("delta", option.delta());
                                    calculated.put("gamma", option.gamma());
                                    calculated.put("theta", option.theta());
                                    calculated.put("rho", option.rho());
                                    calculated.put("divRho", option.dividendRho());
                                    calculated.put("vega", option.vega());

                                    final Map<String, Double> expected = new HashMap<String, Double>();
                                    if (value > spot.value() * 1.0e-5) {
                                        // perturb spot and get delta and gamma
                                        final double du = u * 1.0e-4;
                                        spot.setValue(u + du);
                                        double value_p = option.NPV();
                                        final double delta_p = option.delta();
                                        spot.setValue(u - du);
                                        double value_m = option.NPV();
                                        final double delta_m = option.delta();
                                        spot.setValue(u);
                                        expected.put("delta", (value_p - value_m) / (2 * du));
                                        expected.put("gamma", (delta_p - delta_m) / (2 * du));

                                        // perturb rates and get rho and dividend rho
                                        final double dr = r * 1.0e-4;
                                        rRate.setValue(r + dr);
                                        value_p = option.NPV();
                                        rRate.setValue(r - dr);
                                        value_m = option.NPV();
                                        rRate.setValue(r);
                                        expected.put("rho", (value_p - value_m) / (2 * dr));

                                        final double dq = q * 1.0e-4;
                                        qRate.setValue(q + dq);
                                        value_p = option.NPV();
                                        qRate.setValue(q - dq);
                                        value_m = option.NPV();
                                        qRate.setValue(q);
                                        expected.put("divRho", (value_p - value_m) / (2 * dq));

                                        // perturb volatility and get vega
                                        final double dv = v * 1.0e-4;
                                        vol.setValue(v + dv);
                                        value_p = option.NPV();
                                        vol.setValue(v - dv);
                                        value_m = option.NPV();
                                        vol.setValue(v);
                                        expected.put("vega", (value_p - value_m) / (2 * dv));

                                        // perturb date and get theta
                                        final Date yesterday = today.sub(1);
                                        final Date tomorrow = today.add(1);
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.