Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let private calculateDebtReductionResults
- (getTransactions: string -> string -> string[] -> Transaction[])
- (config:Config) =
- let months =
- getTransactions config.AccessToken (config.BudgetId.ToString()) config.FilterAccounts
- |> Seq.groupBy(fun x -> (x.Date.Year.ToString() + x.Date.Month.ToString()))
- |> Seq.map(fun (_,values) ->
- {
- Year = (values |> Seq.head).Date.Year;
- Month = (values |> Seq.head).Date.Month;
- MonthReduction =
- values
- |> Seq.map(fun x -> ((decimal)x.Amount/(decimal)1000))
- |> Seq.sum;
- })
- |> Seq.toArray
- let consideredDebtReduction =
- months.[(Seq.length(months) - config.MonthsToAvg)..]
- |> Seq.map(fun x -> x.MonthReduction)
- |> Seq.sum
- let debtReductionRate = consideredDebtReduction / (decimal)config.MonthsToAvg
- let remainingDebt =
- months
- |> Seq.map(fun x -> x.MonthReduction)
- |> Seq.sum
- |> Math.Abs
- {
- RemainingDebt = remainingDebt;
- MonthlyPaydownAvg = debtReductionRate;
- MonthsRemaining = remainingDebt / debtReductionRate;
- }
- let GetDebtReductionResults = calculateDebtReductionResults getAllTransactions
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement