financial

package
v1.20.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 14, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

README

financial

financial provides financial date/tenor calculations, settlement date logic, amount formatting, and rate ladder generation.

Types

Type Description
FinDate Represents a dated rate-ladder rung with Code, Name, Date, Index, Simple, External, and Human fields
Tenor Financial tenor value object (e.g. "1M", "SP", "3Y") with validation

Functions

Tenor
Function Description
NewTenor(term string) (Tenor, error) Creates and validates a Tenor
(*Tenor).String() string Returns the tenor string
(*Tenor).Set(term string) (*Tenor, error) Sets and validates the tenor
Date Calculations
Function Description
GetDateFromTenor(tenor, tradeDate string, ccy ...string) (time.Time, error) Calculates the settlement date for a given tenor and currencies
GetTenorFromDate(inDate, baseDate time.Time, ccy ...string) (Tenor, error) Reverse-maps a date to its closest tenor
GetLadder(pivotDate time.Time, ccy ...string) ([]FinDate, int, error) Generates a full rate ladder of dated tenors
GetSpotDate(time.Time) time.Time Returns T+2 adjusted for weekends
GetTenorDate(time.Time, monthStr string) time.Time Returns T+N months adjusted for weekends
GetFirstDayOfYear(time.Time) time.Time Returns Jan 2 adjusted for weekends
SettlementDate(major, minor string, pivotDate time.Time) (time.Time, error) Calculates settlement date for a currency pair
SettlementDateVia(major, minor string, pivotDate time.Time, via string) (time.Time, error) Calculates settlement date for a cross-currency pair
Amount Formatting
Function Description
AbbrToInt(str string) int Converts abbreviated amounts (e.g. "5M") to integers
FormatAmount(float64, ccy string) string Formats amount using currency-specific symbol/DPS
FormatAmountFullDPS(amount, ccy string) string Formats amount to 7 decimal places
FormatAmountToDPS(amount, ccy, prec string) string Formats amount to specified decimal places

Example

import "github.com/mt1976/frantic-core/financial"

func main() {
    tenor, _ := financial.NewTenor("3M")
    date, _ := financial.GetDateFromTenor("3M", "2024-01-15", "GBP", "USD")
    fmt.Println(tenor.String(), "settles on", date)

    formatted := financial.FormatAmount(1234567.89, "GBP")
    fmt.Println(formatted) // £1,234,567.89
}

Documentation

Overview

Package financial provides date/tenor calculations and financial helpers used for scheduling and time conventions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbbrToInt

func AbbrToInt(str string) int

The function AbbrToInt converts a string representation of a number with abbreviations (such as "1M" for 1 million) into its corresponding integer value.

func FormatAmount

func FormatAmount(inAmount float64, inCCY string) string

func FormatAmountFullDPS

func FormatAmountFullDPS(inAmount string, inCCY string) string

FormatAmountFullDPS returns a formated string version of a CCY amount to 7dps The function takes an amount and currency code as input, formats the amount with the specified precision and currency symbol, and returns the formatted amount as a string.

func FormatAmountToDPS

func FormatAmountToDPS(inAmount string, inCCY string, inPrec string) string

FormatAmountToDPS returns a formated string version of a CCY amount to a given DPS The function takes an amount, currency, and precision as input, and formats the amount to the specified decimal places with the currency symbol.

func GetDateFromTenor

func GetDateFromTenor(tenor Tenor, tradeDate time.Time, ccy ...string) (time.Time, error)

The function `GetDateFromTenor` calculates the settlement date based on the given tenor, trade date, and currency.

func GetFirstDayOfYear

func GetFirstDayOfYear(inTime time.Time) time.Time

The function "GetFirstDayOfYear" returns the first day of the year, assuming that January 1st is a holiday and the first day is shifted to January 2nd.

func GetSpotDate

func GetSpotDate(inTime time.Time) time.Time

GetSpotDate(inTime invalid type) The function "GetSpotDate" takes a time input and returns a modified time value.

func GetTenorDate

func GetTenorDate(inTime time.Time, inMonth string) time.Time

CalculateSpotDate(inTime invalid type) The function `GetTenorDate` takes a time and a month as input, adds the specified number of months to the time, and returns the resulting date.

func SettlementDate

func SettlementDate(major string, minor string, pivotDate time.Time) (time.Time, error)

func SettlementDateVia

func SettlementDateVia(major string, minor string, pivotDate time.Time, via string) (time.Time, error)

Types

type FinDate

type FinDate struct {
	Code     string
	Name     string
	Date     time.Time
	Index    int
	Simple   string
	External string
	Human    string
}

The "FinDate" type represents a date with various properties and formats. @property {string} Code - The "Code" property is a string that represents a code associated with the date. @property {string} Name - The "Name" property is a string that represents the name of the date. @property FinDate - The "FinDate" property is of type "time.Time" and represents a specific date and time. @property {int} Sort - The "Sort" property is an integer that is used to determine the order in which the dates should be sorted. It can be used to sort the dates in ascending or descending order based on this value. @property {string} Simple - The "Simple" property is a string that represents the date in a simplified format. It could be a formatted string that only includes the day, month, and year of the date. @property {string} External - The "External" property in the FinDate struct is a string that represents an external reference or identifier related to the date. @property {string} Human - The "Human" property in the "FinDate" struct represents the date in a human-readable format. It is likely used to display the date to users in a more understandable way, such as "January 1, 2022".

func GetLadder

func GetLadder(pivotDate time.Time, ccy ...string) ([]FinDate, int, error)

The function `GetLadder` takes a pivot date and a list of currency codes as input, and returns a list of dates based on a rate ladder.

type Tenor

type Tenor struct {
	// contains filtered or unexported fields
}

func GetTenorFromDate

func GetTenorFromDate(inDate, baseDate time.Time, ccy ...string) (Tenor, error)

The function `GetTenorFromDate` takes a date and optional currency as input and returns the corresponding tenor or an error.

func NewTenor

func NewTenor(term string) (Tenor, error)

The function NewTenor takes a string as input and returns a Tenor object.

func (*Tenor) Set

func (t *Tenor) Set(term string) (*Tenor, error)

The function Set takes a string as input and sets the term of a Tenor object.

func (*Tenor) String

func (t *Tenor) String() string

The function String returns the term of a Tenor object.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL