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 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 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())); }
public double GetDaysBetweenDates(FinancialDay startDate, FinancialDay endDate) { if (startDate.Day == 31) { startDate.Day = 30; } if (endDate.Day == 31) { endDate.Day = 30; } return(GetDaysBetweenDates(startDate, endDate, 360)); }
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); }
public double GetDaysBetweenDates(FinancialDay startDate, FinancialDay endDate) { if (endDate.IsLastDayOfFebruary) { if (startDate.IsLastDayOfFebruary) { endDate.Day = 30; startDate.Day = 30; } else { endDate.Day = 30; } } if (endDate.Day == 31 && (startDate.Day == 30 || startDate.Day == 31)) { endDate.Day = 30; } if (startDate.Day == 31) { startDate.Day = 30; } return(GetDaysBetweenDates(startDate, endDate, 360)); }
protected virtual double GetDaysBetweenDates(FinancialDay start, FinancialDay end, int basis) { return(basis * (end.Year - start.Year) + 30 * (end.Month - start.Month) + ((end.Day > 30 ? 30 : end.Day) - (start.Day > 30 ? 30 : start.Day))); }
public FinancialPeriod(FinancialDay start, FinancialDay end) { Start = start; End = end; }
/// <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())); }
public double GetCoupdays(FinancialDay start, FinancialDay end, int frequency) { return(360d / frequency); }
protected override double GetDaysBetweenDates(FinancialDay start, FinancialDay end, int basis) { return(end.ToDateTime().Subtract(start.ToDateTime()).TotalDays); }
public double GetDaysBetweenDates(FinancialDay startDate, FinancialDay endDate) { return(GetDaysBetweenDates(startDate, endDate, 360)); }
public double GetCoupdays(FinancialDay start, FinancialDay end, int frequency) { return(GetDaysBetweenDates(start, end)); }