Examples of SimpleQuote


Examples of org.jquantlib.quotes.SimpleQuote

        // Define exercise for American Options
        final Exercise americanExercise = new AmericanExercise(settlementDate, maturity);

        // bootstrap the yield/dividend/volatility curves
        final Handle<Quote> underlyingH = new Handle<Quote>(new SimpleQuote(underlying));
        final Handle<YieldTermStructure> flatDividendTS = new Handle<YieldTermStructure>(new FlatForward(settlementDate, dividendYield, dayCounter));
        final Handle<YieldTermStructure> flatTermStructure = new Handle<YieldTermStructure>(new FlatForward(settlementDate, riskFreeRate, dayCounter));
        final Handle<BlackVolTermStructure> flatVolTS = new Handle<BlackVolTermStructure>(new BlackConstantVol(settlementDate, calendar, volatility, dayCounter));
        final Payoff payoff = new PlainVanillaPayoff(type, strike);
View Full Code Here

Examples of org.jquantlib.quotes.SimpleQuote

        // ZC rates for the short end
        final double zc3mQuote = 0.0096;
        final double zc6mQuote = 0.0145;
        final double zc1yQuote = 0.0194;

        final Quote zc3mRate = new SimpleQuote(zc3mQuote);
        final Quote zc6mRate = new SimpleQuote(zc6mQuote);
        final Quote zc1yRate = new SimpleQuote(zc1yQuote);

        final DayCounter zcBondsDayCounter = new Actual365Fixed();

        final RateHelper zc3m = new DepositRateHelper(
                new Handle<Quote>(zc3mRate), new Period(3, TimeUnit.Months),
                fixingDays, calendar,
                BusinessDayConvention.ModifiedFollowing, true, zcBondsDayCounter);
        final RateHelper zc6m = new DepositRateHelper(
                new Handle<Quote>(zc6mRate), new Period(6, TimeUnit.Months),
                fixingDays, calendar,
                BusinessDayConvention.ModifiedFollowing, true, zcBondsDayCounter);
        final RateHelper zc1y = new DepositRateHelper(
                new Handle<Quote>(zc1yRate), new Period(1, TimeUnit.Years),
                fixingDays, calendar,
                BusinessDayConvention.ModifiedFollowing, true, zcBondsDayCounter);

        // setup bonds
        final double redemption = 100.0;
        final int numberOfBonds = 5;

        final Date issueDates[] = {
                new Date(15, Month.March,    2005),
                new Date(15, Month.June,     2005),
                new Date(30, Month.June,     2006),
                new Date(15, Month.November, 2002),
                new Date(15, Month.May,      1987) };

        final Date maturities[] = {
                new Date(31, Month.August, 2010),
                new Date(31, Month.August, 2011),
                new Date(31, Month.August, 2013),
                new Date(15, Month.August, 2018),
                new Date(15, Month.May,    2038) };

        final double couponRates[] = 0.02375,
                        0.04625,
                        0.03125,
                        0.04000,
                        0.04500
                        };

        final double marketQuotes[] = { 100.390625,
                        106.21875,
                        100.59375,
                        101.6875,
                        102.140625
                        };

        final List<SimpleQuote> quote = new ArrayList<SimpleQuote>(numberOfBonds);
        final List<RelinkableHandle<Quote>> quoteHandle = new ArrayList<RelinkableHandle<Quote>>(numberOfBonds);
        for (int i = 0; i < numberOfBonds; i++) {
          final SimpleQuote sq = new SimpleQuote(marketQuotes[i]);
          final RelinkableHandle<Quote> handle = new RelinkableHandle<Quote>(sq);
            quote.add(sq);
            quoteHandle.add(handle);  
        }

        // Definition of the rate helpers
