Source code

    001/*
    002# Licensed Materials - Property of IBM
    003# Copyright IBM Corp. 2015
    004 */
    005package vwap;
    006
    007import java.math.BigDecimal;
    008import java.math.MathContext;
    009
    010public class Bargain extends Ticker {
    011    /**
    012     *
    013     */
    014    private static final long serialVersionUID = 1L;
    015
    016    final Quote quote;
    017    final VWapT vwap;
    018    final BigDecimal index;
    019
    020    Bargain(Quote quote, VWapT vwap) {
    021        super(quote.getTicker());
    022        this.quote = quote;
    023        this.vwap = vwap;
    024
    025        BigDecimal idx = BigDecimal.ZERO;
    026        if (vwap.vwap.compareTo(quote.askprice) > 0) {
    027            double ep = Math.pow(Math.E, vwap.vwap.subtract(quote.askprice)
    028                    .doubleValue());
    029            idx = quote.asksize.multiply(new BigDecimal(ep),
    030                    MathContext.DECIMAL64);
    031        }
    032        index = idx;
    033    }
    034
    035    @Override
    036    public String toString() {
    037        return "BARGAIN: " + quote + " " + vwap + " Index: " + index;
    038    }
    039
    040    public boolean isBargain() {
    041        return index.compareTo(BigDecimal.ZERO) > 0;
    042    }
    043}