This commit is contained in:
Richard Green 2016-06-14 11:28:58 +01:00
parent 86203709c0
commit 2ce0dce0aa
2 changed files with 15 additions and 17 deletions

View File

@ -673,7 +673,6 @@ class InterestRateSwap() : Contract {
for (periodEndDate in dates) { for (periodEndDate in dates) {
val paymentDate = BusinessCalendar.getOffsetDate(periodEndDate, Frequency.Daily, fixedLeg.paymentDelay) // + fixedLeg.paymentDelay val paymentDate = BusinessCalendar.getOffsetDate(periodEndDate, Frequency.Daily, fixedLeg.paymentDelay) // + fixedLeg.paymentDelay
val paymentEvent = FixedRatePaymentEvent( val paymentEvent = FixedRatePaymentEvent(
// TODO: We are assuming the payment date is the end date of the accrual period.
paymentDate, paymentDate,
periodStartDate, periodStartDate,
periodEndDate, periodEndDate,

View File

@ -250,28 +250,28 @@ enum class DateOffset {
*/ */
enum class Frequency(val annualCompoundCount: Int) { enum class Frequency(val annualCompoundCount: Int) {
Annual(1) { Annual(1) {
override fun offset(d: LocalDate) = d.plusYears(1) override fun offset(d: LocalDate, n: Long) = d.plusYears(1 * n)
}, },
SemiAnnual(2) { SemiAnnual(2) {
override fun offset(d: LocalDate) = d.plusMonths(6) override fun offset(d: LocalDate, n: Long) = d.plusMonths(6 * n)
}, },
Quarterly(4) { Quarterly(4) {
override fun offset(d: LocalDate) = d.plusMonths(3) override fun offset(d: LocalDate, n: Long) = d.plusMonths(3 * n)
}, },
Monthly(12) { Monthly(12) {
override fun offset(d: LocalDate) = d.plusMonths(1) override fun offset(d: LocalDate, n: Long) = d.plusMonths(1 * n)
}, },
Weekly(52) { Weekly(52) {
override fun offset(d: LocalDate) = d.plusWeeks(1) override fun offset(d: LocalDate, n: Long) = d.plusWeeks(1 * n)
}, },
BiWeekly(26) { BiWeekly(26) {
override fun offset(d: LocalDate) = d.plusWeeks(2) override fun offset(d: LocalDate, n: Long) = d.plusWeeks(2 * n)
}, },
Daily(365) { Daily(365) {
override fun offset(d: LocalDate) = d.plusDays(1) override fun offset(d: LocalDate, n: Long) = d.plusDays(1 * n)
}; };
abstract fun offset(d: LocalDate): LocalDate abstract fun offset(d: LocalDate, n: Long = 1): LocalDate
// Daily() // Let's not worry about this for now. // Daily() // Let's not worry about this for now.
} }
@ -330,16 +330,15 @@ open class BusinessCalendar private constructor(val calendars: Array<out String>
return ret return ret
} }
fun getOffsetDate(startDate: LocalDate, period: Frequency, howMany: Int = 1): LocalDate { /** Calculates the date from @startDate moving forward @steps of time size @period. Does not apply calendar
if (howMany == 0) return startDate * logic / roll conventions.
var nextDate = startDate */
repeat(howMany) { nextDate = period.offset(nextDate) } fun getOffsetDate(startDate: LocalDate, period: Frequency, steps: Int = 1): LocalDate {
return nextDate if (steps == 0) return startDate
return period.offset(startDate, steps.toLong())
} }
} }
override fun equals(other: Any?): Boolean = if (other is BusinessCalendar) { override fun equals(other: Any?): Boolean = if (other is BusinessCalendar) {
/** Note this comparison is OK as we ensure they are sorted in getInstance() */ /** Note this comparison is OK as we ensure they are sorted in getInstance() */
this.holidayDates == other.holidayDates this.holidayDates == other.holidayDates