List of usage examples for java.lang Math floor
public static double floor(double a)
From source file:com.opengamma.analytics.financial.interestrate.future.method.BondFutureHullWhiteMethod.java
/** * Computes the future price from the curves used to price the underlying bonds and a Hull-White one factor model. * @param future The future security.//from w ww.j a v a 2 s. co m * @param hwData The curve and Hull-White parameters. * @param nbPoint The number of point in the numerical cross estimation. * @return The future price. */ public double price(final BondFuture future, final HullWhiteOneFactorPiecewiseConstantDataBundle hwData, final int nbPoint) { Validate.notNull(future, "Future"); Validate.notNull(hwData, "Hull-White data bundle"); final int nbBond = future.getDeliveryBasket().length; final YieldAndDiscountCurve bndCurve = hwData .getCurve(future.getDeliveryBasket()[0].getDiscountingCurveName()); final double expiry = future.getNoticeLastTime(); final double delivery = future.getDeliveryLastTime(); final double dfdelivery = bndCurve.getDiscountFactor(delivery); // Constructing non-homogeneous point series for the numerical estimations. final int nbPtWing = ((int) Math.floor(nbPoint / 20.)); // Number of point on each wing. final int nbPtCenter = nbPoint - 2 * nbPtWing; final double prob = 1.0 / (2.0 * nbPtCenter); final double xStart = NORMAL.getInverseCDF(prob); final double[] x = new double[nbPoint]; for (int loopwing = 0; loopwing < nbPtWing; loopwing++) { x[loopwing] = xStart * (1.0 + (nbPtWing - loopwing) / 2.0); x[nbPoint - 1 - loopwing] = -xStart * (1.0 + (nbPtWing - loopwing) / 2.0); } for (int loopcent = 0; loopcent < nbPtCenter; loopcent++) { x[nbPtWing + loopcent] = xStart + loopcent * (-2.0 * xStart) / (nbPtCenter - 1); } // Figures for each bond final double[][] cfTime = new double[nbBond][]; final double[][] df = new double[nbBond][]; final double[][] alpha = new double[nbBond][]; final double[][] beta = new double[nbBond][]; final double[][] cfaAdjusted = new double[nbBond][]; final double[] e = new double[nbBond]; final double[][] pv = new double[nbPoint][nbBond]; final AnnuityPaymentFixed[] cf = new AnnuityPaymentFixed[nbBond]; for (int loopbnd = 0; loopbnd < nbBond; loopbnd++) { cf[loopbnd] = future.getDeliveryBasket()[loopbnd].accept(CFEC, hwData); final int nbCf = cf[loopbnd].getNumberOfPayments(); cfTime[loopbnd] = new double[nbCf]; df[loopbnd] = new double[nbCf]; alpha[loopbnd] = new double[nbCf]; beta[loopbnd] = new double[nbCf]; cfaAdjusted[loopbnd] = new double[nbCf]; for (int loopcf = 0; loopcf < nbCf; loopcf++) { cfTime[loopbnd][loopcf] = cf[loopbnd].getNthPayment(loopcf).getPaymentTime(); df[loopbnd][loopcf] = bndCurve.getDiscountFactor(cfTime[loopbnd][loopcf]); alpha[loopbnd][loopcf] = MODEL.alpha(hwData.getHullWhiteParameter(), 0.0, expiry, delivery, cfTime[loopbnd][loopcf]); beta[loopbnd][loopcf] = MODEL.futuresConvexityFactor(hwData.getHullWhiteParameter(), expiry, cfTime[loopbnd][loopcf], delivery); cfaAdjusted[loopbnd][loopcf] = df[loopbnd][loopcf] / dfdelivery * beta[loopbnd][loopcf] * cf[loopbnd].getNthPayment(loopcf).getAmount() / future.getConversionFactor()[loopbnd]; for (int looppt = 0; looppt < nbPoint; looppt++) { pv[looppt][loopbnd] += cfaAdjusted[loopbnd][loopcf] * Math.exp(-alpha[loopbnd][loopcf] * alpha[loopbnd][loopcf] / 2.0 - alpha[loopbnd][loopcf] * x[looppt]); } } e[loopbnd] = future.getDeliveryBasket()[loopbnd].getAccruedInterest() / future.getConversionFactor()[loopbnd]; for (int looppt = 0; looppt < nbPoint; looppt++) { pv[looppt][loopbnd] -= e[loopbnd]; } } // Minimum: create a list of index of the CTD in each interval and a first estimate of the crossing point (x[]). final double[] pvMin = new double[nbPoint]; final int[] indMin = new int[nbPoint]; for (int looppt = 0; looppt < nbPoint; looppt++) { pvMin[looppt] = Double.POSITIVE_INFINITY; for (int loopbnd = 0; loopbnd < nbBond; loopbnd++) { if (pv[looppt][loopbnd] < pvMin[looppt]) { pvMin[looppt] = pv[looppt][loopbnd]; indMin[looppt] = loopbnd; } } } final ArrayList<Double> refx = new ArrayList<>(); final ArrayList<Integer> ctd = new ArrayList<>(); int lastInd = indMin[0]; ctd.add(indMin[0]); for (int looppt = 1; looppt < nbPoint; looppt++) { if (indMin[looppt] != lastInd) { ctd.add(indMin[looppt]); lastInd = indMin[looppt]; refx.add(x[looppt]); } } // Sum on each interval final int nbInt = ctd.size(); final double[] kappa = new double[nbInt - 1]; double price = 0.0; if (nbInt == 1) { for (int loopcf = 0; loopcf < cfaAdjusted[ctd.get(0)].length; loopcf++) { price += cfaAdjusted[ctd.get(0)][loopcf]; } price -= e[ctd.get(0)]; } else { // The intersections final BracketRoot bracketer = new BracketRoot(); final double accuracy = 1.0E-8; final RidderSingleRootFinder rootFinder = new RidderSingleRootFinder(accuracy); for (int loopint = 1; loopint < nbInt; loopint++) { final BondDifference cross = new BondDifference(cfaAdjusted[ctd.get(loopint - 1)], alpha[ctd.get(loopint - 1)], e[ctd.get(loopint - 1)], cfaAdjusted[ctd.get(loopint)], alpha[ctd.get(loopint)], e[ctd.get(loopint)]); final double[] range = bracketer.getBracketedPoints(cross, refx.get(loopint - 1) - 0.01, refx.get(loopint - 1) + 0.01); kappa[loopint - 1] = rootFinder.getRoot(cross, range[0], range[1]); } // From -infinity to first cross. for (int loopcf = 0; loopcf < cfaAdjusted[ctd.get(0)].length; loopcf++) { price += cfaAdjusted[ctd.get(0)][loopcf] * NORMAL.getCDF(kappa[0] + alpha[ctd.get(0)][loopcf]); } price -= e[ctd.get(0)] * NORMAL.getCDF(kappa[0]); // Between cross for (int loopint = 1; loopint < nbInt - 1; loopint++) { for (int loopcf = 0; loopcf < cfaAdjusted[ctd.get(loopint)].length; loopcf++) { price += cfaAdjusted[ctd.get(loopint)][loopcf] * (NORMAL.getCDF(kappa[loopint] + alpha[ctd.get(loopint)][loopcf]) - NORMAL.getCDF(kappa[loopint - 1] + alpha[ctd.get(loopint)][loopcf])); } price -= e[ctd.get(loopint)] * (NORMAL.getCDF(kappa[loopint]) - NORMAL.getCDF(kappa[loopint - 1])); } // From last cross to +infinity for (int loopcf = 0; loopcf < cfaAdjusted[ctd.get(nbInt - 1)].length; loopcf++) { price += cfaAdjusted[ctd.get(nbInt - 1)][loopcf] * (1.0 - NORMAL.getCDF(kappa[nbInt - 2] + alpha[ctd.get(nbInt - 1)][loopcf])); } price -= e[ctd.get(nbInt - 1)] * (1 - NORMAL.getCDF(kappa[nbInt - 2])); } return price; }
From source file:com.miz.mizuu.fragments.WebVideoFragment.java
@Override public void onViewCreated(View v, Bundle savedInstanceState) { super.onViewCreated(v, savedInstanceState); mProgressBar = (ProgressBar) v.findViewById(R.id.progress); if (mVideos.size() > 0) mProgressBar.setVisibility(View.GONE); // Hack to remove the ProgressBar on orientation change mAdapter = new ImageAdapter(getActivity()); mGridView = (ObservableGridView) v.findViewById(R.id.gridView); mGridView.setClipToPadding(false);/* www . j ava 2 s . c om*/ mGridView.setAdapter(mAdapter); mGridView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { if (mAdapter.getNumColumns() == 0) { final int numColumns = (int) Math .floor(mGridView.getWidth() / (mImageThumbSize + mImageThumbSpacing)); mGridView.setColumnWidth(mImageThumbSize); if (numColumns > 0) { mAdapter.setNumColumns(numColumns); } } } }); mGridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { if (YouTubeApiServiceUtil.isYouTubeApiServiceAvailable(getActivity()) .equals(YouTubeInitializationResult.SUCCESS)) { Intent intent = YouTubeStandalonePlayer.createVideoIntent(getActivity(), MizLib.getYouTubeApiKey(getActivity()), mVideos.get(arg2).getId(), 0, false, true); startActivity(intent); } else { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("http://www.youtube.com/watch?v=" + mVideos.get(arg2).getId())); startActivity(intent); } } }); }
From source file:eu.matejkormuth.rpgdavid.starving.Region.java
public int getMaxXFloor() { return (int) Math.floor(this.maxVector.getX()); }
From source file:org.wallerlab.yoink.cube.service.CubeBuilderImpl.java
private void setNumberOfSteps(Cube cube, double[] xyzMinimumOfCube, double[] xyzMaximumOfCube) { int[] numberOfXYZSteps = new int[3]; numberOfXYZSteps[0] = (int) Math .floor(((xyzMaximumOfCube[0] - xyzMinimumOfCube[0]) / cube.getXyzStepSize()[0]) + 1); numberOfXYZSteps[1] = (int) Math .floor(((xyzMaximumOfCube[1] - xyzMinimumOfCube[1]) / cube.getXyzStepSize()[1]) + 1); numberOfXYZSteps[2] = (int) Math .floor(((xyzMaximumOfCube[2] - xyzMinimumOfCube[2]) / cube.getXyzStepSize()[2]) + 1); cube.setNumberOfXYZSteps(numberOfXYZSteps); cube.setSize(numberOfXYZSteps[0] * numberOfXYZSteps[1] * numberOfXYZSteps[2]); }
From source file:es.udc.gii.common.eaf.benchmark.multiobjective.wfg.Wfg_Objective.java
protected double b_param(double y, double u, double A, double B, double C) { double v = A - (1.0 - 2.0 * u) * Math.abs(Math.floor(0.5 - u) + A); return correct_to_01(Math.pow(y, B + (C - B) * v), EPSILON); }
From source file:com.l3.info.magenda.emplois_du_temps.EmploisDuTemps.java
public void writeInPdf(String path) throws FileNotFoundException { File file = new File(path); file.getParentFile().mkdirs();/*from www . j a v a2 s . c o m*/ //new FullDottedLine().manipulatePdf(path); com.itextpdf.kernel.pdf.PdfDocument pdfDoc = new com.itextpdf.kernel.pdf.PdfDocument( new com.itextpdf.kernel.pdf.PdfWriter(path)); // Taille feuille A4 mode paysage (842, 595) com.itextpdf.kernel.geom.PageSize pageSize = new com.itextpdf.kernel.geom.PageSize(842, 595); pdfDoc.setDefaultPageSize(pageSize); java.awt.Dimension taille_totale_semaine = getSemaine(48).getSize(); int hauteur_panel_semaine = getSemaine(48).getSize().height; int largeur_panel_semaine = getSemaine(48).getSize().width; double nbPages = Math.floor((hauteur_panel_semaine / pageSize.getHeight())) + 1; System.out.println("taille sem 48 : " + taille_totale_semaine); System.out.println("Hauteur sem 48 : " + hauteur_panel_semaine); System.out.println("Largeur sem 48 : " + largeur_panel_semaine); System.out.println("nombre de pages : " + nbPages); com.itextpdf.kernel.pdf.canvas.PdfCanvas canvas; // Cration des pages for (int i = 0; i < nbPages; i++) { canvas = new com.itextpdf.kernel.pdf.canvas.PdfCanvas(pdfDoc.addNewPage()); Component[] comp = getSemaine(48).getComponents(); /*for (float x = 0; x < pageSize.getWidth(); ) { for (float y = 0; y < pageSize.getHeight(); ) { canvas.circle(x, y, 1f); y += 72f; } x += 72f; }*/ canvas.fill(); } pdfDoc.close(); /* File file = new File(path); file.getParentFile().mkdirs(); //Initialize PDF writer com.itextpdf.kernel.pdf.PdfWriter writer = new com.itextpdf.kernel.pdf.PdfWriter(path); //Initialize PDF document com.itextpdf.kernel.pdf.PdfDocument pdf = new com.itextpdf.kernel.pdf.PdfDocument(writer); com.itextpdf.kernel.pdf.PdfPage page = pdf.addNewPage(); com.itextpdf.kernel.pdf.PdfArray lineEndings = new com.itextpdf.kernel.pdf.PdfArray(); lineEndings.add(new com.itextpdf.kernel.pdf.PdfName("Diamond")); lineEndings.add(new com.itextpdf.kernel.pdf.PdfName("Diamond")); //Create line annotation with inside caption com.itextpdf.kernel.pdf.annot.PdfAnnotation annotation = new com.itextpdf.kernel.pdf.annot.PdfLineAnnotation( new com.itextpdf.kernel.geom.Rectangle(0, 0), new float[]{20, 790, page.getPageSize().getWidth() - 20, 790}) .setLineEndingStyles((lineEndings)) .setContentsAsCaption(true) .setTitle(new com.itextpdf.kernel.pdf.PdfString("iText")) .setContents("The example of line annotation") .setColor(com.itextpdf.kernel.color.Color.BLUE); page.addAnnotation(annotation); //Close document pdf.close(); */ }
From source file:edu.umn.cs.spatialHadoop.indexing.GridPartitioner.java
@Override public void overlapPartitions(Shape shape, ResultCollector<Integer> matcher) { if (shape == null) return;/*from w w w. jav a 2 s . com*/ Rectangle shapeMBR = shape.getMBR(); if (shapeMBR == null) return; int col1, col2, row1, row2; col1 = (int) Math.floor((shapeMBR.x1 - x) / tileWidth); col2 = (int) Math.ceil((shapeMBR.x2 - x) / tileWidth); row1 = (int) Math.floor((shapeMBR.y1 - y) / tileHeight); row2 = (int) Math.ceil((shapeMBR.y2 - y) / tileHeight); if (col1 < 0) col1 = 0; if (row1 < 0) row1 = 0; for (int col = col1; col < col2; col++) for (int row = row1; row < row2; row++) matcher.collect(getCellNumber(col, row)); }
From source file:eu.matejkormuth.rpgdavid.starving.Region.java
public int getMaxYFloor() { return (int) Math.floor(this.maxVector.getY()); }
From source file:eu.matejkormuth.rpgdavid.starving.Region.java
public int getMaxZFloor() { return (int) Math.floor(this.maxVector.getZ()); }
From source file:de.biomedical_imaging.ij.nanotrackj.WalkerMethodEstimator.java
/** * /*from w ww . jav a 2s . c om*/ * @param data Containes the mean squared displacement and the Tracklength for each track. data[i][0] = MSD data[i][1] = Tracklength * @param temp Temperature of the suspension in kelvin * @param visk Viscosity of the suspension * @param framerate * @param maxdiameter The maximum diameter for the estimation. 0 = Maximum Diameter is estimated automatically */ public WalkerMethodEstimator(double[][] data, double temp, double visk, double framerate, int maxdiameter) { this.temp = temp; this.visk = visk; this.framerate = 1.0 / framerate; this.data = data; kMin = Integer.MAX_VALUE; kMax = Integer.MIN_VALUE; msdMin = Double.MAX_VALUE; msdMax = Double.MIN_VALUE; double convFact = Math.pow(10, -10); for (int i = 0; i < data.length; i++) { //10^-10 cm^2 -> cm^2 this.data[i][0] = this.data[i][0] * convFact; //- 4*17.562862475*17.562862475*Math.pow(10, -7)*Math.pow(10, -7); if (this.data[i][0] > msdMax) { msdMax = this.data[i][0]; } if (this.data[i][0] < msdMin) { msdMin = this.data[i][0]; } if (this.data[i][1] > kMax) { kMax = (int) this.data[i][1]; } if (this.data[i][1] < kMin) { kMin = (int) this.data[i][1]; } //IJ.log("MSD " + this.data[i][0]); } logMapK = new double[kMax + 1]; logMapGammaK = new double[kMax + 1]; java.util.Arrays.fill(logMapK, Double.NaN); java.util.Arrays.fill(logMapGammaK, Double.NaN); maxRadiusInNm = maxdiameter / 2.0; if (maxdiameter == 0) { maxRadiusInNm = NanoTrackJ_.getInstance() .diffCoeffToDiameter((msdMin * Math.pow(10, 10)) / 4 * (framerate)); maxRadiusInNm = (maxRadiusInNm + 1) / 2; } binNumber = (int) (maxRadiusInNm / binSizeInnm); histBinNumber = (int) Math.ceil(Math.sqrt(data.length)); deltaB = msdMax / histBinNumber; histogramMSD = new double[histBinNumber]; java.util.Arrays.fill(histogramMSD, 0); Nk = new int[kMax + 1]; java.util.Arrays.fill(Nk, 0); for (int i = 0; i < data.length; i++) { int index = (int) this.data[i][1]; Nk[index]++; int index2 = (int) Math.floor(data[i][0] / deltaB - 0.001); histogramMSD[index2]++; } }