razorpay / go-financial

A go port of numpy-financial functions and more.
MIT License
310 stars 22 forks source link

"uneven end date" when the day of month is 29, 30 or 31. #39

Open arobase-che opened 1 year ago

arobase-che commented 1 year ago

Hello \o

I got that error when I tried to make a credit simulation at the end of any month.

Can be reproduced with :

package main

import (
    "fmt"
    "time"

    financial "github.com/razorpay/go-financial"
    "github.com/razorpay/go-financial/enums/frequency"
    "github.com/razorpay/go-financial/enums/interesttype"
    "github.com/razorpay/go-financial/enums/paymentperiod"
    "github.com/shopspring/decimal"
)

func main() {
    date := time.Date(2023, 5, 31, 12, 0, 0, 0, time.UTC)
    FinancingDurationInMonths := 12

    config := financial.Config{
        StartDate:      date,
        EndDate:        date.AddDate(0, FinancingDurationInMonths, 0).AddDate(0, 0, -1),
        Frequency:      frequency.MONTHLY,
        AmountBorrowed: decimal.NewFromInt(35_000),
        InterestType:   interesttype.FLAT,
        Interest:       decimal.NewFromFloat(4.20),
        PaymentPeriod:  paymentperiod.BEGINNING,
    }

    amortization, err := financial.NewAmortization(&config)
    if err != nil {
        fmt.Println(err.Error(), "failed to initialize amortization rules")
    } else {
        fmt.Println(amortization)
    }
}

Is it expected or I'm doing something wrong ?