}
@Transient
public Money getWeightedAveragePriceOfExecutions() {
if (executions.size() == 0) {
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);
}