Code example for BigDecimal

0
        if (ratio > 1.0) {
            throw new Exception("Cannot risk more than all of account");
        } else if (ratio <= 0.0) {
            throw new Exception("Ratio must be > 0");
        } 
        this.ratio = new BigDecimal(ratio);
        this.asset = asset;
    } 
 
    @Override 
    public int sizePosition(Account account, DateTime time) {
        BigDecimal price = asset.priceAt(time);
        BigDecimal allocated = account.getCurrentAmount().multiply(ratio);
        BigDecimal shares = allocated.divide(price, 2, RoundingMode.HALF_UP);
        int i = shares.round(mc).intValue();
 
        return i;
    } 
}