//        final List<FixedRateBondHelper<YieldTermStructure>> bondsHelpers = new ArrayList<FixedRateBondHelper<YieldTermStructure>>();
        final List<FixedRateBondHelper> bondsHelpers = new ArrayList<FixedRateBondHelper>();

        for (int i = 0; i < numberOfBonds; i++) {
            final Schedule schedule = new Schedule(
                    issueDates[i], maturities[i],
                    new Period(Frequency.Semiannual),
                    new UnitedStates(UnitedStates.Market.GOVERNMENTBOND),
                    BusinessDayConvention.Unadjusted,
                    BusinessDayConvention.Unadjusted,
                    DateGeneration.Rule.Backward,
                    false);
            final FixedRateBondHelper bondHelper = new FixedRateBondHelper(
                            quoteHandle.get(i),
                            settlementDays,
                            100.0,
                            schedule,
                            new double[]{ couponRates[i] },
                            new ActualActual(ActualActual.Convention.Bond),
                            BusinessDayConvention.Unadjusted,
                            redemption,
                            issueDates[i]);

            bondsHelpers.add(bondHelper);
        }

        /*********************
         ** CURVE BUILDING **
         *********************/

        // Any DayCounter would be fine.
        // ActualActual::ISDA ensures that 30 years is 30.0
        final DayCounter termStructureDayCounter = new ActualActual(ActualActual.Convention.ISDA);

        final double tolerance = 1.0e-15;

        // A depo-bond curve
        final List<RateHelper> bondInstruments = new ArrayList<RateHelper>();

        // Adding the ZC bonds to the curve for the short end
        bondInstruments.add(zc3m);
        bondInstruments.add(zc6m);
        bondInstruments.add(zc1y);

        // Adding the Fixed rate bonds to the curve for the long end
        for (int i = 0; i < numberOfBonds; i++) {
            bondInstruments.add(bondsHelpers.get(i));
        }
        final RateHelper[] instruments1 = new RateHelper[bondInstruments.size()];
        bondInstruments.toArray(instruments1);
        final Handle[] jumps1 = new Handle[0];
        final Date[] jumpDates1 = new Date[0];
        final double tolerance1 = 1.0e-15;
        final LogLinear interpolator = null;
        final IterativeBootstrap bootstrap = null;
       
        final YieldTermStructure  bondDiscountingTermStructur =
                 new PiecewiseYieldCurve<Discount,LogLinear,IterativeBootstrap>(
                     Discount.class, LogLinear.class, IterativeBootstrap.class,
                     settlementDate,
                     instruments1,
                     termStructureDayCounter,
                     jumps1,
                     jumpDates1,
                     tolerance1,
                     interpolator,
                     bootstrap){/* anonymous */};

        // Building of the Libor forecasting curve
        // deposits
        final double d1wQuote = 0.043375;
        final double d1mQuote = 0.031875;
        final double d3mQuote = 0.0320375;
        final double d6mQuote = 0.03385;
        final double d9mQuote = 0.0338125;
        final double d1yQuote = 0.0335125;
        // swaps
        final double s2yQuote = 0.0295;
        final double s3yQuote = 0.0323;
        final double s5yQuote = 0.0359;
        final double s10yQuote = 0.0412;
        final double s15yQuote = 0.0433;

        /********************
         *** QUOTES ***
         ********************/

        // SimpleQuote stores a value which can be manually changed;
        // other Quote subclasses could read the value from a database
        // or some kind of data feed.

        // deposits
        final Quote d1wRate = (new SimpleQuote(d1wQuote));
        final Quote d1mRate = (new SimpleQuote(d1mQuote));
        final Quote d3mRate = (new SimpleQuote(d3mQuote));
        final Quote d6mRate = (new SimpleQuote(d6mQuote));
        final Quote d9mRate = (new SimpleQuote(d9mQuote));
        final Quote d1yRate = (new SimpleQuote(d1yQuote));
        // swaps
        final Quote s2yRate = (new SimpleQuote(s2yQuote));
        final Quote s3yRate = (new SimpleQuote(s3yQuote));
        final Quote s5yRate = (new SimpleQuote(s5yQuote));
        final Quote s10yRate = (new SimpleQuote(s10yQuote));
        final Quote s15yRate = (new SimpleQuote(s15yQuote));

        /*********************
         *** RATE HELPERS ***
         *********************/

 
View Full Code Here

