Package org.jquantlib.math.solvers1D

Examples of org.jquantlib.math.solvers1D.Brent


                data[i+1] = traits.initialGuess();
            }
            ts.setData(data);
        }

        final Brent solver = new Brent ();
        final int maxIterations = traits.maxIterations();

        for (int iteration = 0;; ++iteration) {
            // only read safe to use as a reference
            final double previousData[] = data.clone(); // TODO: verify if clone() is needed
            // restart from the previous interpolation
            if (validCurve) {
                ts.setInterpolation(interpolator.interpolate(new Array(times), new Array(data)));
            }

            for (int i=1; i<n+1; ++i) {
                /*
                for (int k = 0; k < data.size(); ++ k)
                {
                    StringBuilder sb = new StringBuilder ();
                    sb.append ("Date: ");
                    sb.append (dates[k]);
                    sb.append ("\t Time: ");
                    sb.append (df.format (times.get (k)));
                    sb.append ("\t Discount: ");
                    sb.append (df.format (data.get(k)));
                    QL.debug (sb.toString ());
                }
                */

                // calculate guess before extending interpolation
                // to ensure that any extrapolation is performed
                // using the curve bootstrapped so far and no more
                final RateHelper instrument = instruments[i-1];
                double guess = 0.0;
                if (validCurve|| iteration>0) {
                    guess = ts.data()[i];
                } else if (i==1) {
                    guess = traits.initialGuess();
                } else {
                    // most traits extrapolate
                    guess = traits.guess(ts, dates[i]);
                }

                //QL.debug (" Guess : " + ((Double)(guess)).toString());

                // bracket
                final double min = traits.minValueAfter(i, data);
                final double max = traits.maxValueAfter(i, data);

                if (guess <= min || guess >= max) {
                    guess = (min + max) / 2.0;
                }

                if (! validCurve && iteration == 0) {
                    // extend interpolation a point at a time
                    try {
                        ts.setInterpolation(interpolator.interpolate (new Array(times, i+1), new Array(data)));
                    } catch (final Exception e) {
                        // no chance to fix it in a later iteration
                        if (ts.interpolator().global()) {
                            throw new LibraryException("no chance to fix it in a later iteration");
                        }

                        // otherwise, if the target interpolation is not usable yet
                        ts.setInterpolation(new Linear().interpolate (new Array(times, i+1), new Array(data)));
                    }
                }
                // required because we just changed the data
                // is it really required?
                ts.interpolation().update();

                try {
                    final BootstrapError error = new BootstrapError(traits, ts, instrument, i);
                    final double r = solver.solve (error, ts.accuracy(), guess, min, max);
                    // redundant assignment (as it has been already performed
                    // by BootstrapError in solve procedure), but safe
                    data[i] = r;
                } catch (final Exception e) {
                    validCurve = false;
View Full Code Here


     */
    public/* @Rate */double yield(final DayCounter dc, final Compounding comp,
            final Frequency freq,
            /* Real */final double accuracy,
            /* Size */final int maxEvaluations) {
        final Brent solver = new Brent();
        solver.setMaxEvaluations(maxEvaluations);
        final YieldFinder objective = new YieldFinder(notional(settlementDate()), this.cashflows_,
                getDirtyPrice(),
                dc, comp, freq,
                settlementDate());
        return solver.solve(objective, accuracy, 0.02, 0.0, 1.0);

    }
View Full Code Here

            final /* @Size */ int maxEvaluations) {
        if (settlementDate.isNull()) {
            settlementDate = settlementDate();
        }

        final Brent solver = new Brent();
        final double dirtyPrice = cleanPrice + accruedAmount(settlementDate);
        solver.setMaxEvaluations(maxEvaluations);
        final YieldFinder objective = new YieldFinder(
                notional(settlementDate),
                this.cashflows_,
                dirtyPrice,
                dc, comp, freq,
                settlementDate);
        return solver.solve(objective, accuracy, 0.02, 0.0, 1.0);
    }
View Full Code Here

         * if (aggregateCashFlow * nextAggregateCashFlow < 0.0) signChanges++;
         * aggregateCashFlow = nextAggregateCashFlow; } if (signChanges > 1)
         * QL_WARN( "danger of non-unique solution"); }
         */

        final Brent solver = new Brent();
        solver.setMaxEvaluations(maxIterations);
        return solver.solve(new IRRFinder(cashflows, marketPrice, dayCounter, compounding, frequency, date), tolerance, guess,
                guess / 10.0);
    }
