Package org.archfirst.common.quantity

Examples of org.archfirst.common.quantity.DecimalQuantity


        // Find lots for the specified instrument
        List<Lot> lots =
            brokerageAccountRepository.findActiveLots(this, symbol);

        // First deposit to lots that have negative quantity (unusual case)
        DecimalQuantity quantityLeftToDeposit = quantity;
        for (Lot lot : lots) {
            DecimalQuantity lotQuantity = lot.getQuantity();
            if (lotQuantity.isMinus()) {
                DecimalQuantity depositQuantity = lotQuantity.negate();
                lot.buy(depositQuantity, pricePaidPerShare);
                lot.addAllocation(factory.createAllocation(depositQuantity));
                quantityLeftToDeposit = quantityLeftToDeposit.minus(depositQuantity);
                if (quantityLeftToDeposit.isZero()) {
                    break;
View Full Code Here


        // Find lots for the specified instrument
        List<Lot> lots =
            brokerageAccountRepository.findActiveLots(this, symbol);

        // Withdraw specified quantity from available lots
        DecimalQuantity quantityLeftToWithdraw = quantity;
        for (Lot lot : lots) {
            DecimalQuantity lotQuantity = lot.getQuantity();
            if (lotQuantity.isMinus()) {
                continue;
            }
            DecimalQuantity withdrawQuantity =
                (lotQuantity.gteq(quantityLeftToWithdraw)) ?
                        quantityLeftToWithdraw : lotQuantity;
            lot.sell(withdrawQuantity);
            lot.addAllocation(factory.createAllocation(withdrawQuantity.negate()));
            quantityLeftToWithdraw = quantityLeftToWithdraw.minus(withdrawQuantity);
            if (quantityLeftToWithdraw.isZero()) {
                break;
            }
        }
View Full Code Here

        return quantity.lteq(calculateSecurityAvailable(symbol));
    }
   
    public DecimalQuantity calculateSecurityAvailable(String symbol) {

        DecimalQuantity securityAvailable =
            brokerageAccountRepository.getNumberOfShares(this, symbol);

        // Reduce security available by estimated quantity of sell orders
        List<Order> orders =
            brokerageAccountRepository.findActiveSellOrders(this, symbol);
        for (Order order : orders) {
            securityAvailable = securityAvailable.minus(order.getQuantity());
        }
       
        return securityAvailable;
    }
View Full Code Here

    public static int toJson(DecimalQuantity quantity) {
        return (quantity == null) ? 0 : quantity.getValue().intValue();
    }
   
    public static DecimalQuantity toDomain(int quantity) {
        return new DecimalQuantity(quantity);
    }
View Full Code Here

    }

    public DecimalQuantity getNumberOfShares(
            BrokerageAccount account, String symbol) {
       
        DecimalQuantity numberOfShares = DecimalQuantity.ZERO;
       
        List<Lot> lots = findActiveLots(account, symbol);
        for (Lot lot : lots) {
            numberOfShares = numberOfShares.plus(lot.getQuantity());
        }

        return numberOfShares;
    }
View Full Code Here

        validator = factory.getValidator();
    }

    @Test
    public void testOrderIsTooSmall() {
        Order order = new Order(new DecimalQuantity());

        Set<ConstraintViolation<Order>> constraintViolations =
            validator.validate(order);

        Assert.assertEquals(constraintViolations.size(), 1);
View Full Code Here

            VIOLATION_MESSAGE);
    }

    @Test
    public void testOrderIsCorrectSize() {
        Order order = new Order(new DecimalQuantity("1"));

        Set<ConstraintViolation<Order>> constraintViolations =
            validator.validate(order);

        Assert.assertEquals(constraintViolations.size(), 0);
View Full Code Here

    @Test
    public void testOrderMarshalUnmarshal() throws JAXBException, IOException {

        // Create an order
        Order order = new Order(new DecimalQuantity("10.2"));

        // Write it out as XML
        JAXBContext jaxbContext = JAXBContext.newInstance(Order.class);
        StringWriter writer = new StringWriter();
        Marshaller marshaller = jaxbContext.createMarshaller();
View Full Code Here

        return quantity.minus(getCumQty());
    }
   
    @Transient
    public DecimalQuantity getCumQty() {
        DecimalQuantity cumQty = new DecimalQuantity();
        for (Execution execution : executions) {
            cumQty = cumQty.plus(execution.getQuantity());
        }
        return cumQty;
    }
View Full Code Here

            return new Money("0.00");
        }

        // Calculate weighted average
        Money totalPrice = new Money("0.00");
        DecimalQuantity totalQuantity = new DecimalQuantity();
        for (Execution execution : executions) {
            totalPrice = totalPrice.plus(
                    execution.getPrice().times(execution.getQuantity()));
            totalQuantity = totalQuantity.plus(execution.getQuantity());
        }
        totalPrice = totalPrice.scaleToCurrency();
        return totalPrice.div(totalQuantity, Constants.PRICE_SCALE);
    }
View Full Code Here

TOP

Related Classes of org.archfirst.common.quantity.DecimalQuantity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.