Examples of Brent


Examples of org.jquantlib.math.solvers1D.Brent

                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

Examples of org.jquantlib.math.solvers1D.Brent

        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

Examples of org.jquantlib.math.solvers1D.Brent

                              final Compounding comp,
                              final Frequency freq,
                              final /* Real */double accuracy,
                              final /* Size */int maxEvaluations) {
     
        final Brent solver = new Brent();
        solver.setMaxEvaluations(maxEvaluations);
        final YieldFinder objective = new YieldFinder(notional(settlementDate()), cashflows_,
                dirtyPrice(),
                dc, comp, freq,
                settlementDate());
        return solver.solve(objective, accuracy, 0.02, 0.0, 1.0);
    }
View Full Code Here

Examples of org.jquantlib.math.solvers1D.Brent

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

        final Brent solver = new Brent();
        solver.setMaxEvaluations(maxEvaluations);
        final double dirtyPrice = cleanPrice + accruedAmount(settlementDate);
        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

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

Examples of org.jquantlib.math.solvers1D.Brent

            }

        };

        final double accuracy = 1.0e-15;
        final Brent brent = new Brent();

        double soln = brent.solve(square, accuracy, 0.01, 0, 2);

        // assertEquals(1.0, soln, accuracy);
        if (Math.abs(1.0 - soln) > accuracy) {
            fail("expected: 1.0 but was: " + (soln - accuracy));
        }

        // assertEquals(10, brent.getNumEvaluations());
        if (brent.getNumEvaluations() != 10) {
            fail("expected: 10" + " but was: " + brent.getNumEvaluations());
        }

        soln = brent.solve(square, accuracy, 0.01, 0.1);

        // assertEquals(1.0, soln,accuracy);
        if (Math.abs(1.0 - soln) > accuracy) {
            fail("expected: 1.0 but was: " + (soln - accuracy));
        }

        // assertEquals(13, brent.getNumEvaluations());
        if (brent.getNumEvaluations() != 13) {
            fail("expected: 13" + " but was: " + brent.getNumEvaluations());
        }

    }
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.