Help us shape the future of Go! Take the 2026 Go Developer Survey

landedcost

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 0 Imported by: 0

README

landedcost

Landed-cost arithmetic for an imported shipment: duty, carriage, fees, and the effective rate that actually lands in a margin calculation.

What it does not do

It ships no rate table. Which duty rate applies to a good is a question of tariff classification and of trade measures in force on the day of entry, and both change by proclamation. A library that hardcoded rates would go wrong silently and on a schedule nobody controls. You supply the rate; this computes what follows.

The part people get wrong

The valuation basis, not the rate. On an FOB basis the duty applies to the customs value alone. On a CIF basis it applies to the customs value plus freight and insurance. On a shipment whose carriage is a large fraction of its value those are materially different numbers at the same headline rate, which is why the basis is worth establishing first.

The other one is the effective rate. Duty as a fraction of the landed total is always lower than the headline rate, because the rate applies to the customs value while the total includes carriage and fees.

Usage

s := landedcost.Shipment{
    CustomsValue: 10000, DutyRate: 0.25,
    Freight: 1500, Insurance: 500, Fees: 200,
}
s.Duty()          // FOB basis
s.DutyCIF()       // CIF basis
s.Total()
s.EffectiveRate()
s.UnitLandedCost(100)

An interactive version is at ustariffcalc.com.

Licence

MIT.

Documentation

Overview

Package landedcost computes the landed cost of an imported shipment from a declared customs value, an ad valorem duty rate, and any per-shipment fees.

It deliberately ships NO rate table. Which duty rate applies to a given good is a question of tariff classification and of trade measures in force on the day of entry, and both change by proclamation. A library that hardcoded rates would be wrong silently and on a schedule nobody controls. Supply the rate; this computes what follows from it.

Worked through at https://ustariffcalc.com/ if you want the arithmetic in a form you can poke at.

The full breakdown this package mirrors — customs value, duty, freight, insurance, fees and the resulting effective rate — is at https://ustariffcalc.com/landed-cost-calculator.html

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Shipment

type Shipment struct {
	// CustomsValue is the declared value the ad valorem duty applies to,
	// in the same currency as every other field here.
	CustomsValue float64
	// DutyRate is the ad valorem rate as a fraction, so 0.25 means 25 percent.
	DutyRate float64
	// Freight and Insurance are carriage costs. Whether they sit inside the
	// dutiable value depends on the valuation basis: they are excluded under an
	// FOB basis and included under a CIF basis. See Duty and DutyCIF.
	Freight   float64
	Insurance float64
	// Fees are flat per-entry charges that are not ad valorem.
	Fees float64
}

Shipment is one customs entry.

func (Shipment) Duty

func (s Shipment) Duty() float64

Duty returns the ad valorem duty on an FOB basis: the rate applies to the customs value alone, and carriage is excluded from the dutiable base.

func (Shipment) DutyCIF

func (s Shipment) DutyCIF() float64

DutyCIF returns the ad valorem duty on a CIF basis: the rate applies to the customs value plus freight and insurance.

The two bases are not a rounding difference. On a shipment whose carriage is a large fraction of its value, CIF duty is materially higher than FOB duty at the same rate, which is why the valuation basis is worth establishing before the rate.

func (Shipment) EffectiveRate

func (s Shipment) EffectiveRate() float64

EffectiveRate returns duty as a fraction of the landed total, which is the number that actually shows up in a margin calculation. It is always lower than the headline duty rate, because the rate applies to the customs value while the denominator includes carriage and fees.

func (Shipment) Total

func (s Shipment) Total() float64

Total returns the landed cost on an FOB duty basis: value, carriage, duty, fees.

func (Shipment) TotalCIF

func (s Shipment) TotalCIF() float64

TotalCIF returns the landed cost with duty computed on a CIF basis.

func (Shipment) UnitLandedCost

func (s Shipment) UnitLandedCost(units int) float64

UnitLandedCost divides the landed total across a unit count. Returns 0 for a non-positive count rather than panicking or returning an infinity.

Jump to

Keyboard shortcuts

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