Skip to content

Commit

Permalink
simplify schedule type
Browse files Browse the repository at this point in the history
  • Loading branch information
simontreanor committed Apr 23, 2024
1 parent c7f0a75 commit c63ce0a
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 116 deletions.
2 changes: 1 addition & 1 deletion docs/exampleAmortisation.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ let actualPayments = [|

let amortisationSchedule =
actualPayments
|> Amortisation.generate scheduleParameters IntendedPurpose.Statement ScheduledPaymentType.Original
|> Amortisation.generate scheduleParameters IntendedPurpose.Statement ScheduleType.Original

amortisationSchedule

Expand Down
8 changes: 4 additions & 4 deletions src/Amortisation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ module Amortisation =
}

/// generates an amortisation schedule and final statistics
let generate sp intendedPurpose scheduledPaymentType actualPayments =
let generate sp intendedPurpose scheduleType trimEnd actualPayments =
let payments =
match sp.PaymentSchedule with
| RegularSchedule _ ->
Expand All @@ -540,7 +540,7 @@ module Amortisation =
|> Array.map(fun si -> {
PaymentDay = si.Day
PaymentDetails =
match sp.ScheduleType with
match scheduleType with
| ScheduleType.Original -> ScheduledPayment (ScheduledPaymentType.Original si.Payment.Value)
| ScheduleType.Rescheduled -> ScheduledPayment (ScheduledPaymentType.Rescheduled si.Payment.Value)
})
Expand All @@ -554,7 +554,7 @@ module Amortisation =
{
PaymentDay = OffsetDay.fromDate sp.AsOfDate d
PaymentDetails =
match sp.ScheduleType with
match scheduleType with
| ScheduleType.Original -> ScheduledPayment (ScheduledPaymentType.Original rfs.PaymentAmount)
| ScheduleType.Rescheduled -> ScheduledPayment (ScheduledPaymentType.Rescheduled rfs.PaymentAmount)
}
Expand All @@ -572,6 +572,6 @@ module Amortisation =
payments
|> applyPayments asOfDay intendedPurpose sp.FeesAndCharges.LatePaymentGracePeriod latePaymentCharge sp.FeesAndCharges.ChargesGrouping sp.Calculation.PaymentTimeout actualPayments
|> calculate sp intendedPurpose
|> Array.trimEnd(fun si -> match sp.ScheduleType with ScheduleType.Rescheduled when si.PaymentStatus = NoLongerRequired -> true | _ -> false) // remove extra items from rescheduling
|> Array.trimEnd(fun si -> trimEnd && si.PaymentStatus = NoLongerRequired) // remove extra items from rescheduling
|> calculateStats sp intendedPurpose
|> ValueSome
2 changes: 0 additions & 2 deletions src/PaymentSchedule.fs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ module PaymentSchedule =
type Parameters = {
/// the date on which the schedule is inspected, typically today, but can be used to inspect it at any point (affects e.g. whether schedule payments are deemed as not yet due)
AsOfDate: Date
/// the type of schedule, whether it is an original schedule or a reschedule
ScheduleType: ScheduleType
/// the start date of the schedule, typically the day on which the principal is advanced
StartDate: Date
/// the principal
Expand Down
5 changes: 3 additions & 2 deletions src/Quotes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Quotes =
open Calculation
open Currency
open CustomerPayments
open PaymentSchedule
open ValueOptionCE

[<Struct>]
Expand All @@ -30,8 +31,8 @@ module Quotes =
/// <returns>the requested quote, if possible</returns>
let getQuote quoteType sp (actualPayments: CustomerPayment array) =
voption {
let! currentAmortisationSchedule = Amortisation.generate sp IntendedPurpose.Statement ScheduledPaymentType.Original actualPayments
let! revisedAmortisationSchedule = Amortisation.generate sp (IntendedPurpose.Quote quoteType) ScheduledPaymentType.Original actualPayments
let! currentAmortisationSchedule = Amortisation.generate sp IntendedPurpose.Statement ScheduleType.Original false actualPayments
let! revisedAmortisationSchedule = Amortisation.generate sp (IntendedPurpose.Quote quoteType) ScheduleType.Original false actualPayments
let! si = revisedAmortisationSchedule.ScheduleItems |> Array.tryFind(_.GeneratedPayment.IsSome) |> toValueOption
let confirmedPayments = si.ActualPayments |> Array.sumBy(function ActualPaymentStatus.Confirmed ap -> ap | ActualPaymentStatus.WriteOff ap -> ap | _ -> 0L<Cent>)
let pendingPayments = si.ActualPayments |> Array.sumBy(function ActualPaymentStatus.Pending ap -> ap | _ -> 0L<Cent>)
Expand Down
7 changes: 3 additions & 4 deletions src/Rescheduling.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module Rescheduling =
open Currency
open DateDay
open FeesAndCharges
open PaymentSchedule
open ValueOptionCE

/// the parameters used for setting up additional items for an existing schedule or new items for a new schedule
Expand Down Expand Up @@ -65,7 +66,6 @@ module Rescheduling =
// configure the parameters for the new schedule
let spNew =
{ sp with
ScheduleType = PaymentSchedule.ScheduleType.Rescheduled
PaymentSchedule = [| oldPaymentSchedule; newPaymentSchedule |] |> Array.concat |> IrregularSchedule
FeesAndCharges =
{ sp.FeesAndCharges with
Expand All @@ -84,7 +84,7 @@ module Rescheduling =
match rp.FutureSettlementDay with
| ValueSome futureSettlementDay -> IntendedPurpose.Quote (FutureSettlement futureSettlementDay)
| ValueNone -> IntendedPurpose.Statement
let! rescheduledSchedule = Amortisation.generate spNew intendedPurpose ScheduledPaymentType.Rescheduled actualPayments
let! rescheduledSchedule = Amortisation.generate spNew intendedPurpose ScheduleType.Rescheduled true actualPayments
return quote.RevisedSchedule, rescheduledSchedule
}

Expand Down Expand Up @@ -124,7 +124,6 @@ module Rescheduling =
let spNew =
{ sp with
StartDate = sp.AsOfDate
ScheduleType = PaymentSchedule.ScheduleType.Rescheduled
Principal = principalPortion
PaymentSchedule = rp.PaymentSchedule
FeesAndCharges =
Expand All @@ -146,6 +145,6 @@ module Rescheduling =
Calculation = rp.Calculation |> ValueOption.defaultValue sp.Calculation
}
// create the new amortiation schedule
let! rescheduledSchedule = Amortisation.generate spNew IntendedPurpose.Statement ScheduledPaymentType.Original [||] // sic: `ScheduledPaymentType.Original` is correct here as this is a new schedule
let! rescheduledSchedule = Amortisation.generate spNew IntendedPurpose.Statement ScheduleType.Original true [||] // sic: `ScheduledPaymentType.Original` is correct here as this is a new schedule
return quote.RevisedSchedule, rescheduledSchedule
}
Loading

0 comments on commit c63ce0a

Please sign in to comment.