Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.43 KB | None | 0 0
  1.     let private calculateDebtReductionResults
  2.         (getTransactions: string -> string -> string[] -> Transaction[])
  3.         (config:Config) =
  4.         let months =
  5.             getTransactions config.AccessToken (config.BudgetId.ToString()) config.FilterAccounts
  6.             |> Seq.groupBy(fun x ->  (x.Date.Year.ToString() + x.Date.Month.ToString()))
  7.             |> Seq.map(fun (_,values) ->
  8.                 {
  9.                     Year = (values |> Seq.head).Date.Year;
  10.                     Month = (values |> Seq.head).Date.Month;
  11.                     MonthReduction =
  12.                         values
  13.                         |> Seq.map(fun x -> ((decimal)x.Amount/(decimal)1000))
  14.                         |> Seq.sum;
  15.                 })
  16.             |> Seq.toArray
  17.         let consideredDebtReduction =
  18.             months.[(Seq.length(months) - config.MonthsToAvg)..]
  19.             |> Seq.map(fun x -> x.MonthReduction)
  20.             |> Seq.sum
  21.         let debtReductionRate = consideredDebtReduction / (decimal)config.MonthsToAvg
  22.         let remainingDebt =
  23.             months
  24.             |> Seq.map(fun x -> x.MonthReduction)
  25.             |> Seq.sum
  26.             |> Math.Abs
  27.         {
  28.             RemainingDebt = remainingDebt;
  29.             MonthlyPaydownAvg = debtReductionRate;
  30.             MonthsRemaining = remainingDebt / debtReductionRate;
  31.         }
  32.  
  33.     let GetDebtReductionResults = calculateDebtReductionResults getAllTransactions
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement