Introducing go-financial 📊 ! - Hashnode

At Razorpay , we recently worked on building a collection system. For that, we needed an amortization schedule generator in go . Currently, in go, there are no packages which offer complete solution to this problem. There is numpy-financial in python, consisting of fundamental financial functions, but it only covers the reducing interest rate cases.

Introducing, go-finanicial 🎉 !

It's a go-native port of the numpy-financial library and includes amortization schedule generation.

You can either use the low-level functions for financial calculations or utilize the higher-level amortization functions. For now, only 4 functions were ported on a priority basis.

PRs are most welcome for the remaining functions. You can find the contributing guidelines here. 🧑‍💻


If you have to generate the schedule for a loan of 20 lakhs over 15years at 12% p.a., you can define the config as follows:

package main import ( "time" financial "" "" "" ""
) func main() { loc, err := time.LoadLocation("Asia/Kolkata") if err != nil { panic("location loading error") } currentDate := time.Now().In(loc) config := financial.Config{ StartDate: currentDate, EndDate: currentDate.AddDate(15, 0, 0).AddDate(0, 0, -1), Frequency: frequency.ANNUALLY, AmountBorrowed: 2000000, InterestType: interesttype.REDUCING, Interest: 1200, PaymentPeriod: paymentperiod.ENDING, Round: true, } }

Then, to generate the amortization schedule, you just need to call GenerateTable method on the amortization object.

 amortization, err := financial.NewAmortization(&config) if err != nil { panic(err) } rows, err := amortization.GenerateTable() if err != nil { panic(err) } financial.PrintRows(rows) financial.PlotRows(rows, "20lakh-loan-repayment-schedule")

Run complete code on go-playground

The PlotRows function above generates an interactive stacked bar plot of the payments, principal and interest across the period.

For loan repayment, the payment which is made every period is constant throughout the duration of the loan(light-blue bars). Since the interest type was reducing, so higher interest is collected in the beginning and as time period passes, the interest contribution of the payment reduces gradually(dark-blue bars). Likewise, the contribution made to the principal from the payment increases over time.(red bars)

This was just one use case of the go-financial package. You can find detailed examples for more use cases and complete documentation at go-docs.

Gopher artwork credit: ashleymcnamara