public static WithdrawalRuleRegularity GetWithdrawalRuleRegularity(IDalSession session, Regularities id) { List<ICriterion> expressions = new List<ICriterion>(); expressions.Add(Expression.Eq("key", (int)id)); IList<WithdrawalRuleRegularity> rules = session.GetTypedList<WithdrawalRuleRegularity>(expressions); if (rules != null && rules.Count == 1) return rules[0]; else return null; }
public static IList GetAverageValuations(IList valuations, Regularities regularity) { SortedList averageValuations = null; int period; int year = 0; foreach (IValuation valuation in valuations) { if (regularity != Regularities.Annual) checkYear(valuation.Date, ref year); switch (regularity) { case Regularities.Annual: period = valuation.Date.Year; break; case Regularities.BiAnnual: period = valuation.Date.Month <= 6 ? 1 : 2; break; case Regularities.Quarterly: period = Util.GetQuarter(valuation.Date); break; case Regularities.Monthly: period = valuation.Date.Month; break; case Regularities.Weekly: period = Util.GetWeekNumber(valuation.Date); break; default: period = 0; break; } if (period != 0) { string key = string.Format("{0}_{1}", valuation.Instrument.Key.ToString(), period.ToString()); if (averageValuations == null) averageValuations = new SortedList(); if (!averageValuations.ContainsKey(key)) averageValuations.Add(key, new AverageValuation(valuation, period)); else ((AverageValuation)averageValuations[key]).AddValue(valuation); } } if (averageValuations != null && averageValuations.Count > 0) { // first return zero items removeZeroItems(ref averageValuations); IAverageValuation[] list = new IAverageValuation[averageValuations.Count]; averageValuations.Values.CopyTo(list, 0); return list; } else return null; }
/// <summary> /// Method that calculates the last coupon payment date relative to the passed in settlementDate /// </summary> /// <param name="firstCouponDate">The First Coupon payment date</param> /// <param name="freq">The coupon frequency</param> /// <param name="settlementDate">The passed in settlement date</param> /// <returns>A date</returns> public DateTime CalculateLastCouponDate(DateTime firstCouponDate, Regularities freq, bool ultimoDating, DateTime settlementDate) { // find the last coupon payment date. // first find the first payment date that is later than the settlement date -> // then take the previous date // Note, there is a Special case when the settlementdate is between the Issue Date // and the First Coupon Date. This has special consequences when the FirstCouponDate // is Greater (or less) then (IssueDate + Frequency) as in case of long Bonds. DateTime date; Int16 intI = 0; // Return null date, when settlement date is before the first coupon payment date. if (firstCouponDate.Date > settlementDate.Date) { date = DateTime.MinValue; } else { date = firstCouponDate.Date; if (Util.IsNullDate(date)) throw new ApplicationException("The first coupon payment date can not be null"); else { while (settlementDate.Date > date.AddMonths(12 / (int)freq)) { date = date.AddMonths(12 / (int)freq); if (UltimoDating) date = Util.GetLastDayOfMonth(date); if (!IsPerpetual && Util.IsNotNullDate(MaturityDate) && date > MaturityDate) { date = MaturityDate; break; } intI++; if (intI >= 400) return DateTime.MinValue; } } } return date; }