Examples of org.jquantlib.quotes.SimpleQuote

        // SimpleQuote stores a value which can be manually changed;
        // other Quote subclasses could read the value from a database
        // or some kind of data feed.

        final Handle<SimpleQuote> fra1x4Rate = new Handle<SimpleQuote>(new SimpleQuote(threeMonthFraQuote[1]));
        final Handle<SimpleQuote> fra2x5Rate = new Handle<SimpleQuote>(new SimpleQuote(threeMonthFraQuote[2]));
        final Handle<SimpleQuote> fra3x6Rate = new Handle<SimpleQuote>(new SimpleQuote(threeMonthFraQuote[3]));
        final Handle<SimpleQuote> fra6x9Rate = new Handle<SimpleQuote>(new SimpleQuote(threeMonthFraQuote[6]));
        final Handle<SimpleQuote> fra9x12Rate = new Handle<SimpleQuote>(new SimpleQuote(threeMonthFraQuote[9]));

        final RelinkableHandle<Quote> h1x4 = null ;       h1x4.linkTo(fra1x4Rate.currentLink());
        final RelinkableHandle<Quote> h2x5 = null;        h2x5.linkTo(fra2x5Rate.currentLink());
        final RelinkableHandle<Quote> h3x6 = null;        h3x6.linkTo(fra3x6Rate.currentLink());
        final RelinkableHandle<Quote> h6x9 = null;        h6x9.linkTo(fra6x9Rate.currentLink());
View Full Code Here

Examples of org.jquantlib.quotes.SimpleQuote

        }
        QL.require(s0 > 0.0,
                   "negative value after subtracting dividends");

        // binomial trees with constant coefficient
        final Handle<Quote> underlying = new Handle<Quote>(new SimpleQuote(s0));
        final Handle<YieldTermStructure> flatRiskFree =
              new Handle<YieldTermStructure>(new FlatForward(referenceDate, riskFreeRate, rfdc));
        final Handle<YieldTermStructure> flatDividends =
              new Handle<YieldTermStructure>(new FlatForward(referenceDate, q, divdc));
        final Handle<BlackVolTermStructure> flatVol =
View Full Code Here

Examples of org.jquantlib.quotes.SimpleQuote

        // Define exercise for American Options
        final Exercise americanExercise = new AmericanExercise(settlementDate, maturity);

        // bootstrap the yield/dividend/volatility curves
        final Handle<Quote> underlyingH = new Handle<Quote>(new SimpleQuote(underlying));
        final Handle<YieldTermStructure> flatDividendTS = new Handle<YieldTermStructure>(new FlatForward(settlementDate, dividendYield, dayCounter));
        final Handle<YieldTermStructure> flatTermStructure = new Handle<YieldTermStructure>(new FlatForward(settlementDate, riskFreeRate, dayCounter));
        final Handle<BlackVolTermStructure> flatVolTS = new Handle<BlackVolTermStructure>(new BlackConstantVol(settlementDate, calendar, volatility, dayCounter));
        final Payoff payoff = new PlainVanillaPayoff(type, strike);
View Full Code Here

Examples of org.jquantlib.quotes.SimpleQuote

        }

        this.riskFreeRate_ = (riskFreeRate);
        this.dividendYield_ = (dividendYield);
        this.s0_ = (s0); // TODO: code review
        this.v0_ = new RelinkableHandle<Quote>(new SimpleQuote(v0));
        this.kappa_ = new RelinkableHandle<Quote>(new SimpleQuote(kappa));
        this.theta_ = new RelinkableHandle<Quote>(new SimpleQuote(theta));
        this.sigma_ = new RelinkableHandle<Quote>(new SimpleQuote(sigma));
        this.rho_ = new RelinkableHandle<Quote>(new SimpleQuote(rho));
        this.discretization_ = (d);

        // TODO: code review :: please verify against QL/C++ code

        this.riskFreeRate_.addObserver(this);
View Full Code Here

