internal AggregatedCashValuation(ValuationCollection cashValuations, bool aggregateToBase) { bool hasInitialized = false; if (aggregateToBase) { foreach (IValuation valuation in cashValuations) { if (valuation.Instrument.IsCash) { if (this.account == null) { this.account = valuation.Account; this.date = valuation.Date; this.key = valuation.Key; this.marketRate = 1M; this.avgOpenExRate = 1M; baseCurrency = ((ICurrency)valuation.Instrument).BaseCurrency; price = new Price(1M, baseCurrency, baseCurrency); this.bookPrice = price; this.costPrice = price; this.marketPrice = price; this.displayInstrumentsCategory = valuation.DisplayInstrumentsCategory; this.AssetClass = valuation.ValuationMutation.AssetClass; this.ValuationMutation = valuation.ValuationMutation; } this.size += valuation.BaseMarketValue; this.bookValue += valuation.BookValue; this.bookChange += valuation.BookChange; this.deposit += valuation.Deposit; this.withDrawal += valuation.WithDrawal; if (!valuation.ValuationMutation.IsSecurityValuationMutation) { this.depositToDate += ((IMonetaryValuationMutation)valuation.ValuationMutation).DepositToDate; this.withDrawalToDate += ((IMonetaryValuationMutation)valuation.ValuationMutation).WithDrawalToDate; } hasInitialized = true; } } } if (!hasInitialized) throw new ApplicationException("Class AggregatedCashValuation could not be initialized"); }
/// <summary> /// This method takes a valuation collection as input and returns the same collection but with the cash valuations aggregated. /// </summary> /// <param name="valuations">The original valuation collection</param> /// <returns>A collection with valuations</returns> public static IList<IValuation> GetValuationsPortfolioOverview(IList<IValuation> valuations) { ValuationCollection cashValuations = null; foreach (IValuation valuation in valuations) { if (valuation.Instrument.IsCash) { if (cashValuations == null) cashValuations = new ValuationCollection(); cashValuations.Add(valuation); } } if (cashValuations != null && cashValuations.Count > 0) { IValuation aggCashValuation = new AggregatedCashValuation(cashValuations, true); foreach (IValuation v in cashValuations) { valuations.Remove(v); } valuations.Add(aggCashValuation); return valuations; } else return valuations; }