diff --git a/docs/exampleAmortisation.fsx b/docs/exampleAmortisation.fsx index 2daccbd..f3a2636 100644 --- a/docs/exampleAmortisation.fsx +++ b/docs/exampleAmortisation.fsx @@ -65,7 +65,7 @@ let actualPayments = [| let amortisationSchedule = actualPayments - |> Amortisation.generate scheduleParameters IntendedPurpose.Statement DoNotCalculateFinalApr ApplyNegativeInterest + |> Amortisation.generate scheduleParameters IntendedPurpose.Statement ApplyNegativeInterest amortisationSchedule (*** include-it ***) diff --git a/src/Amortisation.fs b/src/Amortisation.fs index 76f226a..729e0b7 100644 --- a/src/Amortisation.fs +++ b/src/Amortisation.fs @@ -366,7 +366,7 @@ module Amortisation = |> fst /// wraps the amortisation schedule in some statistics, and optionally calculate the final APR (optional because it can be processor-intensive) - let calculateStats sp finalAprOption items = + let calculateStats sp intendedPurpose items = let finalItem = Array.last items let principalTotal = items |> Array.sumBy _.PrincipalPortion let feesTotal = items |> Array.sumBy _.FeesPortion @@ -376,15 +376,14 @@ module Amortisation = let finalPaymentDay = finalItem.OffsetDay let finalBalanceStatus = finalItem.BalanceStatus let finalAprSolution = - match finalAprOption with - | CalculateFinalApr when finalBalanceStatus = ClosedBalance -> + match intendedPurpose with + | IntendedPurpose.Quote Settlement when finalBalanceStatus = ClosedBalance -> items |> Array.filter(fun asi -> asi.NetEffect > 0L) |> Array.map(fun asi -> { Apr.TransferType = Apr.Payment; Apr.TransferDate = sp.StartDate.AddDays(int asi.OffsetDay); Apr.Amount = asi.NetEffect }) |> Apr.calculate sp.Calculation.AprMethod sp.Principal sp.StartDate |> ValueSome - | CalculateFinalApr - | DoNotCalculateFinalApr -> + | _ -> ValueNone { ScheduleItems = items @@ -401,7 +400,7 @@ module Amortisation = } /// generates an amortisation schedule and final statistics - let generate sp intendedPurpose finalAprOption negativeInterestOption originalFinalPaymentDay actualPayments = + let generate sp intendedPurpose negativeInterestOption originalFinalPaymentDay actualPayments = let payments = match sp.PaymentSchedule with | RegularSchedule _ -> @@ -432,5 +431,5 @@ module Amortisation = |> applyPayments asOfDay intendedPurpose sp.FeesAndCharges.LatePaymentGracePeriod latePaymentCharge sp.Calculation.PaymentTimeout actualPayments |> calculate sp intendedPurpose originalFinalPaymentDay' negativeInterestOption |> Array.takeWhile(fun si -> originalFinalPaymentDay.IsNone || si.PaymentStatus <> NoLongerRequired) // remove extra items from rescheduling - |> calculateStats sp finalAprOption + |> calculateStats sp intendedPurpose |> ValueSome diff --git a/src/Calculation.fs b/src/Calculation.fs index 1e4586c..92ff2da 100644 --- a/src/Calculation.fs +++ b/src/Calculation.fs @@ -24,14 +24,6 @@ module Calculation = /// intended just for information, e.g. to view the current status of a loan | Statement - /// whether to calculate the final APR - [] - type FinalAprOption = - /// calculate the final APR (can be compute-intensive) - | CalculateFinalApr - /// do not calculate the final APR (not needed) - | DoNotCalculateFinalApr - /// whether to apply interest on a negative balance (i.e. while a refund is owing) [] type NegativeInterestOption = diff --git a/src/Quotes.fs b/src/Quotes.fs index bfeef90..61a45bc 100644 --- a/src/Quotes.fs +++ b/src/Quotes.fs @@ -25,9 +25,9 @@ module Quotes = /// calculates a revised schedule showing the generated payment for the given quote type let getQuote quoteType sp negativeInterestOption (actualPayments: CustomerPayment array) = voption { - let! currentAmortisationSchedule = Amortisation.generate sp IntendedPurpose.Statement DoNotCalculateFinalApr negativeInterestOption ValueNone actualPayments + let! currentAmortisationSchedule = Amortisation.generate sp IntendedPurpose.Statement negativeInterestOption ValueNone actualPayments let originalFinalPaymentDay = currentAmortisationSchedule.ScheduleItems |> Array.last |> _.OffsetDay - let! revisedAmortisationSchedule = Amortisation.generate sp (IntendedPurpose.Quote quoteType) DoNotCalculateFinalApr negativeInterestOption (ValueSome originalFinalPaymentDay) actualPayments + let! revisedAmortisationSchedule = Amortisation.generate sp (IntendedPurpose.Quote quoteType) negativeInterestOption (ValueSome originalFinalPaymentDay) actualPayments let! si = revisedAmortisationSchedule.ScheduleItems |> Array.tryFind(_.GeneratedPayment.IsSome) |> toValueOption let confirmedPayments = si.ActualPayments |> Array.sumBy(function ActualPayment.Confirmed ap -> ap | _ -> 0L) let pendingPayments = si.ActualPayments |> Array.sumBy(function ActualPayment.Pending ap -> ap | _ -> 0L) diff --git a/src/Rescheduling.fs b/src/Rescheduling.fs index a069415..b4e4528 100644 --- a/src/Rescheduling.fs +++ b/src/Rescheduling.fs @@ -60,7 +60,7 @@ module Rescheduling = Interest = { sp.Interest with InitialGracePeriod = 0; Holidays = rp.InterestHolidays } } // create the new amortiation schedule - let! rescheduledSchedule = Amortisation.generate spNew IntendedPurpose.Statement DoNotCalculateFinalApr DoNotApplyNegativeInterest (ValueSome quote.OriginalFinalPaymentDay) [||] + let! rescheduledSchedule = Amortisation.generate spNew IntendedPurpose.Statement DoNotApplyNegativeInterest (ValueSome quote.OriginalFinalPaymentDay) [||] return quote.RevisedSchedule, rescheduledSchedule } @@ -116,7 +116,7 @@ module Rescheduling = Calculation = rp.Calculation |> ValueOption.defaultValue sp.Calculation } // create the new amortiation schedule - let! rescheduledSchedule = Amortisation.generate spNew IntendedPurpose.Statement DoNotCalculateFinalApr DoNotApplyNegativeInterest (ValueSome quote.OriginalFinalPaymentDay) [||] + let! rescheduledSchedule = Amortisation.generate spNew IntendedPurpose.Statement DoNotApplyNegativeInterest (ValueSome quote.OriginalFinalPaymentDay) [||] return quote.RevisedSchedule, rescheduledSchedule } diff --git a/tests/ActualPaymentTests.fs b/tests/ActualPaymentTests.fs index 38138e7..4be08cd 100644 --- a/tests/ActualPaymentTests.fs +++ b/tests/ActualPaymentTests.fs @@ -83,7 +83,7 @@ module ActualPaymentTests = let schedule = actualPayments - |> Amortisation.generate sp IntendedPurpose.Statement DoNotCalculateFinalApr ApplyNegativeInterest ValueNone + |> Amortisation.generate sp IntendedPurpose.Statement ApplyNegativeInterest ValueNone schedule |> ValueOption.iter (_.ScheduleItems >> Formatting.outputListToHtml "out/ActualPaymentTest001.md") @@ -128,7 +128,7 @@ module ActualPaymentTests = let schedule = actualPayments - |> Amortisation.generate sp IntendedPurpose.Statement DoNotCalculateFinalApr ApplyNegativeInterest ValueNone + |> Amortisation.generate sp IntendedPurpose.Statement ApplyNegativeInterest ValueNone schedule |> ValueOption.iter(_.ScheduleItems >> Formatting.outputListToHtml "out/ActualPaymentTest002.md") @@ -173,7 +173,7 @@ module ActualPaymentTests = let schedule = actualPayments - |> Amortisation.generate sp IntendedPurpose.Statement DoNotCalculateFinalApr ApplyNegativeInterest ValueNone + |> Amortisation.generate sp IntendedPurpose.Statement ApplyNegativeInterest ValueNone schedule |> ValueOption.iter(_.ScheduleItems >> Formatting.outputListToHtml "out/ActualPaymentTest003.md") @@ -218,7 +218,7 @@ module ActualPaymentTests = let schedule = actualPayments - |> Amortisation.generate sp IntendedPurpose.Statement DoNotCalculateFinalApr ApplyNegativeInterest ValueNone + |> Amortisation.generate sp IntendedPurpose.Statement ApplyNegativeInterest ValueNone schedule |> ValueOption.iter(_.ScheduleItems >> Formatting.outputListToHtml "out/ActualPaymentTest004.md") @@ -285,7 +285,7 @@ module ActualPaymentTests = let schedule = actualPayments - |> Amortisation.generate sp IntendedPurpose.Statement DoNotCalculateFinalApr ApplyNegativeInterest ValueNone + |> Amortisation.generate sp IntendedPurpose.Statement ApplyNegativeInterest ValueNone schedule |> ValueOption.iter(_.ScheduleItems >> Formatting.outputListToHtml "out/ActualPaymentTest005.md") @@ -357,7 +357,7 @@ module ActualPaymentTests = let schedule = actualPayments - |> Amortisation.generate sp IntendedPurpose.Statement DoNotCalculateFinalApr ApplyNegativeInterest ValueNone + |> Amortisation.generate sp IntendedPurpose.Statement ApplyNegativeInterest ValueNone schedule |> ValueOption.iter(_.ScheduleItems >> Formatting.outputListToHtml "out/ActualPaymentTest006.md") @@ -426,7 +426,7 @@ module ActualPaymentTests = let schedule = actualPayments - |> Amortisation.generate sp IntendedPurpose.Statement DoNotCalculateFinalApr ApplyNegativeInterest ValueNone + |> Amortisation.generate sp IntendedPurpose.Statement ApplyNegativeInterest ValueNone schedule |> ValueOption.iter(_.ScheduleItems >> Formatting.outputListToHtml "out/ActualPaymentTest007.md") @@ -498,7 +498,7 @@ module ActualPaymentTests = let schedule = actualPayments - |> Amortisation.generate sp IntendedPurpose.Statement DoNotCalculateFinalApr ApplyNegativeInterest ValueNone + |> Amortisation.generate sp IntendedPurpose.Statement ApplyNegativeInterest ValueNone schedule |> ValueOption.iter(_.ScheduleItems >> Formatting.outputListToHtml "out/ActualPaymentTest008.md") @@ -570,7 +570,7 @@ module ActualPaymentTests = let schedule = actualPayments - |> Amortisation.generate sp IntendedPurpose.Statement DoNotCalculateFinalApr ApplyNegativeInterest ValueNone + |> Amortisation.generate sp IntendedPurpose.Statement ApplyNegativeInterest ValueNone schedule |> ValueOption.iter(_.ScheduleItems >> Formatting.outputListToHtml "out/ActualPaymentTest009.md") @@ -641,7 +641,7 @@ module ActualPaymentTests = let schedule = actualPayments - |> Amortisation.generate sp IntendedPurpose.Statement DoNotCalculateFinalApr ApplyNegativeInterest ValueNone + |> Amortisation.generate sp IntendedPurpose.Statement ApplyNegativeInterest ValueNone schedule |> ValueOption.iter(_.ScheduleItems >> Formatting.outputListToHtml "out/ActualPaymentTest010.md") @@ -712,7 +712,7 @@ module ActualPaymentTests = let schedule = actualPayments - |> Amortisation.generate sp IntendedPurpose.Statement DoNotCalculateFinalApr ApplyNegativeInterest ValueNone + |> Amortisation.generate sp IntendedPurpose.Statement ApplyNegativeInterest ValueNone schedule |> ValueOption.iter(_.ScheduleItems >> Formatting.outputListToHtml "out/ActualPaymentTest011.md") @@ -785,7 +785,7 @@ module ActualPaymentTests = let schedule = actualPayments - |> Amortisation.generate sp IntendedPurpose.Statement DoNotCalculateFinalApr ApplyNegativeInterest ValueNone + |> Amortisation.generate sp IntendedPurpose.Statement ApplyNegativeInterest ValueNone schedule |> ValueOption.iter(_.ScheduleItems >> Formatting.outputListToHtml "out/ActualPaymentTest012.md") @@ -854,7 +854,7 @@ module ActualPaymentTests = let schedule = actualPayments - |> Amortisation.generate sp IntendedPurpose.Statement DoNotCalculateFinalApr ApplyNegativeInterest ValueNone + |> Amortisation.generate sp IntendedPurpose.Statement ApplyNegativeInterest ValueNone schedule |> ValueOption.iter(_.ScheduleItems >> Formatting.outputListToHtml "out/ActualPaymentTest013.md") @@ -924,7 +924,7 @@ module ActualPaymentTests = let schedule = actualPayments - |> Amortisation.generate sp IntendedPurpose.Statement DoNotCalculateFinalApr ApplyNegativeInterest ValueNone + |> Amortisation.generate sp IntendedPurpose.Statement ApplyNegativeInterest ValueNone schedule |> ValueOption.iter(_.ScheduleItems >> Formatting.outputListToHtml "out/ActualPaymentTest014.md") @@ -971,7 +971,7 @@ module ActualPaymentTests = let schedule = actualPayments - |> Amortisation.generate sp IntendedPurpose.Statement DoNotCalculateFinalApr ApplyNegativeInterest ValueNone + |> Amortisation.generate sp IntendedPurpose.Statement ApplyNegativeInterest ValueNone schedule |> ValueOption.iter(_.ScheduleItems >> Formatting.outputListToHtml "out/ActualPaymentTest015.md") @@ -1019,7 +1019,7 @@ module ActualPaymentTests = let schedule = actualPayments - |> Amortisation.generate sp IntendedPurpose.Statement DoNotCalculateFinalApr ApplyNegativeInterest ValueNone + |> Amortisation.generate sp IntendedPurpose.Statement ApplyNegativeInterest ValueNone schedule |> ValueOption.iter(_.ScheduleItems >> Formatting.outputListToHtml "out/ActualPaymentTest016.md") @@ -1068,7 +1068,7 @@ module ActualPaymentTests = let schedule = actualPayments - |> Amortisation.generate sp IntendedPurpose.Statement DoNotCalculateFinalApr ApplyNegativeInterest ValueNone + |> Amortisation.generate sp IntendedPurpose.Statement ApplyNegativeInterest ValueNone schedule |> ValueOption.iter(_.ScheduleItems >> Formatting.outputListToHtml "out/ActualPaymentTest017.md") @@ -1117,7 +1117,7 @@ module ActualPaymentTests = let schedule = actualPayments - |> Amortisation.generate sp IntendedPurpose.Statement DoNotCalculateFinalApr ApplyNegativeInterest ValueNone + |> Amortisation.generate sp IntendedPurpose.Statement ApplyNegativeInterest ValueNone schedule |> ValueOption.iter(_.ScheduleItems >> Formatting.outputListToHtml "out/ActualPaymentTest018.md") @@ -1166,7 +1166,7 @@ module ActualPaymentTests = let schedule = actualPayments - |> Amortisation.generate sp IntendedPurpose.Statement DoNotCalculateFinalApr ApplyNegativeInterest ValueNone + |> Amortisation.generate sp IntendedPurpose.Statement ApplyNegativeInterest ValueNone schedule |> ValueOption.iter(_.ScheduleItems >> Formatting.outputListToHtml "out/ActualPaymentTest019.md")