private decimal CalculateClientsNetPosition(AllocatedOrder[] allocatedOrders) { var netPositions = allocatedOrders.Average(o => o.OrderPrice/Math.Abs(o.ClientOrder.LotSize))* allocatedOrders.Sum(o => o.VolumeTraded); //test output seem to be 3 DP max, e.g.: 296.156 as opposed to 296.1564103 netPositions = Math.Round(netPositions, 3); return netPositions; }
private decimal AllocateOrder(string clientId, Order order, Quote[] quotes) { decimal totalPrice = 0; foreach (var quote in quotes) { _brokers[quote.BrokerId].AddVolume(quote.LotSize); totalPrice += quote.PriceAfterCommission; } AllocatedOrder ao = new AllocatedOrder(order, totalPrice, quotes); if (_orders.ContainsKey(clientId) == false) { _orders.Add(clientId, new List<AllocatedOrder> {ao}); } else { _orders[clientId].Add(ao); } return totalPrice; }