List of usage examples for java.lang Math signum
public static float signum(float f)
From source file:de.christianseipl.utilities.maputils.MapMath.java
/** * Erzeugt eine neue Map mit den Vorzeichen der Ursprungsmap. * /* www . j a v a2 s. c om*/ * @see Math#signum(double) * @param <K> ein beliebiger Objekttyp * @param _map Die Ursprungsmap * @return Eine neue Map mit den Absolutwerten */ public static <K> Map<K, Double> signum(Map<? extends K, ? extends Number> _map) { return operateOnMap(_map, new NumberTransformer<K, Double>() { @Override public Double transform(K _key, Number _number) { return Math.signum(_number.doubleValue()); } }); }
From source file:io.github.malapert.jwcs.JWcs.java
/** * Computes CD matrix from CDELT[] and CROTA. * * * The computation is realized as follows: * <pre>// w w w . j a va 2 s . c o m * cos0 = cos(crota) * sin0 = sin(crota) * cd11 = cdelt1 * cos0 * cd12 = abs(cdelt2) * signum(cdelt1) * sin0 * cd21 = -abs(cdelt1) * signum(cdelt2) * sin0; * cd22 = cdelt2 * cos0; * </pre> * * @param cdelt increment of position * @param crota rotation * @return the cd matrix as array */ protected static final double[][] computeCdFromCdelt(double[] cdelt, double crota) { final double cos0 = Math.cos(Math.toRadians(crota)); final double sin0 = Math.sin(Math.toRadians(crota)); double cd11 = cdelt[0] * cos0; double cd12 = Math.abs(cdelt[1]) * Math.signum(cdelt[0]) * sin0; double cd21 = -Math.abs(cdelt[0]) * Math.signum(cdelt[1]) * sin0; double cd22 = cdelt[1] * cos0; double[][] array = { { cd11, cd12 }, { cd21, cd22 } }; return array; }
From source file:org.vast.stt.provider.tiling.TiledMapProvider.java
protected double yToLat(double y) { double lat = 0; if (Math.abs(y) < Math.PI - (1e-4)) //lat = 2 * Math.atan(Math.exp(y)) - Math.PI/2; lat = Math.PI / 2 - 2 * Math.atan(Math.exp(-y)); else/*from ww w. j a v a2s.co m*/ lat = Math.signum(y) * Math.PI / 2; return lat; }
From source file:com.facebook.presto.operator.scalar.MathFunctions.java
@Description("round to integer by dropping digits after decimal point") @ScalarFunction//from w ww . ja v a 2 s. c o m @SqlType(StandardTypes.REAL) public static long truncate(@SqlType(StandardTypes.REAL) long num) { float numInFloat = intBitsToFloat((int) num); return floatToRawIntBits((float) (Math.signum(numInFloat) * Math.floor(Math.abs(numInFloat)))); }
From source file:org.apache.sysml.runtime.functionobjects.Builtin.java
public double execute(double in) throws DMLRuntimeException { switch (bFunc) { case SIN:/*from www . java 2s.c o m*/ return FASTMATH ? FastMath.sin(in) : Math.sin(in); case COS: return FASTMATH ? FastMath.cos(in) : Math.cos(in); case TAN: return FASTMATH ? FastMath.tan(in) : Math.tan(in); case ASIN: return FASTMATH ? FastMath.asin(in) : Math.asin(in); case ACOS: return FASTMATH ? FastMath.acos(in) : Math.acos(in); case ATAN: return Math.atan(in); //faster in Math case CEIL: return FASTMATH ? FastMath.ceil(in) : Math.ceil(in); case FLOOR: return FASTMATH ? FastMath.floor(in) : Math.floor(in); case LOG: return FASTMATH ? FastMath.log(in) : Math.log(in); case LOG_NZ: return (in == 0) ? 0 : FASTMATH ? FastMath.log(in) : Math.log(in); case ABS: return Math.abs(in); //no need for FastMath case SIGN: return FASTMATH ? FastMath.signum(in) : Math.signum(in); case SQRT: return Math.sqrt(in); //faster in Math case EXP: return FASTMATH ? FastMath.exp(in) : Math.exp(in); case ROUND: return Math.round(in); //no need for FastMath case PLOGP: if (in == 0.0) return 0.0; else if (in < 0) return Double.NaN; else return (in * (FASTMATH ? FastMath.log(in) : Math.log(in))); case SPROP: //sample proportion: P*(1-P) return in * (1 - in); case SIGMOID: //sigmoid: 1/(1+exp(-x)) return FASTMATH ? 1 / (1 + FastMath.exp(-in)) : 1 / (1 + Math.exp(-in)); case SELP: //select positive: x*(x>0) return (in > 0) ? in : 0; default: throw new DMLRuntimeException("Builtin.execute(): Unknown operation: " + bFunc); } }
From source file:com.opengamma.analytics.math.interpolation.MonotonicityPreservingQuinticSplineInterpolator.java
/** * First derivatives are modified such that cubic interpolant has the same sign as linear interpolator * @param yValues /*from ww w. ja v a2 s .c om*/ * @param intervals * @param slopes * @param initialFirst * @return first derivative */ private double[] firstDerivativeCalculator(final double[] yValues, final double[] intervals, final double[] slopes, final double[] initialFirst) { final int nDataPts = yValues.length; double[] res = new double[nDataPts]; res[0] = Math.max(Math.min(Math.max(0., initialFirst[0]), 5. * Math.abs(slopes[0])), -5. * Math.abs(slopes[0])); res[nDataPts - 1] = Math.max( Math.min(Math.max(0., initialFirst[nDataPts - 2]), 5. * Math.abs(slopes[nDataPts - 2])), -5. * Math.abs(slopes[nDataPts - 2])); for (int i = 1; i < nDataPts - 1; ++i) { final double sigma = slopes[i - 1] * slopes[i] < 0 ? Math.signum(initialFirst[i]) : 0.; if (sigma >= 0.) { res[i] = Math.min(Math.max(0., initialFirst[i]), 5. * Math.min(Math.abs(slopes[i - 1]), Math.abs(slopes[i]))); } else { res[i] = Math.max(Math.min(0., initialFirst[i]), -5. * Math.min(Math.abs(slopes[i - 1]), Math.abs(slopes[i]))); } } return res; }
From source file:com.opengamma.analytics.financial.interestrate.swaption.method.SwaptionPhysicalFixedIborLMMDDMethod.java
/** * Computes the present value sensitivity to LMM parameters of the Physical delivery swaption. * @param swaption The swaption./*ww w . j a v a 2s . com*/ * @param lmmBundle The LMM parameters and the curves. * @return The present value. */ public double[][] presentValueLMMSensitivity(final SwaptionPhysicalFixedIbor swaption, final LiborMarketModelDisplacedDiffusionDataBundle lmmBundle) { // 1. Swaption CFE preparation AnnuityPaymentFixed cfe = CFEC.visit(swaption.getUnderlyingSwap(), lmmBundle); YieldAndDiscountCurve dsc = lmmBundle.getCurve(cfe.getDiscountCurve()); int nbCFInit = cfe.getNumberOfPayments(); double multFact = Math.signum(cfe.getNthPayment(0).getAmount()); boolean isCall = (cfe.getNthPayment(0).getAmount() < 0); double[] cftInit = new double[nbCFInit]; double[] cfaInit = new double[nbCFInit]; for (int loopcf = 0; loopcf < nbCFInit; loopcf++) { cftInit[loopcf] = cfe.getNthPayment(loopcf).getPaymentTime(); cfaInit[loopcf] = cfe.getNthPayment(loopcf).getAmount() * -multFact; } double timeToExpiry = swaption.getTimeToExpiry(); // 2. Model data int nbFactor = lmmBundle.getLmmParameter().getNbFactor(); double[][] volLMM = lmmBundle.getLmmParameter().getVolatility(); double[] timeLMM = lmmBundle.getLmmParameter().getIborTime(); // 3. Link cfe dates to lmm int[] indCFDate = new int[nbCFInit]; int indStart = nbCFInit - 1; int indEnd = 0; for (int loopcf = 0; loopcf < nbCFInit; loopcf++) { indCFDate[loopcf] = Arrays.binarySearch(timeLMM, cftInit[loopcf]); if (indCFDate[loopcf] < 0) { if (timeLMM[-indCFDate[loopcf] - 1] - cftInit[loopcf] < TIME_TOLERANCE) { indCFDate[loopcf] = -indCFDate[loopcf] - 1; } else { if (cftInit[loopcf] - timeLMM[-indCFDate[loopcf] - 2] < TIME_TOLERANCE) { indCFDate[loopcf] = -indCFDate[loopcf] - 2; } else { Validate.isTrue(true, "Instrument time incompatible with LMM"); } } } if (indCFDate[loopcf] < indStart) { indStart = indCFDate[loopcf]; } if (indCFDate[loopcf] > indEnd) { indEnd = indCFDate[loopcf]; } } int nbCF = indEnd - indStart + 1; double[] cfa = new double[nbCF]; for (int loopcf = 0; loopcf < nbCFInit; loopcf++) { cfa[indCFDate[loopcf] - indStart] = cfaInit[loopcf]; } double[] cft = new double[nbCF]; System.arraycopy(timeLMM, indStart, cft, 0, nbCF); double[] dfLMM = new double[nbCF]; for (int loopcf = 0; loopcf < nbCF; loopcf++) { dfLMM[loopcf] = dsc.getDiscountFactor(cft[loopcf]); } double[][] gammaLMM = new double[nbCF - 1][nbFactor]; double[] deltaLMM = new double[nbCF - 1]; System.arraycopy(lmmBundle.getLmmParameter().getAccrualFactor(), indStart, deltaLMM, 0, nbCF - 1); double[] aLMM = new double[nbCF - 1]; System.arraycopy(lmmBundle.getLmmParameter().getDisplacement(), indStart, aLMM, 0, nbCF - 1); double[] liborLMM = new double[nbCF - 1]; double amr = lmmBundle.getLmmParameter().getMeanReversion(); for (int loopcf = 0; loopcf < nbCF - 1; loopcf++) { gammaLMM[loopcf] = volLMM[indStart + loopcf]; liborLMM[loopcf] = (dfLMM[loopcf] / dfLMM[loopcf + 1] - 1.0d) / deltaLMM[loopcf]; } // TODO: 4. cfe modification (for roller coasters) double[] cfaMod = new double[nbCF + 1]; double cfaMod0 = cfa[0]; cfaMod[0] = cfaMod0; // modified strike cfaMod[1] = 0.0; System.arraycopy(cfa, 1, cfaMod, 2, nbCF - 1); // 5. Pricing algorithm double[] p0 = new double[nbCF]; double[] dP = new double[nbCF]; double b0 = 0; for (int loopcf = 0; loopcf < nbCF; loopcf++) { p0[loopcf] = dfLMM[loopcf] / dfLMM[0]; dP[loopcf] = cfaMod[loopcf + 1] * p0[loopcf]; b0 += dP[loopcf]; } double bK = -cfaMod0; double bM = (b0 + bK) / 2.0d; double[] rate0Ratio = new double[nbCF - 1]; double[][] mu0 = new double[nbCF - 1][nbFactor]; for (int loopcf = 0; loopcf < nbCF - 1; loopcf++) { rate0Ratio[loopcf] = (liborLMM[loopcf] + aLMM[loopcf]) / (liborLMM[loopcf] + 1 / deltaLMM[loopcf]); } for (int loopfact = 0; loopfact < nbFactor; loopfact++) { mu0[0][loopfact] = rate0Ratio[0] * gammaLMM[0][loopfact]; } for (int loopcf = 1; loopcf < nbCF - 1; loopcf++) { for (int loopfact = 0; loopfact < nbFactor; loopfact++) { mu0[loopcf][loopfact] = mu0[loopcf - 1][loopfact] + rate0Ratio[loopcf] * gammaLMM[loopcf][loopfact]; } } double meanReversionImpact = (Math.exp(2.0d * amr * timeToExpiry) - 1.0d) / (2.0d * amr); double[] tau = new double[nbCF]; double[] tau2 = new double[nbCF]; for (int loopcf = 0; loopcf < nbCF - 1; loopcf++) { for (int loopfact = 0; loopfact < nbFactor; loopfact++) { tau2[loopcf + 1] += mu0[loopcf][loopfact] * mu0[loopcf][loopfact]; } tau2[loopcf + 1] = tau2[loopcf + 1] * meanReversionImpact; tau[loopcf + 1] = Math.sqrt(tau2[loopcf + 1]); } double sumNum = -bM; double sumDen = 0; for (int loopcf = 0; loopcf < nbCF; loopcf++) { sumNum += dP[loopcf] - dP[loopcf] * tau2[loopcf] / 2.0; sumDen += dP[loopcf] * tau[loopcf]; } double xBar = sumNum / sumDen; double[] pM = new double[nbCF]; for (int loopcf = 0; loopcf < nbCF; loopcf++) { pM[loopcf] = p0[loopcf] * (1 - xBar * tau[loopcf] - tau2[loopcf] / 2.0); } double[] liborM = new double[nbCF - 1]; double[] alphaM = new double[nbCF]; for (int loopcf = 0; loopcf < nbCF - 1; loopcf++) { liborM[loopcf] = (pM[loopcf] / pM[loopcf + 1] - 1.0d) / deltaLMM[loopcf]; } for (int loopcf = 0; loopcf < nbCF; loopcf++) { alphaM[loopcf] = cfaMod[loopcf + 1] * pM[loopcf] / bM; } double[] rateMRatio = new double[nbCF - 1]; double[][] muM = new double[nbCF - 1][nbFactor]; for (int loopcf = 0; loopcf < nbCF - 1; loopcf++) { rateMRatio[loopcf] = (liborM[loopcf] + aLMM[loopcf]) / (liborM[loopcf] + 1 / deltaLMM[loopcf]); } for (int loopfact = 0; loopfact < nbFactor; loopfact++) { muM[0][loopfact] = rateMRatio[0] * gammaLMM[0][loopfact]; } for (int loopcf = 1; loopcf < nbCF - 1; loopcf++) { for (int loopfact = 0; loopfact < nbFactor; loopfact++) { muM[loopcf][loopfact] = muM[loopcf - 1][loopfact] + rateMRatio[loopcf] * gammaLMM[loopcf][loopfact]; } } double normSigmaM = 0; double[] sigmaM = new double[nbFactor]; for (int loopfact = 0; loopfact < nbFactor; loopfact++) { for (int loopcf = 0; loopcf < nbCF - 1; loopcf++) { sigmaM[loopfact] += alphaM[loopcf + 1] * muM[loopcf][loopfact]; } normSigmaM += sigmaM[loopfact] * sigmaM[loopfact]; } double impliedBlackVol = Math.sqrt(normSigmaM * meanReversionImpact); EuropeanVanillaOption option = new EuropeanVanillaOption(bK, 1, isCall); final BlackPriceFunction blackFunction = new BlackPriceFunction(); final BlackFunctionData dataBlack = new BlackFunctionData(b0, 1.0, impliedBlackVol); double[] blkAdjoint = blackFunction.getPriceAdjoint(option, dataBlack); // Backward sweep double pvBar = 1.0; double impliedBlackVolBar = dfLMM[0] * blkAdjoint[2] * pvBar; double normSigmaMBar = meanReversionImpact / (2.0 * impliedBlackVol) * impliedBlackVolBar; double[] sigmaMBar = new double[nbFactor]; for (int loopfact = 0; loopfact < nbFactor; loopfact++) { sigmaMBar[loopfact] = 2 * sigmaM[loopfact] * normSigmaMBar; } double[][] muMBar = new double[nbCF - 1][nbFactor]; for (int loopcf = 0; loopcf < nbCF - 1; loopcf++) { for (int loopfact = 0; loopfact < nbFactor; loopfact++) { muMBar[loopcf][loopfact] = alphaM[loopcf + 1] * sigmaMBar[loopfact]; } } for (int loopcf = nbCF - 3; loopcf >= 0; loopcf--) { for (int loopfact = 0; loopfact < nbFactor; loopfact++) { muMBar[loopcf][loopfact] += muMBar[loopcf + 1][loopfact]; } } double[] rateMRatioBar = new double[nbCF - 1]; for (int loopcf = 0; loopcf < nbCF - 1; loopcf++) { for (int loopfact = 0; loopfact < nbFactor; loopfact++) { rateMRatioBar[loopcf] += gammaLMM[loopcf][loopfact] * muMBar[loopcf][loopfact]; } } double[] alphaMBar = new double[nbCF]; for (int loopfact = 0; loopfact < nbFactor; loopfact++) { for (int loopcf = 0; loopcf < nbCF - 1; loopcf++) { alphaMBar[loopcf + 1] += muM[loopcf][loopfact] * sigmaMBar[loopfact]; } } double[] liborMBar = new double[nbCF - 1]; for (int loopcf = 0; loopcf < nbCF - 1; loopcf++) { liborMBar[loopcf] = ((liborM[loopcf] + 1 / deltaLMM[loopcf]) - (liborM[loopcf] + aLMM[loopcf])) / ((liborM[loopcf] + 1 / deltaLMM[loopcf]) * (liborM[loopcf] + 1 / deltaLMM[loopcf])) * rateMRatioBar[loopcf]; } double[] pMBar = new double[nbCF]; for (int loopcf = 0; loopcf < nbCF - 1; loopcf++) { pMBar[loopcf] += 1.0 / pM[loopcf + 1] / deltaLMM[loopcf] * liborMBar[loopcf]; pMBar[loopcf + 1] += -pM[loopcf] / (pM[loopcf + 1] * pM[loopcf + 1]) / deltaLMM[loopcf] * liborMBar[loopcf]; } for (int loopcf = 0; loopcf < nbCF; loopcf++) { pMBar[loopcf] += cfaMod[loopcf + 1] / bM * alphaMBar[loopcf]; } double xBarBar = 0.0; for (int loopcf = 0; loopcf < nbCF; loopcf++) { xBarBar += -p0[loopcf] * tau[loopcf] * pMBar[loopcf]; } double sumNumBar = 1.0 / sumDen * xBarBar; double sumDenBar = -sumNum / (sumDen * sumDen) * xBarBar; double[] tauBar = new double[nbCF]; for (int loopcf = 0; loopcf < nbCF; loopcf++) { tauBar[loopcf] = -p0[loopcf] * xBar * pMBar[loopcf]; } for (int loopcf = 0; loopcf < nbCF; loopcf++) { tauBar[loopcf] += dP[loopcf] * sumDenBar; } double[] tau2Bar = new double[nbCF]; for (int loopcf = 0; loopcf < nbCF; loopcf++) { tau2Bar[loopcf] = -p0[loopcf] / 2.0 * pMBar[loopcf]; } for (int loopcf = 0; loopcf < nbCF; loopcf++) { tau2Bar[loopcf] += -dP[loopcf] / 2.0 * sumNumBar; } for (int loopcf = 0; loopcf < nbCF - 1; loopcf++) { tau2Bar[loopcf + 1] += 1 / 2.0 / tau[loopcf + 1] * tauBar[loopcf + 1]; } double[][] mu0Bar = new double[nbCF - 1][nbFactor]; for (int loopcf = 0; loopcf < nbCF - 1; loopcf++) { for (int loopfact = 0; loopfact < nbFactor; loopfact++) { mu0Bar[loopcf][loopfact] = 2.0 * mu0[loopcf][loopfact] * meanReversionImpact * tau2Bar[loopcf + 1]; } } for (int loopcf = nbCF - 3; loopcf >= 0; loopcf--) { for (int loopfact = 0; loopfact < nbFactor; loopfact++) { mu0Bar[loopcf][loopfact] += mu0Bar[loopcf + 1][loopfact]; } } double[][] gammaLMMBar = new double[nbCF - 1][nbFactor]; for (int loopfact = 0; loopfact < nbFactor; loopfact++) { gammaLMMBar[0][loopfact] = rateMRatio[0] * muMBar[0][loopfact]; } for (int loopcf = 1; loopcf < nbCF - 1; loopcf++) { for (int loopfact = 0; loopfact < nbFactor; loopfact++) { gammaLMMBar[loopcf][loopfact] += rateMRatio[loopcf] * muMBar[loopcf][loopfact]; } } for (int loopfact = 0; loopfact < nbFactor; loopfact++) { gammaLMMBar[0][loopfact] += rate0Ratio[0] * mu0Bar[0][loopfact]; } for (int loopcf = 1; loopcf < nbCF - 1; loopcf++) { for (int loopfact = 0; loopfact < nbFactor; loopfact++) { gammaLMMBar[loopcf][loopfact] += rate0Ratio[loopcf] * mu0Bar[loopcf][loopfact]; } } double[][] volLMMBar = new double[volLMM.length][nbFactor]; for (int loopcf = 0; loopcf < nbCF - 1; loopcf++) { volLMMBar[indStart + loopcf] = gammaLMMBar[loopcf]; } return volLMMBar; }
From source file:org.shaman.terrain.polygonal.GraphToHeightmap.java
private void calculateBaseElevation() { //assign elevation to oceans for (Graph.Corner c : graph.corners) { if (c.ocean) { c.elevation = -1;/*from ww w. j av a 2s .c o m*/ } } Queue<Graph.Corner> q = new ArrayDeque<>(); for (Graph.Corner c : graph.corners) { if (c.coast) { q.add(c); } } while (!q.isEmpty()) { Graph.Corner c = q.poll(); for (Graph.Corner r : c.adjacent) { float h = Math.max(-1, c.elevation - 0.2f); if (r.ocean && r.elevation < h) { r.elevation = h; q.add(r); } } } assignCenterElevations(); //render Geometry geom = createElevationGeometry(); Heightmap tmp = new Heightmap(size); render(tmp.getRawData(), geom, ColorRGBA.Black, -1, 1); //scale for (int x = 0; x < size; ++x) { for (int y = 0; y < size; ++y) { float h = tmp.getHeightAt(x, y); h = (float) (Math.signum(h) * Math.pow(Math.abs(h), HEIGHT_SCALING)); tmp.setHeightAt(x, y, h); } } //distort Noise distortionNoise = new Noise(rand.nextLong()); for (int x = 0; x < size; ++x) { for (int y = 0; y < size; ++y) { float s = x / (float) size; float t = y / (float) size; float ss = (float) (s + DISTORTION_AMPLITUDE * 2 * distortionNoise.noise(s * DISTORTION_FREQUENCY, t * DISTORTION_FREQUENCY, 0)); float tt = (float) (t + DISTORTION_AMPLITUDE * 2 * distortionNoise.noise(s * DISTORTION_FREQUENCY, t * DISTORTION_FREQUENCY, 3.4)); float v = tmp.getHeightInterpolating(ss * size, tt * size); heightmap.setHeightAt(x, y, v); } } //smooth for (int i = 0; i < SMOOTHING_STEPS; ++i) { smooth(heightmap); } //reset height for (Graph.Corner c : graph.corners) { if (c.ocean) { c.elevation = 0; } } assignCenterElevations(); LOG.info("base elevation assigned"); }
From source file:org.opencastproject.dataloader.EventsLoader.java
private List<EventEntry> parseCSV(CSVParser csv) { List<EventEntry> arrayList = new ArrayList<EventEntry>(); for (CSVRecord record : csv) { String title = record.get(0); String description = StringUtils.trimToNull(record.get(1)); String series = StringUtils.trimToNull(record.get(2)); String seriesName = StringUtils.trimToNull(record.get(3)); Integer days = Integer.parseInt(record.get(4)); float signum = Math.signum(days); DateTime now = DateTime.now();//from ww w . ja va 2 s. co m if (signum > 0) { now = now.plusDays(days); } else if (signum < 0) { now = now.minusDays(days * -1); } Integer duration = Integer.parseInt(record.get(5)); boolean archive = BooleanUtils.toBoolean(record.get(6)); String agent = StringUtils.trimToNull(record.get(7)); String source = StringUtils.trimToNull(record.get(8)); String contributor = StringUtils.trimToNull(record.get(9)); List<String> presenters = Arrays .asList(StringUtils.split(StringUtils.trimToEmpty(record.get(10)), ",")); EventEntry eventEntry = new EventEntry(title, now.toDate(), duration, archive, series, agent, source, contributor, description, seriesName, presenters); arrayList.add(eventEntry); } return arrayList; }
From source file:org.powertac.du.DefaultBrokerService.java
/** * Computes a limit price with a random element. *///from w ww . j a v a 2 s.c om private Double computeLimitPrice(Timeslot timeslot, double amountNeeded) { // start with default limits Double oldLimitPrice; double minPrice; if (amountNeeded > 0.0) { // buying oldLimitPrice = buyLimitPriceMax; minPrice = buyLimitPriceMin; } else { // selling oldLimitPrice = sellLimitPriceMax; minPrice = sellLimitPriceMin; } // check for escalation Order lastTry = lastOrder.get(timeslot); if (lastTry != null && Math.signum(amountNeeded) == Math.signum(lastTry.getMWh())) oldLimitPrice = lastTry.getLimitPrice(); // set price between oldLimitPrice and maxPrice, according to number of // remaining chances we have to get what we need. double newLimitPrice = minPrice; // default value Timeslot current = timeslotRepo.currentTimeslot(); int remainingTries = (timeslot.getSerialNumber() - current.getSerialNumber() - Competition.currentCompetition().getDeactivateTimeslotsAhead()); if (remainingTries > 0) { double range = (minPrice - oldLimitPrice) * 2.0 / (double) remainingTries; log.debug("oldLimitPrice=" + oldLimitPrice + ", range=" + range); double computedPrice = oldLimitPrice + randomSeed.nextDouble() * range; return Math.max(newLimitPrice, computedPrice); } else return null; // market order }