public int GetNumberOfCouponPeriods(FinancialDay settlementDay, FinancialDay maturityDay, int frequency) { var settlementDate = settlementDay.ToDateTime(); var tmpDay = maturityDay; var lastDay = tmpDay; var nPeriods = 0; while (tmpDay.ToDateTime() > settlementDate) { switch (frequency) { case 1: tmpDay = tmpDay.SubtractYears(1); break; case 2: tmpDay = tmpDay.SubtractMonths(6, maturityDay.Day); break; case 4: tmpDay = tmpDay.SubtractMonths(3, maturityDay.Day); break; default: throw new ArgumentException("frequency"); } nPeriods++; } return(nPeriods); }
public FinancialPeriod GetCouponPeriod(FinancialDay settlementDay, FinancialDay maturityDay, int frequency) { var periods = new List <FinancialPeriod>(); var settlementDate = settlementDay.ToDateTime(); var tmpDay = maturityDay; var lastDay = tmpDay; while (tmpDay.ToDateTime() > settlementDate) { switch (frequency) { case 1: tmpDay = tmpDay.SubtractYears(1); break; case 2: tmpDay = tmpDay.SubtractMonths(6, maturityDay.Day); break; case 4: tmpDay = tmpDay.SubtractMonths(3, maturityDay.Day); break; default: throw new ArgumentException("frequency"); } if (tmpDay > settlementDay) { lastDay = tmpDay; } } return(new FinancialPeriod(tmpDay, lastDay)); }
public int CompareTo(FinancialDay other) { if (other is null) { return(1); } if (Year == other.Year && Month == other.Month && Day == other.Day) { return(0); } return(ToDateTime().CompareTo(other.ToDateTime())); }
protected double ActualDaysInLeapYear(FinancialDay start, FinancialDay end) { var daysInLeapYear = 0d; for (var year = start.Year; year <= end.Year; year++) { if (System.DateTime.IsLeapYear(year)) { if (year == start.Year) { daysInLeapYear += new System.DateTime(year + 1, 1, 1).Subtract(start.ToDateTime()).TotalDays; } else if (year == end.Year) { daysInLeapYear += end.ToDateTime().Subtract(new System.DateTime(year, 1, 1)).TotalDays; } else { daysInLeapYear += 366d; } } } return(daysInLeapYear); }
/// <summary> /// Number of days between two <see cref="FinancialDay"/>s /// </summary> /// <param name="day">The other day</param> /// <returns>Number of days according to the <see cref="DayCountBasis"/> of this day</returns> public double SubtractDays(FinancialDay day) { var financialDays = FinancialDaysFactory.Create(Basis); return(financialDays.GetDaysBetweenDates(this.ToDateTime(), day.ToDateTime())); }
protected override double GetDaysBetweenDates(FinancialDay start, FinancialDay end, int basis) { return(end.ToDateTime().Subtract(start.ToDateTime()).TotalDays); }