Skip to content

Commit

Permalink
remove ValueOptionCE
Browse files Browse the repository at this point in the history
  • Loading branch information
simontreanor committed Oct 11, 2024
1 parent b8dfe2b commit 6380ebd
Show file tree
Hide file tree
Showing 17 changed files with 61 additions and 115 deletions.
3 changes: 1 addition & 2 deletions src/Amortisation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module Amortisation =
open DateDay
open PaymentSchedule
open Percentages
open ValueOptionCE

/// the status of the balance on a given offset day
[<Struct>]
Expand Down Expand Up @@ -402,7 +401,7 @@ module Amortisation =
| Fee.SettlementRefund.ProRata originalFinalPaymentDay ->
match originalFinalPaymentDay with
| ValueNone ->
let originalFinalPaymentDay = sp.ScheduleConfig |> generatePaymentMap sp.StartDate |> Map.keys |> Seq.toArray |> Array.tryLast |> toValueOption |> ValueOption.defaultValue 0<OffsetDay>
let originalFinalPaymentDay = sp.ScheduleConfig |> generatePaymentMap sp.StartDate |> Map.keys |> Seq.toArray |> Array.tryLast |> Option.defaultValue 0<OffsetDay>
calculateFees originalFinalPaymentDay
| ValueSome ofpd ->
calculateFees ofpd
Expand Down
3 changes: 1 addition & 2 deletions src/AppliedPayment.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ module AppliedPayment =
open Calculation
open Currency
open DateDay
open ValueOptionCE

/// an actual payment made on a particular day, optionally with charges applied, with the net effect and payment status calculated
[<Struct>]
Expand Down Expand Up @@ -76,7 +75,7 @@ module AppliedPayment =
let latePaymentGracePeriod, latePaymentCharge, chargeGrouping =
chargeConfig
|> fun cc ->
let lpc = cc.ChargeTypes |> Array.tryPick(function Charge.LatePayment _ as c -> Some c | _ -> None) |> toValueOption
let lpc = cc.ChargeTypes |> Array.tryPick(function Charge.LatePayment _ as c -> Some c | _ -> None)
cc.LatePaymentGracePeriod, lpc, cc.ChargeGrouping

let netEffect, paymentStatus =
Expand Down
1 change: 0 additions & 1 deletion src/FSharp.Finance.Personal.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<ItemGroup Condition="'$(Configuration)'=='Debug'">
</ItemGroup>
<ItemGroup>
<Compile Include="ValueOption.fs" />
<Compile Include="DateDay.fs" />
<Compile Include="Calculation.fs" />
<Compile Include="Percentages.fs" />
Expand Down
1 change: 0 additions & 1 deletion src/Interest.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module Interest =
open Currency
open DateDay
open Percentages
open ValueOptionCE

/// the interest rate expressed as either an annual or a daily rate
[<RequireQualifiedAccess; Struct>]
Expand Down
4 changes: 3 additions & 1 deletion src/PaymentSchedule.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module PaymentSchedule =
open Formatting
open Percentages
open UnitPeriod
open ValueOptionCE

/// an originally scheduled payment, including the original simple interest and contractual interest calculations
[<Struct; StructuredFormatDisplay("{Html}")>]
Expand Down Expand Up @@ -373,6 +372,9 @@ module PaymentSchedule =
InterestConfig: Interest.Config
}

/// convert an option to a value option
let toValueOption = function Some x -> ValueSome x | None -> ValueNone

/// generates a map of offset days and payments based on a start date and payment schedule
let generatePaymentMap startDate paymentSchedule =
match paymentSchedule with
Expand Down
1 change: 0 additions & 1 deletion src/Quotes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module Quotes =
open Currency
open DateDay
open PaymentSchedule
open ValueOptionCE

