List of usage examples for org.apache.commons.math.util MathUtils round
public static float round(float x, int scale)
From source file:com.algoTrader.util.RoundUtil.java
public static double roundToNextN(double value, double n) { return MathUtils.round(value / n, 0) * n; }
From source file:ch.algotrader.util.RoundUtil.java
public static double roundToNextN(double value, double n) { return MathUtils.round((value) / n, 0) * n; }
From source file:hoot.services.geo.QuadTileCalculator.java
/** * Calculates the quad tile for a point/*from ww w.j a v a 2 s . c o m*/ * * @param latitude point's latitude * @param longitude points longitude * @return tile integer */ public static long tileForPoint(final double latitude, final double longitude) { int lonInt = (int) MathUtils.round(((longitude + 180.0) * 65535.0 / 360.0), 0); int latInt = (int) MathUtils.round(((latitude + 90.0) * 65535.0 / 180.0), 0); //use a long here, because java doesn't have unsigned int long tileUnsigned = 0; for (int i = 15; i >= 0; i--) { //use y, x ordering tileUnsigned = (tileUnsigned << 1) | ((lonInt >> i) & 1); tileUnsigned = (tileUnsigned << 1) | ((latInt >> i) & 1); } assert (tileUnsigned >= 0); return tileUnsigned; }
From source file:hoot.services.utils.QuadTileCalculator.java
/** * Calculates the quad tile for a point// w ww . ja v a 2 s.c om * * @param latitude * point's latitude * @param longitude * points longitude * @return tile integer */ public static long tileForPoint(double latitude, double longitude) { int lonInt = (int) MathUtils.round((((longitude + 180.0) * 65535.0) / 360.0), 0); int latInt = (int) MathUtils.round((((latitude + 90.0) * 65535.0) / 180.0), 0); // use a long here, because java doesn't have unsigned int long tileUnsigned = 0; for (int i = 15; i >= 0; i--) { // use y, x ordering tileUnsigned = (tileUnsigned << 1) | ((lonInt >> i) & 1); tileUnsigned = (tileUnsigned << 1) | ((latInt >> i) & 1); } return tileUnsigned; }
From source file:cc.recommenders.evaluation.data.Averager.java
public double getRoundedAverage(int scale) { return MathUtils.round(getAverage(), scale); }
From source file:hmp.Read.java
public String getRDPResultString() { String s = ""; for (Iterator<String> i = rdpResultHash.keySet().iterator(); i.hasNext();) { String key = i.next();/*from w ww . j av a 2s. c o m*/ double mean = MathUtils.round(rdpResultHash.get(key).getMean(), 3); double sd = MathUtils.round(rdpResultHash.get(key).getStandardDeviation(), 3); s += " " + key + "; " + mean + "; " + sd + ";"; } return s.replaceFirst(" ", ""); }
From source file:cc.recommenders.evaluation.data.BoxplotDataTest.java
private double calculateVariance(double... values) { double mean = 0; double numEntries = values.length; for (double value : values) { mean += value;// w w w. j a v a 2 s . c o m } mean = mean / numEntries; double variance = 0.0; for (double value : values) { double diff = value - mean; variance += diff * diff / (numEntries - 1.0); } return MathUtils.round(variance, Boxplot.DATA_SCALE); // double variance = StatUtils.variance(values); // return MathUtils.round(variance, Boxplot.DATA_SCALE); }
From source file:ch.algotrader.service.OptionServiceImpl.java
/** * {@inheritDoc}/*from www . ja v a 2s .c o m*/ */ @Override public void hedgeDelta(final long underlyingId) { List<Position> positions = this.positionDao.findOpenPositionsByUnderlying(underlyingId); Date currentEPTime = this.engineManager.getCurrentEPTime(); // get the deltaAdjustedMarketValue double deltaAdjustedMarketValue = 0; for (Position position : positions) { MarketDataEventVO marketDataEvent = this.marketDataCacheService .getCurrentMarketDataEvent(position.getSecurity().getId()); MarketDataEventVO underlyingMarketDataEvent = this.marketDataCacheService .getCurrentMarketDataEvent(position.getSecurity().getUnderlying().getId()); deltaAdjustedMarketValue += position.getMarketValue(marketDataEvent).doubleValue() * position.getSecurity().getLeverage(marketDataEvent, underlyingMarketDataEvent, currentEPTime); } final Security underlying = this.securityDao.get(underlyingId); final Strategy server = this.strategyDao.findServer(); Subscription underlyingSubscription = this.subscriptionDao.findByStrategyAndSecurity(StrategyImpl.SERVER, underlying.getId()); if (!underlyingSubscription.hasProperty("hedgingFamily")) { throw new IllegalStateException("no hedgingFamily defined for security " + underlying); } final FutureFamily futureFamily = this.futureFamilyDao .load(underlyingSubscription.getIntProperty("hedgingFamily")); Date targetDate = DateUtils.addMilliseconds(currentEPTime, this.coreConfig.getDeltaHedgeMinTimeToExpiration()); final Future future = this.futureService.getFutureByMinExpiration(futureFamily.getId(), targetDate); final double deltaAdjustedMarketValuePerContract = deltaAdjustedMarketValue / futureFamily.getContractSize(); this.serverEngine.addFirstTickCallback(Collections.singleton(future.getId()), (strategyName, ticks) -> { // round to the number of contracts int qty = (int) MathUtils .round(deltaAdjustedMarketValuePerContract / ticks.get(0).getCurrentValueDouble(), 0); if (qty != 0) { // create the order Order order = OptionServiceImpl.this.orderService.createOrderByOrderPreference( OptionServiceImpl.this.coreConfig.getDeltaHedgeOrderPreference()); order.setStrategy(server); order.setSecurity(future); order.setQuantity(Math.abs(qty)); order.setSide(qty > 0 ? Side.SELL : Side.BUY); OptionServiceImpl.this.orderService.sendOrder(order); } else { if (LOGGER.isInfoEnabled()) { LOGGER.info("no delta hedge necessary on {}", underlying); } } }); // make sure the future is subscriped this.marketDataService.subscribe(server.getName(), future.getId()); }
From source file:cc.kave.episodes.mining.evaluation.Evaluation.java
private void synthesizeResults(String category) { Map<Double, List<Tuple<Averager, Averager>>> categoryAverager = new LinkedHashMap<Double, List<Tuple<Averager, Averager>>>(); // initialize for (double percent : percentages) { List<Tuple<Averager, Averager>> percAvg = new LinkedList<Tuple<Averager, Averager>>(); for (int propId = 0; propId < PROPOSALS; propId++) { percAvg.add(Tuple.newTuple(new Averager(), new Averager())); }//from w w w. ja va 2s. com categoryAverager.put(MathUtils.round(percent, 2), percAvg); } if (category.length() == 5) { int range = Integer.parseInt(category.substring(3)); if (range > 10) { for (double p = 1.0; p < range; p += 1.0) { List<Tuple<Averager, Averager>> percAvg = new LinkedList<Tuple<Averager, Averager>>(); for (int propId = 0; propId < PROPOSALS; propId++) { percAvg.add(Tuple.newTuple(new Averager(), new Averager())); } categoryAverager.put(MathUtils.round(p, 2), percAvg); } } } // synthesize for (int ind = 0; ind < results.size(); ind++) { Map<Double, List<Tuple<Double, Double>>> targetResults = results.get(ind).getResults(); for (Map.Entry<Double, List<Tuple<Double, Double>>> entry : targetResults.entrySet()) { for (int p = 0; p < entry.getValue().size(); p++) { double qpAvg = targetResults.get(entry.getKey()).get(p).getFirst(); double tpAvg = targetResults.get(entry.getKey()).get(p).getSecond(); categoryAverager.get(entry.getKey()).get(p).getFirst().addValue(qpAvg); categoryAverager.get(entry.getKey()).get(p).getSecond().addValue(tpAvg); } } } // average for (Map.Entry<Double, List<Tuple<Averager, Averager>>> qsEntry : categoryAverager.entrySet()) { List<Tuple<Double, Double>> avgs = new LinkedList<Tuple<Double, Double>>(); for (Tuple<Averager, Averager> ps : qsEntry.getValue()) { avgs.add(Tuple.newTuple(ps.getFirst().average(), ps.getSecond().average())); } categoryResults.put(qsEntry.getKey(), avgs); } }
From source file:at.tuwien.ifs.somtoolbox.visualization.ClusterConnectionsVisualizer.java
@Override public HashMap<String, BufferedImage> getVisualizationFlavours(int index, GrowingSOM gsom, int width, int height) throws SOMToolboxException { HashMap<String, BufferedImage> res = new HashMap<String, BufferedImage>(); // modify t1 0.7 - 0.9 // modify t2 1.0 - 1.2 // modify t3 1.5 - 1.7 double oldT1 = t1; // save original values double oldT2 = t2; double oldT3 = t3; double stepWidth = 0.05; for (t1 = 0.7; MathUtils.round(t1, 2) <= 0.9; t1 += stepWidth) { for (t2 = Math.max(t1, 1.0); MathUtils.round(t2, 2) <= 1.2; t2 += stepWidth) { for (t3 = Math.max(t2, 1.5); MathUtils.round(t3, 2) <= 1.7; t3 += stepWidth) { String key = String.format("_%.2f_%.2f_%.2f", t1, t2, t3); res.put(key, getVisualization(index, gsom, width, height)); }//w ww.j a v a 2s . c o m } } t1 = oldT1; // reset to original values t2 = oldT2; t3 = oldT3; return res; }