public static decimal?BuildWeightedAverageSell(List <Watcher> watchers) { // Watchers selling var watcherWillingToSell = watchers.Where(WatcherExpression.WatcherSelling()).ToList(); // Return if no watchers if (watcherWillingToSell.Count == 0) { return(null); } // Total quantity var totalQuantity = watcherWillingToSell.Select(x => x.Quantity).Sum(); // Weights var weights = watcherWillingToSell.Select(x => x.Sell * x.Quantity); // Total weight var totalWeight = weights.Sum(); // Weighted average var weightedAverage = totalWeight / totalQuantity; // Return return(weightedAverage); }
public static WatcherStatus BuildStatus(Watcher watcher) { // Evaluate and return if (WatcherExpression.WatcherNotSet().Invoke(watcher)) { return(WatcherStatus.NOT_SET); } if (WatcherExpression.WatcherBuying().Invoke(watcher)) { return(WatcherStatus.BUYING); } if (WatcherExpression.WatcherSelling().Invoke(watcher)) { return(WatcherStatus.SELLING); } if (WatcherExpression.WatcherBought().Invoke(watcher)) { return(WatcherStatus.BOUGHT); } if (WatcherExpression.WatcherHolding().Invoke(watcher)) { return(WatcherStatus.HOLDING); } if (WatcherExpression.WatcherSold().Invoke(watcher)) { return(WatcherStatus.SOLD); } throw new NotImplementedException(); }