View Full Code Here

            final double vMin = -100.0;
            final double vMax = 100.0;
            for (int i=0; i<(timeGrid.size() - 1); i++) {
                final double discountBond = theta.termStructure().currentLink().discount(t.get(i+1));
                final Helper finder = new Helper(i, discountBond, theta, this);
                final Brent s1d = new Brent();
                s1d.setMaxEvaluations(1000);
                value = s1d.solve(finder, 1e-7, value, vMin, vMax);
                // vMin = value - 1.0;
                // vMax = value + 1.0;
                theta.change(value);
            }
        }
View Full Code Here

    // ! Black volatility implied by the model
    public double /* @Volatility */impliedVolatility(final double /* @Real */targetValue, final double /* @Real */accuracy,
            final int /* @Size */maxEvaluations, final double /* @Volatility */minVol, final double /* @Volatility */maxVol){
        final ImpliedVolatilityHelper f = new ImpliedVolatilityHelper(this, targetValue);
        final Brent solver = new Brent();
        solver.setMaxEvaluations(maxEvaluations);
        return solver.solve(f, accuracy, volatility_.currentLink().value(), minVol, maxVol);
    }
View Full Code Here

            final double /* @Real */discountBond = termstructureConsistentModel.termStructure().currentLink().discount(grid.at(i + 1));
            final double /* @Real */xMin = trinomial.underlying(i, 0);
            final double /* @Real */dx = trinomial.dx(i);

            final Helper finder = new BlackKarasinski.Helper(i, xMin, dx, discountBond, numericTree);
            final Brent s1d = new Brent();
            s1d.setMaxEvaluations(1000);
            value = s1d.solve(finder, 1e-7, value, vMin, vMax);
            impl.set(grid.index(i) /* [i] */, value);
            // vMin = value - 10.0;
            // vMax = value + 10.0;
        }
        return numericTree;
View Full Code Here

         * if (aggregateCashFlow * nextAggregateCashFlow < 0.0) signChanges++;
         * aggregateCashFlow = nextAggregateCashFlow; } if (signChanges > 1)
         * QL_WARN( "danger of non-unique solution"); }
         */

        final Brent solver = new Brent();
        solver.setMaxEvaluations(maxIterations);
        return solver.solve(new IRRFinder(cashflows, marketPrice, dayCounter, compounding, frequency, date), tolerance, guess,
                guess / 10.0);
    }
View Full Code Here

                final double /* @Real */c = (i == size_ - 1 ? (1.0 + rate_ * tau) : rate_ * tau);
                lambda.set(i, c * A_.get(i) * Math.exp(-Ba_.get(i) * x));
            }

            final SolvingFunction function = new SolvingFunction(lambda, Bb_);
            final Brent s1d = new Brent();
            s1d.setMaxEvaluations(1000);

            final double /* @Real */yb = s1d.solve(function, 1e-6, 0.00, -100.0, 100.0);
            final double /* @Real */h1 = (yb - muy_) / (sigmay_ * txy) - rhoxy_ * (x - mux_) / (sigmax_ * txy);
            // not sure if evaluate method is equivalent of op overloading -> we have to test it ;-)
            double /* @Real */value = /* phi(-w_*h1) */phi.op(-w_ * h1);

            for (i = 0; i < size_; i++) {
View Full Code Here

        instrument.setupArguments(engine.getArguments());
        engine.getArguments().validate();

        final PriceError f = new PriceError(engine, volQuote, targetValue);

        final Brent solver = new Brent();
        solver.setMaxEvaluations(maxEvaluations);
        final /*@Volatility*/ double guess = (minVol+maxVol)/2.0;
        final /*@Volatility*/ double result = solver.solve(f, accuracy, guess, minVol, maxVol);
        return result;
    }
View Full Code Here

TOP

Related Classes of org.jquantlib.math.solvers1D.Brent

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.