public decimal Value(Date date) { if (EffectivePeriod.Contains(date)) { return(Properties[date].Units * Stock.GetPrice(date)); } else { return(0.00m); } }
public void Change(Date date, int unitChange, decimal amountChange, decimal costBaseChange, IPortfolioTransaction transaction) { if (!EffectivePeriod.Contains(date)) { throw new EffectiveDateException("The parcel is not effective at that date"); } var parcelProperties = _Properties[date]; var newUnits = parcelProperties.Units + unitChange; var newAmount = parcelProperties.Amount + amountChange; var newCostBase = parcelProperties.CostBase + costBaseChange; if (newUnits < 0) { throw new ArgumentException("Units cannot be changed to be less than 0"); } if (newAmount < 0) { throw new ArgumentException("Amount cannot be changed to be less than 0"); } if (newCostBase < 0) { throw new ArgumentException("Costbase cannot be changed to be less than 0"); } ParcelProperties newParcelProperties; if (newUnits == 0) { End(date); newParcelProperties = new ParcelProperties(0, 0.00m, 0.00m); } else { newParcelProperties = new ParcelProperties(newUnits, newAmount, newCostBase); } _Properties.Change(date, newParcelProperties); _Audit.Add(new ParcelAudit(date, unitChange, costBaseChange, amountChange, transaction)); }
public bool IsEffectiveAt(Date date) { return(EffectivePeriod.Contains(date)); }