List of usage examples for java.math BigDecimal add
public BigDecimal add(BigDecimal augend)
From source file:cimav.client.data.domain.EmpleadoNomina.java
public BigDecimal getTotalDeducciones() { List<Movimiento> deducciones = this.getMovimientos(ETipoConcepto.DEDUCCION); BigDecimal result = BigDecimal.ZERO; for (Movimiento deduccion : deducciones) { if (deduccion.getConcepto().getSuma()) { result = result.add(deduccion.getCantidad()); }/*w ww.ja v a2s.c om*/ } return result; }
From source file:cimav.client.data.domain.EmpleadoNomina.java
public BigDecimal getTotalPercepciones() { List<Movimiento> percepciones = this.getMovimientos(ETipoConcepto.PERCEPCION); BigDecimal result = BigDecimal.ZERO; for (Movimiento percepcion : percepciones) { if (percepcion.getConcepto().getSuma()) { result = result.add(percepcion.getCantidad()); }//from w w w . j av a 2 s. c o m } return result; }
From source file:fsm.series.Series_CF.java
public double getF1Value(double y, int m, int n) { double um = getMu_m(m); double un = getMu_m(n); double alphaM = (sin(um) + sinh(um)) / (cos(um) + cosh(um)); double alphaN = (sin(un) + sinh(un)) / (cos(un) + cosh(un)); double km = um / a; double kn = un / a; BigDecimal Ym;/*from ww w . j ava 2 s . c o m*/ BigDecimal Yn; BigDecimal cosh = new BigDecimal(-alphaM * -cosh(km * y)); BigDecimal sinh = new BigDecimal(-sinh(km * y)); BigDecimal sin = new BigDecimal(sin(km * y)); BigDecimal cos = new BigDecimal(-alphaM * cos(km * y)); Ym = (cos.add(sin).add(sinh).add(cosh)); BigDecimal coshN = new BigDecimal(-alphaN * -cosh(kn * y)); BigDecimal sinhN = new BigDecimal(-sinh(kn * y)); BigDecimal sinN = new BigDecimal(sin(kn * y)); BigDecimal cosN = new BigDecimal(-alphaN * cos(kn * y)); Yn = cosN.add(sinN).add(sinhN).add(coshN); BigDecimal ans = Ym.multiply(Yn); return ans.doubleValue(); }
From source file:fsm.series.Series_CF.java
public double getF5Value(double y, int m, int n) { double um = getMu_m(m); double un = getMu_m(n); double alphaM = (sin(um) + sinh(um)) / (cos(um) + cosh(um)); double alphaN = (sin(un) + sinh(un)) / (cos(un) + cosh(un)); double km = um / a; double kn = un / a; BigDecimal Ymd1;//from ww w. j a v a 2s . c om BigDecimal Ynd1; BigDecimal cosh = new BigDecimal(-km * cosh(km * y)); BigDecimal sinh = new BigDecimal(alphaM * km * sinh(km * y)); BigDecimal sin = new BigDecimal(alphaM * km * sin(km * y)); BigDecimal cos = new BigDecimal(km * cos(km * y)); Ymd1 = (cos.add(sin).add(sinh).add(cosh)); BigDecimal coshN = new BigDecimal(-kn * cosh(kn * y)); BigDecimal sinhN = new BigDecimal(alphaN * kn * sinh(kn * y)); BigDecimal sinN = new BigDecimal(alphaN * kn * sin(kn * y)); BigDecimal cosN = new BigDecimal(kn * cos(kn * y)); Ynd1 = cosN.add(sinN).add(sinhN).add(coshN); BigDecimal ans = Ymd1.multiply(Ynd1); return ans.doubleValue(); }
From source file:com.jsquant.servlet.YahooFinanceProxyCalc.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { /* http://ichart.finance.yahoo.com/table.csv?a=00&c=2005&b=01&e=03&d=05&g=d&f=2008&ignore=.csv&s=GOOG Date,Open,High,Low,Close,Volume,Adj Close 2008-06-03,576.50,580.50,560.61,567.30,4305300,567.30 2008-06-02,582.50,583.89,571.27,575.00,3674200,575.00 *//*from w w w .j a v a2s . c o m*/ int fromMM = Integer.valueOf(request.getParameter("a")); // 00 == January int fromDD = Integer.valueOf(request.getParameter("b")); int fromYYYY = Integer.valueOf(request.getParameter("c")); int toMM = Integer.valueOf(request.getParameter("d")); int toDD = Integer.valueOf(request.getParameter("e")); int toYYYY = Integer.valueOf(request.getParameter("f")); String resolution = request.getParameter("g").substring(0, 1); // == "d"ay "w"eek "m"onth "y"ear ValidationUtils.validateResolution(resolution); String symbol = request.getParameter("s"); ValidationUtils.validateSymbol(symbol); String queryString = String.format("a=%02d&b=%02d&c=%d&d=%02d&e=%02d&f=%d&g=%s&s=%s&ignore=.csv", fromMM, fromDD, fromYYYY, toMM, toDD, toYYYY, URLEncoder.encode(resolution, JsquantContextListener.YAHOO_FINANCE_URL_ENCODING), URLEncoder.encode(symbol, JsquantContextListener.YAHOO_FINANCE_URL_ENCODING)); String cacheKey = String.format("%02d%02d%d-%02d%02d%d-%s-%s-%tF-calc.csv.gz", fromMM, fromDD, fromYYYY, toMM, toDD, toYYYY, URLEncoder.encode(resolution, JsquantContextListener.YAHOO_FINANCE_URL_ENCODING), URLEncoder.encode(symbol, JsquantContextListener.YAHOO_FINANCE_URL_ENCODING), new Date()); // include server date to limit to 1 day, for case where future dates might return less data, but fill cache FileCache fileCache = JsquantContextListener.getFileCache(request); String responseBody = fileCache.get(cacheKey); if (responseBody == null) { HttpGet httpget = new HttpGet("http://ichart.finance.yahoo.com/table.csv?" + queryString); ResponseHandler<String> responseHandler = new BasicResponseHandler(); log.debug("requesting uri=" + httpget.getURI()); responseBody = JsquantContextListener.getHttpClient(request).execute(httpget, responseHandler); //httpget.setReleaseTrigger(releaseTrigger); // no need to close? fileCache.put(cacheKey, responseBody); } String[] lines = responseBody.split("\n"); List<Stock> dayPrices = new ArrayList<Stock>(); int index = 0; for (String line : lines) if (index++ > 0 && line.length() > 0) dayPrices.add(new Stock(line)); Collections.reverse(dayPrices); index = 0; BigDecimal allTimeHighClose = new BigDecimal(0); BigDecimal stopAt = null; BigDecimal boughtPrice = null; Stock sPrev = null; for (Stock s : dayPrices) { allTimeHighClose = allTimeHighClose.max(s.adjClose); s.allTimeHighClose = allTimeHighClose; if (index > 0) { sPrev = dayPrices.get(index - 1); //true range = max(high,closeprev) - min(low,closeprev) s.trueRange = s.high.max(sPrev.adjClose).subtract(s.low.min(sPrev.adjClose)); } int rng = 10; if (index > rng) { BigDecimal sum = new BigDecimal(0); for (Stock s2 : dayPrices.subList(index - rng, index)) sum = sum.add(s2.trueRange); s.ATR10 = sum.divide(new BigDecimal(rng)); if (allTimeHighClose.equals(s.adjClose)) { stopAt = s.adjClose.subtract(s.ATR10); } } s.stopAt = stopAt; if (s.stopAt != null && s.adjClose.compareTo(s.stopAt) == -1 && sPrev != null && (sPrev.order == OrderAction.BUY || sPrev.order == OrderAction.HOLD)) { s.order = OrderAction.SELL; s.soldPrice = s.adjClose; s.soldDifference = s.soldPrice.subtract(boughtPrice); } else if (allTimeHighClose.equals(s.adjClose) && stopAt != null && sPrev != null && sPrev.order == OrderAction.IGNORE) { s.order = OrderAction.BUY; boughtPrice = s.adjClose; s.boughtPrice = boughtPrice; } else if (sPrev != null && (sPrev.order == OrderAction.HOLD || sPrev.order == OrderAction.BUY)) { s.order = OrderAction.HOLD; } else { s.order = OrderAction.IGNORE; } index++; } ServletOutputStream out = response.getOutputStream(); out.println(lines[0] + ",Split,All Time High Close,True Range,ATR10,Stop At,Order State,Bought Price,Sold Price,Sold Difference"); for (Stock s : dayPrices) out.println(s.getCSV()); }
From source file:ch.algotrader.entity.security.SecurityFamilyImpl.java
@Override public BigDecimal getTotalCharges(String broker) { BigDecimal totalCharges = new BigDecimal(0.0); BigDecimal executionCommission = getExecutionCommission(broker); if (executionCommission != null) { totalCharges.add(executionCommission); }/*from ww w . ja v a 2 s . c o m*/ BigDecimal clearingCommission = getClearingCommission(broker); if (clearingCommission != null) { totalCharges.add(executionCommission); } BigDecimal fee = getFee(broker); if (fee != null) { totalCharges.add(fee); } return totalCharges; }
From source file:ch.algotrader.entity.security.SecurityFamilyImpl.java
@Override public BigDecimal adjustPrice(String broker, BigDecimal price, int ticks) { Validate.notNull(price, "Price cannot be null"); if (ticks > 0) { for (int i = 0; i < ticks; i++) { price = price.add(getTickSize(broker, price, true)); }/*www .ja va2s. c o m*/ } else if (ticks < 0) { for (int i = 0; i > ticks; i--) { price = price.subtract(getTickSize(broker, price, false)); } } return price; }
From source file:fsm.series.Series_CF.java
public double getF2Value(double y, int m, int n) { double Pi = Math.PI; double um = getMu_m(m); double un = getMu_m(n); double alphaM = (sin(um) + sinh(um)) / (cos(um) + cosh(um)); double alphaN = (sin(un) + sinh(un)) / (cos(un) + cosh(un)); double km = um / a; double kn = un / a; BigDecimal Ymd2;// w w w . ja va2 s .c o m BigDecimal Yn; BigDecimal cosh = new BigDecimal(alphaM * km * km * cosh(km * y)); BigDecimal sinh = new BigDecimal(-km * km * sinh(km * y)); BigDecimal sin = new BigDecimal(-km * km * sin(km * y)); BigDecimal cos = new BigDecimal(alphaM * km * km * cos(km * y)); Ymd2 = (cos.add(sin).add(sinh).add(cosh)); BigDecimal coshN = new BigDecimal(-alphaN * -cosh(kn * y)); BigDecimal sinhN = new BigDecimal(-sinh(kn * y)); BigDecimal sinN = new BigDecimal(sin(kn * y)); BigDecimal cosN = new BigDecimal(-alphaN * cos(kn * y)); Yn = cosN.add(sinN).add(sinhN).add(coshN); BigDecimal ans = Ymd2.multiply(Yn); return ans.doubleValue(); }
From source file:fsm.series.Series_CF.java
public double getF4Value(double y, int m, int n) { double Pi = Math.PI; double um = getMu_m(m); double un = getMu_m(n); double alphaM = (sin(um) + sinh(um)) / (cos(um) + cosh(um)); double alphaN = (sin(un) + sinh(un)) / (cos(un) + cosh(un)); double km = um / a; double kn = un / a; BigDecimal Ymd2;//from w w w.j a va2 s. c om BigDecimal Ynd2; BigDecimal cosh = new BigDecimal(alphaM * km * km * cosh(km * y)); BigDecimal sinh = new BigDecimal(-km * km * sinh(km * y)); BigDecimal sin = new BigDecimal(-km * km * sin(km * y)); BigDecimal cos = new BigDecimal(alphaM * km * km * cos(km * y)); Ymd2 = (cos.add(sin).add(sinh).add(cosh)); BigDecimal coshN = new BigDecimal(alphaN * kn * kn * cosh(kn * y)); BigDecimal sinhN = new BigDecimal(-kn * kn * sinh(kn * y)); BigDecimal sinN = new BigDecimal(-kn * kn * sin(kn * y)); BigDecimal cosN = new BigDecimal(alphaN * kn * kn * cos(kn * y)); Ynd2 = cosN.add(sinN).add(sinhN).add(coshN); BigDecimal ans = Ymd2.multiply(Ynd2); return ans.doubleValue(); }
From source file:com.salesmanager.core.util.ProductUtil.java
public static BigDecimal determinePriceWithAttributes(Product product, Collection attributes, Locale locale, String currency) {/* w ww . j a va 2 s .c o m*/ int decimalPlace = 2; Map currenciesmap = RefCache.getCurrenciesListWithCodes(); Currency c = (Currency) currenciesmap.get(currency); // prices BigDecimal bdprodprice = product.getProductPrice(); BigDecimal bddiscountprice = null; // discount price Special special = product.getSpecial(); Date dt = new Date(); java.util.Date spdate = null; java.util.Date spenddate = null; if (special != null) { spdate = special.getSpecialDateAvailable(); spenddate = special.getExpiresDate(); if (spdate.before(new Date(dt.getTime())) && spenddate.after(new Date(dt.getTime()))) { bddiscountprice = special.getSpecialNewProductPrice(); } } // all other prices Set prices = product.getPrices(); if (prices != null) { Iterator pit = prices.iterator(); while (pit.hasNext()) { ProductPrice pprice = (ProductPrice) pit.next(); pprice.setLocale(locale); if (pprice.isDefaultPrice()) {// overwrites default price bddiscountprice = null; spdate = null; spenddate = null; bdprodprice = pprice.getProductPriceAmount(); ProductPriceSpecial ppspecial = pprice.getSpecial(); if (ppspecial != null) { if (ppspecial.getProductPriceSpecialStartDate() != null && ppspecial.getProductPriceSpecialEndDate() != null && ppspecial.getProductPriceSpecialStartDate().before(new Date(dt.getTime())) && ppspecial.getProductPriceSpecialEndDate().after(new Date(dt.getTime()))) { bddiscountprice = ppspecial.getProductPriceSpecialAmount(); } else if (ppspecial.getProductPriceSpecialDurationDays() > -1) { bddiscountprice = ppspecial.getProductPriceSpecialAmount(); } } break; } } } double fprodprice = 0; ; if (bdprodprice != null) { fprodprice = bdprodprice.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP).doubleValue(); } // determine any properties prices BigDecimal attributesPrice = null; if (attributes != null) { Iterator i = attributes.iterator(); while (i.hasNext()) { ProductAttribute attr = (ProductAttribute) i.next(); if (!attr.isAttributeDisplayOnly() && attr.getOptionValuePrice().longValue() > 0) { if (attributesPrice == null) { attributesPrice = new BigDecimal(0); } attributesPrice = attributesPrice.add(attr.getOptionValuePrice()); } } } if (bddiscountprice != null) { if (attributesPrice != null) { bddiscountprice = bddiscountprice.add(attributesPrice); } return bddiscountprice; } else { if (attributesPrice != null) { bdprodprice = bdprodprice.add(attributesPrice); } return bdprodprice; } }