예제 #1
0
  public float getVolumeWeightedStockPrice(StockContainer stockContainer, float timeInterval) {
    float priceValue = Constants.ZERO_VALUE;

    long currentTime = System.currentTimeMillis();
    Date filterDateValue = new Date(currentTime - 15 * 60 * 1000); // milli seconds
    TradeContainer tradeContainer = null;
    int iteratedQuantity = 0;

    // check for the values
    if (stockContainer != null && stockContainer.getTradeMap().size() > Constants.ZERO_VALUE) {

      Set<Date> iterSet = stockContainer.getTradeMap().keySet();

      // filter based on the time interval
      for (Date date : iterSet) {
        // neglect values before the time interval
        if (date.before(filterDateValue)) {
          continue;
        } else {
          // Buy or sell calculate the quantity and price
          tradeContainer = stockContainer.getTradeMap().get(date);
          iteratedQuantity += tradeContainer.getQuantity();

          // return value
          priceValue += tradeContainer.getPrice() * tradeContainer.getQuantity();
        }
      }

      // calculate the price
      if (iteratedQuantity > Constants.ZERO_VALUE) {
        priceValue = priceValue / iteratedQuantity;
      }
    }
    return priceValue;
  }
예제 #2
0
  public float calculateMeanValueFromStocks(List<StockContainer> stockList) throws Exception {
    float gbceValue = 0.0f;

    for (StockContainer stockContainer : stockList) {

      // iterate all trade buy and sell and calculate the price
      for (TradeContainer tradeContainer : stockContainer.getTradeMap().values()) {
        gbceValue += tradeContainer.getPrice();
      }
    }
    return (float) Math.pow(gbceValue, 1.0 / stockList.size());
  }