Examples of Brent


Examples of com.nr.min.Brent

   

    // Test Brent
    System.out.println("Testing Brent");

    Brent br = new Brent();
    for (i=0;i<N;i++) {
      a=i;
      b=a+span;
      br.bracket(a,b,this);
      min=br.minimize(this);    // Minimum of bessj0
      localflag = localflag || (abs(Bessj1_Brent(min)) > sbeps);
    }

    globalflag = globalflag || localflag;
    if (localflag) {
View Full Code Here

Examples of com.nr.min.Brent

    ww = new double[ndat];
   
    final double POTN=1.571000,BIG=1.0e30,ACC=1.0e-6;
    final double PI=3.141592653589793238;
    Gamma gam = new Gamma();
    Brent brent = new Brent(ACC);
    Chixy chixy = new Chixy();
    int j;
    double amx,amn,scale,bmn,bmx,d1,d2,r2;
    double[] ang = new double[7];
    double[] ch = new double[7];
    doubleW varx = new doubleW(0);
    doubleW vary = new doubleW(0);
    doubleW dum1 = new doubleW(0);
   
    Moment.avevar(x,dum1,varx);
    Moment.avevar(y,dum1,vary);
    scale=sqrt(varx.val/vary.val);
    for (j=0;j<ndat;j++) {
      xx[j]=x[j];
      yy[j]=y[j]*scale;
      sx[j]=sigx[j];
      sy[j]=sigy[j]*scale;
      ww[j]=sqrt(SQR(sx[j])+SQR(sy[j]));
    }
    Fitab fit = new Fitab(xx,yy,ww);
    b = fit.b;
    offs=ang[0]=0.0;
    ang[1]=atan(b);
    ang[3]=0.0;
    ang[4]=ang[1];
    ang[5]=POTN;
    for (j=3;j<6;j++) ch[j]=chixy.get(ang[j]);
    brent.bracket(ang[0],ang[1],chixy);
    ang[0] = brent.ax; ang[1] = brent.bx; ang[2] = brent.cx;
    ch[0= brent.fa; ch[1= brent.fb; ch[2= brent.fc;
    b = brent.minimize(chixy);
    chi2=chixy.get(b);
    a=aa;
    q=gam.gammq(0.5*(ndat-2),chi2*0.5);
    r2=0.0;
    for (j=0;j<ndat;j++) r2 += ww[j];
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

     */
    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

Examples of org.jquantlib.math.solvers1D.Brent

            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

Examples of org.jquantlib.math.solvers1D.Brent

         * 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

Examples of org.jquantlib.math.solvers1D.Brent

            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

Examples of org.jquantlib.math.solvers1D.Brent

    // ! 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

Examples of org.jquantlib.math.solvers1D.Brent

            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

Examples of org.jquantlib.math.solvers1D.Brent

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