type PaymentQuote = {
PaymentValue: int64<Cent>
Expand Down
1 change: 0 additions & 1 deletion src/Rescheduling.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ module Rescheduling =
open Calculation
open Currency
open DateDay
open ValueOptionCE

/// the parameters used for setting up additional items for an existing schedule or new items for a new schedule
[<RequireQualifiedAccess>]
Expand Down
22 changes: 0 additions & 22 deletions src/ValueOption.fs

This file was deleted.

1 change: 0 additions & 1 deletion tests/ActualPaymentTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module ActualPaymentTests =
open Formatting
open PaymentSchedule
open Percentages
open ValueOptionCE

let interestCapExample : Interest.Cap = {
TotalAmount = ValueSome (Amount.Percentage (Percent 100m, ValueNone, ValueSome RoundDown))
Expand Down
1 change: 0 additions & 1 deletion tests/ActualPaymentTestsExtra.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ module ActualPaymentTestsExtra =
open PaymentSchedule
open Percentages
open Rescheduling
open ValueOptionCE

let interestCapExample : Interest.Cap = {
TotalAmount = ValueSome (Amount.Percentage (Percent 100m, ValueNone, ValueSome RoundDown))
Expand Down
1 change: 0 additions & 1 deletion tests/EdgeCaseTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ module EdgeCaseTests =
open Percentages
open Quotes
open Rescheduling
open ValueOptionCE

let interestCapExample : Interest.Cap = {
TotalAmount = ValueSome (Amount.Percentage (Percent 100m, ValueNone, ValueSome RoundDown))
Expand Down
1 change: 0 additions & 1 deletion tests/InterestFirstTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ module InterestFirstTests =
open MapExtension
open PaymentSchedule
open Percentages
open ValueOptionCE

let startDate = Date(2024, 7, 23)
let scheduleParameters =
Expand Down
132 changes: 56 additions & 76 deletions tests/PaymentMapTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,17 @@ module PaymentMapTests =
let unitPeriodConfig = UnitPeriod.Config.Monthly(1, 2024, 8, 15)
let sp = exampleParametersUk asOfDate startDate 1000_00L<Cent> unitPeriodConfig 5 Interest.Method.AddOn
let paymentMap =
voption {
let! schedule = sp |> calculate BelowZero
let scheduledPayments = schedule.Items |> Array.choose(fun i -> if i.Payment.IsSome then Some ({ Day = i.Day; Amount = i.Payment.Value } : PaymentMap.Payment) else None)
let actualPayments : PaymentMap.Payment array = [|
{ Day = 10<OffsetDay>; Amount = 250_00L<Cent> }
{ Day = 17<OffsetDay>; Amount = 250_00L<Cent> }
|]
let pm = PaymentMap.create asOfDate startDate scheduledPayments actualPayments

let title = "<h3>1) Basic scenario</h3>"
let newHtml = pm |> generateHtmlFromArray None
$"{title}<br />{newHtml}" |> outputToFile' @"out/PaymentMapTest001.md" false

return pm
}
let schedule = sp |> calculate BelowZero
let scheduledPayments = schedule.Items |> Array.choose(fun i -> if i.Payment.IsSome then Some ({ Day = i.Day; Amount = i.Payment.Value } : PaymentMap.Payment) else None)
let actualPayments : PaymentMap.Payment array = [|
{ Day = 10<OffsetDay>; Amount = 250_00L<Cent> }
{ Day = 17<OffsetDay>; Amount = 250_00L<Cent> }
|]
let pm = PaymentMap.create asOfDate startDate scheduledPayments actualPayments
let title = "<h3>1) Basic scenario</h3>"
let newHtml = pm |> generateHtmlFromArray None
$"{title}<br />{newHtml}" |> outputToFile' @"out/PaymentMapTest001.md" false
pm

let dailyInterestRate = sp.Interest.StandardRate |> Interest.Rate.daily |> Percent.toDecimal
let actual =
Expand All @@ -91,24 +87,20 @@ module PaymentMapTests =
let unitPeriodConfig = UnitPeriod.Config.Monthly(1, 2024, 8, 15)
let sp = exampleParametersUk asOfDate startDate 1000_00L<Cent> unitPeriodConfig 5 Interest.Method.AddOn
let paymentMap =
voption {
let! schedule = sp |> calculate BelowZero
let scheduledPayments = schedule.Items |> Array.choose(fun i -> if i.Payment.IsSome then Some ({ Day = i.Day; Amount = i.Payment.Value } : PaymentMap.Payment) else None)
let actualPayments : PaymentMap.Payment array = [|
{ Day = 1<OffsetDay>; Amount = 367_73L<Cent> }
{ Day = 2<OffsetDay>; Amount = 367_73L<Cent> }
{ Day = 3<OffsetDay>; Amount = 367_73L<Cent> }
{ Day = 4<OffsetDay>; Amount = 367_73L<Cent> }
{ Day = 5<OffsetDay>; Amount = 367_72L<Cent> }
|]
let pm = PaymentMap.create asOfDate startDate scheduledPayments actualPayments

let title = "<h3>2) Very early exact repayments</h3>"
let newHtml = pm |> generateHtmlFromArray None
$"{title}<br />{newHtml}" |> outputToFile' @"out/PaymentMapTest002.md" false

return pm
}
let schedule = sp |> calculate BelowZero
let scheduledPayments = schedule.Items |> Array.choose(fun i -> if i.Payment.IsSome then Some ({ Day = i.Day; Amount = i.Payment.Value } : PaymentMap.Payment) else None)
let actualPayments : PaymentMap.Payment array = [|
{ Day = 1<OffsetDay>; Amount = 367_73L<Cent> }
{ Day = 2<OffsetDay>; Amount = 367_73L<Cent> }
{ Day = 3<OffsetDay>; Amount = 367_73L<Cent> }
{ Day = 4<OffsetDay>; Amount = 367_73L<Cent> }
{ Day = 5<OffsetDay>; Amount = 367_72L<Cent> }
|]
let pm = PaymentMap.create asOfDate startDate scheduledPayments actualPayments
let title = "<h3>2) Very early exact repayments</h3>"
let newHtml = pm |> generateHtmlFromArray None
$"{title}<br />{newHtml}" |> outputToFile' @"out/PaymentMapTest002.md" false
pm

let dailyInterestRate = sp.Interest.StandardRate |> Interest.Rate.daily |> Percent.toDecimal
let actual =
Expand All @@ -128,22 +120,18 @@ module PaymentMapTests =
let unitPeriodConfig = UnitPeriod.Config.Monthly(1, 2024, 8, 15)
let sp = exampleParametersUk asOfDate startDate 1000_00L<Cent> unitPeriodConfig 5 Interest.Method.AddOn
let paymentMap =
voption {
let! schedule = sp |> calculate BelowZero
let scheduledPayments = schedule.Items |> Array.choose(fun i -> if i.Payment.IsSome then Some ({ Day = i.Day; Amount = i.Payment.Value } : PaymentMap.Payment) else None)
let actualPayments : PaymentMap.Payment array = [|
{ Day = 18<OffsetDay>; Amount = 367_73L<Cent> }
{ Day = 35<OffsetDay>; Amount = 367_73L<Cent> }
{ Day = 168<OffsetDay>; Amount = 1103_18L<Cent> }
|]
let pm = PaymentMap.create asOfDate startDate scheduledPayments actualPayments

let title = "<h3>3) Paid off but with erratic payment timings</h3>"
let newHtml = pm |> generateHtmlFromArray None
$"{title}<br />{newHtml}" |> outputToFile' @"out/PaymentMapTest003.md" false

return pm
}
let schedule = sp |> calculate BelowZero
let scheduledPayments = schedule.Items |> Array.choose(fun i -> if i.Payment.IsSome then Some ({ Day = i.Day; Amount = i.Payment.Value } : PaymentMap.Payment) else None)
let actualPayments : PaymentMap.Payment array = [|
{ Day = 18<OffsetDay>; Amount = 367_73L<Cent> }
{ Day = 35<OffsetDay>; Amount = 367_73L<Cent> }
{ Day = 168<OffsetDay>; Amount = 1103_18L<Cent> }
|]
let pm = PaymentMap.create asOfDate startDate scheduledPayments actualPayments
let title = "<h3>3) Paid off but with erratic payment timings</h3>"
let newHtml = pm |> generateHtmlFromArray None
$"{title}<br />{newHtml}" |> outputToFile' @"out/PaymentMapTest003.md" false
pm

let dailyInterestRate = sp.Interest.StandardRate |> Interest.Rate.daily |> Percent.toDecimal
let actual =
Expand All @@ -163,21 +151,17 @@ module PaymentMapTests =
let unitPeriodConfig = UnitPeriod.Config.Monthly(1, 2024, 8, 15)
let sp = exampleParametersUk asOfDate startDate 1000_00L<Cent> unitPeriodConfig 5 Interest.Method.AddOn
let paymentMap =
voption {
let! schedule = sp |> calculate BelowZero
let scheduledPayments = schedule.Items |> Array.choose(fun i -> if i.Payment.IsSome then Some ({ Day = i.Day; Amount = i.Payment.Value } : PaymentMap.Payment) else None)
let actualPayments : PaymentMap.Payment array = [|
{ Day = 18<OffsetDay>; Amount = 367_73L<Cent> }
{ Day = 35<OffsetDay>; Amount = 367_73L<Cent> }
|]
let pm = PaymentMap.create asOfDate startDate scheduledPayments actualPayments

let title = "<h3>4) Erratic payment timings but not paid off</h3>"
let newHtml = pm |> generateHtmlFromArray None
$"{title}<br />{newHtml}" |> outputToFile' @"out/PaymentMapTest004.md" false

return pm
}
let schedule = sp |> calculate BelowZero
let scheduledPayments = schedule.Items |> Array.choose(fun i -> if i.Payment.IsSome then Some ({ Day = i.Day; Amount = i.Payment.Value } : PaymentMap.Payment) else None)
let actualPayments : PaymentMap.Payment array = [|
{ Day = 18<OffsetDay>; Amount = 367_73L<Cent> }
{ Day = 35<OffsetDay>; Amount = 367_73L<Cent> }
|]
let pm = PaymentMap.create asOfDate startDate scheduledPayments actualPayments
let title = "<h3>4) Erratic payment timings but not paid off</h3>"
let newHtml = pm |> generateHtmlFromArray None
$"{title}<br />{newHtml}" |> outputToFile' @"out/PaymentMapTest004.md" false
pm

let dailyInterestRate = sp.Interest.StandardRate |> Interest.Rate.daily |> Percent.toDecimal
let actual =
Expand All @@ -197,18 +181,14 @@ module PaymentMapTests =
let unitPeriodConfig = UnitPeriod.Config.Monthly(1, 2024, 8, 15)
let sp = exampleParametersUk asOfDate startDate 1000_00L<Cent> unitPeriodConfig 5 Interest.Method.AddOn
let paymentMap =
voption {
let! schedule = sp |> calculate BelowZero
let scheduledPayments = schedule.Items |> Array.choose(fun i -> if i.Payment.IsSome then Some ({ Day = i.Day; Amount = i.Payment.Value } : PaymentMap.Payment) else None)
let actualPayments = Array.empty<PaymentMap.Payment>
let pm = PaymentMap.create asOfDate startDate scheduledPayments actualPayments

let title = "<h3>5) No payments at all</h3>"
let newHtml = pm |> generateHtmlFromArray None
$"{title}<br />{newHtml}" |> outputToFile' @"out/PaymentMapTest005.md" false

return pm
}
let schedule = sp |> calculate BelowZero
let scheduledPayments = schedule.Items |> Array.choose(fun i -> if i.Payment.IsSome then Some ({ Day = i.Day; Amount = i.Payment.Value } : PaymentMap.Payment) else None)
let actualPayments = Array.empty<PaymentMap.Payment>
let pm = PaymentMap.create asOfDate startDate scheduledPayments actualPayments
let title = "<h3>5) No payments at all</h3>"
let newHtml = pm |> generateHtmlFromArray None
$"{title}<br />{newHtml}" |> outputToFile' @"out/PaymentMapTest005.md" false
pm

let dailyInterestRate = sp.Interest.StandardRate |> Interest.Rate.daily |> Percent.toDecimal
let actual =
Expand Down
1 change: 0 additions & 1 deletion tests/PaymentScheduleTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module PaymentScheduleTests =
open Formatting
open PaymentSchedule
open Percentages
open ValueOptionCE

let interestCapExample : Interest.Cap = {
TotalAmount = ValueSome (Amount.Percentage (Percent 100m, ValueNone, ValueSome RoundDown))
Expand Down
1 change: 0 additions & 1 deletion tests/QuoteTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module QuoteTests =
open PaymentSchedule
open Percentages
open Quotes
open ValueOptionCE

let interestCapExample : Interest.Cap = {
TotalAmount = ValueSome (Amount.Percentage (Percent 100m, ValueNone, ValueSome RoundDown))
Expand Down
1 change: 0 additions & 1 deletion tests/SettlementTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module SettlementTests =
open PaymentSchedule
open Percentages
open Quotes
open ValueOptionCE

let interestCapExample : Interest.Cap = {
TotalAmount = ValueSome (Amount.Percentage (Percent 100m, ValueNone, ValueSome RoundDown))
Expand Down
1 change: 0 additions & 1 deletion tests/UnitPeriodConfigTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ module UnitPeriodConfigTests =
open PaymentSchedule
open Percentages
open Quotes
open ValueOptionCE

open UnitPeriod
module DefaultConfig =
Expand Down

0 comments on commit 6380ebd

Please sign in to comment.