Examples of org.jquantlib.quotes.SimpleQuote

            final /*@NonNegative*/ int maxEvaluations,
            final /*@Volatility*/ double minVol,
            final /*@Volatility*/ double maxVol) /* @ReadOnly */ {

        QL.require(!isExpired(), "option expired");
        final SimpleQuote volQuote = new SimpleQuote();
        final GeneralizedBlackScholesProcess newProcess = ImpliedVolatilityHelper.clone(process, volQuote);

        // engines are built-in for the time being
        final PricingEngine engine;
        switch (exercise.type()) {
View Full Code Here

Examples of org.jquantlib.quotes.SimpleQuote


        System.out.println("//============================StochasticProcess1D/LinearDiscretization=========================");

        //Creating stock quote handle
        final SimpleQuote stockQuote = new SimpleQuote(5.6);
        final RelinkableHandle<Quote>  handleToStockQuote = new RelinkableHandle<Quote>(stockQuote);

        //Creating black volatility term structure

        //Following is the time axis
        final Date[] dates = { date10.clone(), date15.clone(), date20.clone(), date25.clone(), date30.clone(), date40.clone() };

        //Following is the volatility axis
        final double[] volatilities = {0.1,0.2,0.3,0.4,0.5,0.6};

        //Following is the curve
        final BlackVarianceTermStructure varianceCurve = new BlackVarianceCurve(today, dates,volatilities, new Actual365Fixed(), false);
        ((BlackVarianceCurve)varianceCurve).setInterpolation();

        //Dividend termstructure
        final SimpleQuote dividendQuote = new SimpleQuote(0.3);
        final RelinkableHandle<Quote>  handleToInterestRateQuote = new RelinkableHandle<Quote>(dividendQuote);
        final YieldTermStructure dividendTermStructure = new FlatForward(2,new UnitedStates(Market.NYSE),handleToInterestRateQuote, new Actual365Fixed(), Compounding.Continuous,Frequency.Daily);

        //Risk free term structure
        final SimpleQuote riskFreeRateQuote = new SimpleQuote(0.3);
        final RelinkableHandle<Quote>  handleToRiskFreeRateQuote = new RelinkableHandle<Quote>(riskFreeRateQuote);
        final YieldTermStructure riskFreeTermStructure = new FlatForward(2,new UnitedStates(Market.NYSE),handleToRiskFreeRateQuote, new Actual365Fixed(), Compounding.Continuous,Frequency.Daily);

        //Creating the process
        final StochasticProcess1D process = new GeneralizedBlackScholesProcess(handleToStockQuote,new RelinkableHandle<YieldTermStructure>(dividendTermStructure),new RelinkableHandle<YieldTermStructure>(riskFreeTermStructure),new RelinkableHandle<BlackVolTermStructure>(varianceCurve),new EulerDiscretization());
View Full Code Here

Examples of org.jquantlib.quotes.SimpleQuote

        System.out.println("//===============================BlackConstantVol termstructure==================================");

        //Let's explore BlackConstantVolatility by calculating blackVolatility,blackForwardVolatility,blackVariance and blackForwardVariance
        //Following example explains that when volatility is assumed to be constant BlackConstantVol termstructure can be used to represent
        //such a volatility termstructure.
        final SimpleQuote volatilityQuote = new SimpleQuote(0.3);
        final RelinkableHandle<Quote>  handleToVolatilityQuote = new RelinkableHandle<Quote>(volatilityQuote);
        BlackVolatilityTermStructure constantVolatility = new BlackConstantVol(2,new UnitedStates(Market.NYSE),handleToVolatilityQuote, new Actual365Fixed());

        //Calculating blackVolatility using maturity as 10 days after today and strike as 20
        Double volatility1 = constantVolatility.blackVol(date10.clone(), 20);
        System.out.println("BlackVolatility = "+volatility1);

        //Calculating blackVolatility using maturity as 20 days after today and strike as 30
        Double volatility2 = constantVolatility.blackVol(date20.clone(), 30);
        System.out.println("BlackVolatility = "+volatility2);

        //Calculating blackVolatility using maturity as 30 days after today and strike as 40
        Double volatility3 = constantVolatility.blackVol(date30.clone(), 40);
        System.out.println("BlackVolatility = "+volatility3);

        //The volatilities calculated above are same as it's constant volatility termstructure
        if(volatility1.equals(volatility2) && volatility2.equals(volatility3)){
            System.out.println("All the volatilities calculated above are same and = "+volatility1);
        }

        //Calculating blackForwardVolatility between 10 days after today and 15 days after today with strike as 20
        Double forwardVolatility1 = constantVolatility.blackForwardVol(date10.clone(), date15.clone(), 20, true);
        System.out.println("BlackForwardVolatility = "+forwardVolatility1);

        //Calculating blackForwardVolatility between 20 days after today and 25 days after today with strike as 40
        Double forwardVolatility2 = constantVolatility.blackForwardVol(date10.clone(), date15.clone(), 20, true);
        System.out.println("BlackForwardVolatility = "+forwardVolatility2);

        //Calculating blackForwardVolatility between 27 days after today and 35 days after today with strike as 60
        Double forwardVolatility3 = constantVolatility.blackForwardVol(date27.clone(), date35.clone(), 60, true);
        System.out.println("BlackForwardVolatility = "+forwardVolatility3);

        //The volatilities calculated above are same as it's constant volatility termstructure
        if(forwardVolatility1.equals(forwardVolatility2) && forwardVolatility2.equals(forwardVolatility3)){
            System.out.println("All the forward volatilities calculated above are same and = "+forwardVolatility1);
        }else{
            System.out.println("The forward volatilities may not be constant");
        }

        //Calculating blackVariance
        System.out.println("BlackVariance = "+constantVolatility.blackVariance(date10.clone(), 20));

        //Calculating blackForwardVariance
        System.out.println("BlackForwardVariance = "+constantVolatility.blackForwardVariance(date10.clone(), date15.clone(), 20, true));

        //As BlackConstantVol termstructure has been initialized using relinkable handle so lets change the observable SimpleQuote of this handle
        //and see the change getting reflected to all the calculations done above.
        volatilityQuote.setValue(0.04) ;
        constantVolatility = new BlackConstantVol(2,new UnitedStates(Market.NYSE),handleToVolatilityQuote, new Actual365Fixed());

        //Calculating blackVolatility using maturity as 10 days after today and strike as 20
        volatility1 = constantVolatility.blackVol(date10.clone(), 20);
        System.out.println("BlackVolatility = "+volatility1);

        //Calculating blackVolatility using maturity as 20 days after today and strike as 30
        volatility2 = constantVolatility.blackVol(date20.clone(), 30);
        System.out.println("BlackVolatility = "+volatility2);

        volatility3 = constantVolatility.blackVol(date30.clone(), 40);
        System.out.println("BlackVolatility = "+volatility3);

        //The volatilities calculated above are same as it's constant volatility termstructure
        if(volatility1.equals(volatility2) && volatility2.equals(volatility3)){
            System.out.println("All the volatilities calculated above are same and = "+volatility1);
        }

        //Calculating blackForwardVolatility between 10 days after today and 15 days after today with strike as 20
        forwardVolatility1 = constantVolatility.blackForwardVol(date10.clone(), date15.clone(), 20, true);
        System.out.println("BlackForwardVolatility = "+forwardVolatility1);

        //Calculating blackForwardVolatility between 20 days after today and 25 days after today with strike as 40
        forwardVolatility2 = constantVolatility.blackForwardVol(date10.clone(), date15.clone(), 20, true);
        System.out.println("BlackForwardVolatility = "+forwardVolatility2);

        //Calculating blackForwardVolatility between 27 days after today and 35 days after today with strike as 60
        forwardVolatility3 = constantVolatility.blackForwardVol(date27.clone(), date35.clone(), 60, true);
        System.out.println("BlackForwardVolatility = "+forwardVolatility3);

        //The volatilities calculated above are same as it's constant volatility termstructure
        if(forwardVolatility1.equals(forwardVolatility2) && forwardVolatility2.equals(forwardVolatility3)){
            System.out.println("All the volatilities calculated above are same and = "+forwardVolatility1);
        }else{
            System.out.println("The forward volatilities may not be constant");
        }

        //Calculating blackVariance
        System.out.println("BlackVariance = "+constantVolatility.blackVariance(date10.clone(), 20));

        //Calculating blackForwardVariance
        System.out.println("BlackForwardVariance = "+constantVolatility.blackForwardVariance(date10.clone(), date15.clone(), 20, true));

        System.out.println("//===============================BlackVarianceCurve================================");

        //Let's create black variance curve and calculate volatilities/variances by interpolating on
        //the created curve for a given strike.

        //-- Date today = DateFactory.getFactory().getTodaysDate();

        //Following is the time axis
        final Date[] dates = {date10.clone(), date15.clone(), date20.clone(), date25.clone(), date30.clone(), date40.clone() };

        //Following is the volatility axis
        final double[] volatilities = {0.1,0.2,0.3,0.4,0.5,0.6};

        //Following is the curve
        final BlackVarianceTermStructure varianceCurve = new BlackVarianceCurve(today,dates,volatilities, new Actual365Fixed(), false);
        ((BlackVarianceCurve)varianceCurve).setInterpolation();

        //Calculating blackVolatility using maturity as 12 days after today and strike as 20
        volatility1 = varianceCurve.blackVol(date12.clone(), 20);
        System.out.println("Interpolated BlackVolatility on BlackVarianceCurve = "+volatility1);

        //Calculating blackVolatility using maturity as 22 days after today and strike as 30
        volatility2 = varianceCurve.blackVol(date22.clone(), 30);
        System.out.println("Interpolated BlackVolatility on BlackVarianceCurve = "+volatility2);

        //Calculating blackVolatility using maturity as 32 days after today and strike as 40
        volatility3 = varianceCurve.blackVol(date32.clone(), 40);
        System.out.println("Interpolated BlackVolatility on BlackVarianceCurve = "+volatility3);


        //Calculating blackForwardVolatility between 12 days after today and 16 days after today with strike as 20
        forwardVolatility1 = varianceCurve.blackForwardVol(date12.clone(), date16.clone(), 20, true);
        System.out.println("Interpolated BlackForwardVolatility on BlackVarianceCurve = "+forwardVolatility1);

        //Calculating blackForwardVolatility between 22 days after today and 26 days after today with strike as 40
        forwardVolatility2 = varianceCurve.blackForwardVol(date22.clone(), date26.clone(), 40, true);
        System.out.println("Interpolated BlackForwardVolatility on BlackVarianceCurve = "+forwardVolatility2);

        //Calculating blackForwardVolatility between 27 days after today and 35 days after today with strike as 60
        forwardVolatility3 = varianceCurve.blackForwardVol(date27.clone(), date35.clone(), 60, true);
        System.out.println("Interpolated BlackForwardVolatility on BlackVarianceCurve = "+forwardVolatility3);


        //Calculating blackVariance using maturity as 12 days after today and strike as 20
        System.out.println("Interpolated BlackVariance on BlackVarianceCurve = "+varianceCurve.blackVariance(date12.clone(), 20));

        //Calculating blackForwardVariance between 12 days after today and 16 days after today with strike as 20
        System.out.println("Interpolated BlackForwardVariance on BlackVarianceCurve = "+varianceCurve.blackForwardVariance(date12.clone(), date16.clone(), 20, true));

        System.out.println("//===============================BlackVarianceSurface================================");

        //Let's create black variance surface and calculate volatilities/variances by interpolating on
        //the created curve for a given strike.

        //-- today = DateFactory.getFactory().getTodaysDate();

        //Following is the time axis
        final Date[] datesAxis = {date10.clone(), date15.clone(), date20.clone(), date25.clone(), date30.clone(), date40.clone() };

        final Array strikeAxis = new Array(new double[] {10,20,35,40,56,60});

        //Following is the volatility surface on which interpolations will be done
        final Matrix volatilityMatrix = new Matrix(new double[][] {
                {0.01,0.02,0.03,0.04,0.05,0.06},
                {0.02,0.03,0.04,0.05,0.06,0.07},
                {0.03,0.04,0.05,0.06,0.07,0.08},
                {0.3,0.5,0.6,0.7,0.8,0.9},
                {0.1,0.4,0.6,0.7,0.8,0.9},
                {0.2,0.5,0.6,0.7,0.8,0.9}
        });


        //Following is the variance surface where variance = f(strike,maturity) and f = function
        final BlackVarianceTermStructure varianceSurface = new BlackVarianceSurface(
                today, datesAxis,
                strikeAxis, volatilityMatrix, new Actual365Fixed(),
                Extrapolation.InterpolatorDefaultExtrapolation,
                Extrapolation.InterpolatorDefaultExtrapolation);
        ((BlackVarianceSurface)varianceSurface).setInterpolation(null);

        //As the surface has been set up to do interpolations so let's start calculating the volatilities for strikes
        //and maturities lying between the points as mentioned by strikesAxis and dateAxis.
        //Calculating blackVolatility using maturity as 12 days after today and strike as 18
        volatility1 = varianceSurface.blackVol(date12.clone(), 18);
        System.out.println("Interpolated BlackVolatility on BlackVarianceSurface = "+volatility1);

        //Calculating blackVolatility using maturity as 22 days after today and strike as 33
        volatility2 = varianceSurface.blackVol(date22.clone(), 33);
        System.out.println("Interpolated BlackVolatility on BlackVarianceSurface = "+volatility2);

        //Calculating blackVolatility using maturity as 32 days after today and strike as 45
        volatility3 = varianceSurface.blackVol(date32.clone(), 45);
        System.out.println("Interpolated BlackVolatility on BlackVarianceSurface = "+volatility3);


        //Calculating blackForwardVolatility between 12 days after today and 16 days after today with strike as 20
        forwardVolatility1 = varianceSurface.blackForwardVol(date12.clone(), date16.clone(), 20, true);
        System.out.println("Interpolated BlackForwardVolatility on BlackVarianceSurface = "+forwardVolatility1);

        //Calculating blackForwardVolatility between 22 days after today and 26 days after today with strike as 40
        forwardVolatility2 = varianceSurface.blackForwardVol(date22.clone(), date26.clone(), 40, true);
        System.out.println("Interpolated BlackForwardVolatility on BlackVarianceSurface = "+forwardVolatility2);

        //Calculating blackForwardVolatility between 27 days after today and 35 days after today with strike as 50
        forwardVolatility3 = varianceSurface.blackForwardVol(date27.clone(), date35.clone(), 50, true);
        System.out.println("Interpolated BlackForwardVolatility on BlackVarianceSurface = "+forwardVolatility3);


        //Calculating blackVariance using maturity as 12 days after today and strike as 20
        System.out.println("Interpolated BlackVariance on BlackVarianceSurface = "+varianceSurface.blackVariance(date12.clone(), 20));

        //Calculating blackForwardVariance between 12 days after today and 16 days after today with strike as 20
        System.out.println("Interpolated BlackForwardVariance on BlackVarianceSurface = "+varianceSurface.blackForwardVariance(date12.clone(), date16.clone(), 20, true));

        System.out.println("//================================ImpliedVolTermStructure=============================");

        //As mentioned in the java docs the implied volatility termstructure remains linked to
        //the underlying termstructure and changes to same are linked to ImpliedVolTermStructure
        //as well.

        //Lets use underlying as varianceCurve defined above by creating a relinkable handle as shown below
        final RelinkableHandle<BlackVolTermStructure> varianceCurveHandle = new RelinkableHandle<BlackVolTermStructure>(varianceCurve);
        final BlackVarianceTermStructure impliedVolTermStructure = new ImpliedVolTermStructure(varianceCurveHandle, today);

        //Calculating blackVolatility using maturity as 12 days after today and strike as 20
        volatility1 = varianceCurve.blackVol(date12.clone(), 20);
        final double impliedVolatility1 = impliedVolTermStructure.blackVol(date12.clone(), 20);

        if(volatility1 == impliedVolatility1){
            System.out.println("Interpolated BlackVolatility on BlackVarianceCurve is same for varianceCurve and ImpliedVolTermStructure derived on it and = "+volatility1);
        }

        //Calculating blackVolatility using maturity as 22 days after today and strike as 30
        volatility2 = varianceCurve.blackVol(date22.clone(), 30);
        final double impliedVolatility2 = impliedVolTermStructure.blackVol(date22.clone(), 30);
        if(volatility2 == impliedVolatility2){
            System.out.println("Interpolated BlackVolatility on BlackVarianceCurve is same for varianceCurve and ImpliedVolTermStructure derived on it and = "+volatility2);
        }

        //Calculating blackVolatility using maturity as 32 days after today and strike as 40
        volatility3 = varianceCurve.blackVol(date32.clone(), 40);
        final double impliedVolatility3 = impliedVolTermStructure.blackVol(date32.clone(), 40);
        if(volatility3 == impliedVolatility3){
            System.out.println("Interpolated BlackVolatility on BlackVarianceCurve is same for varianceCurve and ImpliedVolTermStructure derived on it and = "+volatility3);
        }


        //Calculating blackForwardVolatility between 12 days after today and 16 days after today with strike as 20
        forwardVolatility1 = varianceCurve.blackForwardVol(date12.clone(), date16.clone(), 20, true);
        final double impliedForwardVolatility1 = impliedVolTermStructure.blackForwardVol(date12.clone(), date16.clone(), 20, true);
        if(forwardVolatility1 == impliedForwardVolatility1){
            System.out.println("Interpolated BlackForwardVolatility on BlackVarianceCurve is same for varianceCurve and ImpliedVolTermStructure derived on it and = "+forwardVolatility1);
        }

        //Calculating blackForwardVolatility between 22 days after today and 26 days after today with strike as 40
        forwardVolatility2 = varianceCurve.blackForwardVol(date22.clone(), date26.clone(), 40, true);
        final double impliedForwardVolatility2 = impliedVolTermStructure.blackForwardVol(date22.clone(), date26.clone(), 40, true);
        if(forwardVolatility2 == impliedForwardVolatility2){
            System.out.println("Interpolated BlackForwardVolatility on BlackVarianceCurve is same for varianceCurve and ImpliedVolTermStructure derived on it and = "+forwardVolatility2);
        }

        //Calculating blackForwardVolatility between 27 days after today and 35 days after today with strike as 60
        forwardVolatility3 = varianceCurve.blackForwardVol(date27.clone(), date35.clone(), 60, true);
        final double impliedForwardVolatility3 = impliedVolTermStructure.blackForwardVol(date27.clone(), date35.clone(), 60, true);
        if(forwardVolatility3 == impliedForwardVolatility3){
            System.out.println("Interpolated BlackForwardVolatility on BlackVarianceCurve is same for varianceCurve and ImpliedVolTermStructure derived on it and = "+forwardVolatility3);
        }


        //Calculating blackVariance using maturity as 12 days after today and strike as 20
        final double variance = varianceCurve.blackVariance(date12.clone(), 20);
        final double impliedVariance = impliedVolTermStructure.blackVariance(date12.clone(), 20);
        if(variance == impliedVariance){
            System.out.println("Interpolated BlackVariance on BlackVarianceCurve is same for varianceCurve and ImpliedVolTermStructure derived on it and = "+varianceCurve.blackVariance(date12.clone(), 20));
        }

        //Calculating blackForwardVariance between 12 days after today and 16 days after today with strike as 20
        final double forwardVariance = varianceCurve.blackForwardVariance(date12.clone(), date16.clone(), 20, true);
        final double impliedForwardVariance = impliedVolTermStructure.blackForwardVariance(date12.clone(), date16.clone(), 20, true);
        if(forwardVariance == impliedForwardVariance){
            System.out.println("Interpolated BlackForwardVariance on BlackVarianceCurve is same for varianceCurve and ImpliedVolTermStructure derived on it and = "+varianceCurve.blackForwardVariance(date12.clone(), date16.clone(), 20, true));
        }

        System.out.println("//================================LocalConstantVol=======================================");

        //LocalConstantVolatility is essentially same as BlackConstantVol and is a local volatility version of BlackConstantVol

        //Let's set the quoteValue = 0.05 and use the constantVolatility a BlackConstantVol
        volatilityQuote.setValue(0.05);
        final LocalVolTermStructure localConstantVolatility = new LocalConstantVol(2,new UnitedStates(Market.NYSE),handleToVolatilityQuote, new Actual365Fixed());

        //Calculating blackVolatility using maturity as 10 days after today and strike as 20
        if(constantVolatility.blackVol(date10.clone(), 20) == localConstantVolatility.localVol(date10.clone(), 20,true)){
            System.out.println("BlackVolatility and LocalVolatility are same and are = "+localConstantVolatility.localVol(date10.clone(), 20,true));
View Full Code Here

Examples of org.jquantlib.quotes.SimpleQuote

            final int maxEvaluations,
            /*@Volatility*/ final double minVol,
            /*@Volatility*/ final double maxVol) /* @ReadOnly */ {

        QL.require(!isExpired(), "option expired");
        final SimpleQuote volQuote = new SimpleQuote();
        final GeneralizedBlackScholesProcess newProcess = ImpliedVolatilityHelper.clone(process, volQuote);

        // engines are built-in for the time being
        final PricingEngine engine;
        switch (exercise.type()) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.