Functional Weave
Code in Python

finance.compound-interest@1.0.0

vectors.json

5,202 bytes · view raw

[
  { "name": "5 percent on 1000.00 for one year compounded annually", "args": [{ "minor": 100000, "currency": "GBP" }, 500, 1, 1], "expect": { "principal": { "minor": 100000, "currency": "GBP" }, "interest": { "minor": 5000, "currency": "GBP" }, "total": { "minor": 105000, "currency": "GBP" }, "periods": 1 } },
  { "name": "three annual periods, the third of which accrues half a penny and rounds up", "args": [{ "minor": 100000, "currency": "GBP" }, 500, 1, 3], "expect": { "principal": { "minor": 100000, "currency": "GBP" }, "interest": { "minor": 15763, "currency": "GBP" }, "total": { "minor": 115763, "currency": "GBP" }, "periods": 3 } },
  { "name": "semi-annual 5 percent: the second period lands on exactly half a penny", "args": [{ "minor": 100000, "currency": "GBP" }, 500, 2, 1], "expect": { "principal": { "minor": 100000, "currency": "GBP" }, "interest": { "minor": 5063, "currency": "GBP" }, "total": { "minor": 105063, "currency": "GBP" }, "periods": 2 } },
  { "name": "a nominal 4.5 percent monthly: 37.5 basis points a period, never rounded as a rate", "args": [{ "minor": 100000, "currency": "GBP" }, 450, 12, 1], "expect": { "principal": { "minor": 100000, "currency": "GBP" }, "interest": { "minor": 4594, "currency": "GBP" }, "total": { "minor": 104594, "currency": "GBP" }, "periods": 12 } },
  { "name": "nominal 12 percent monthly is 1126.84, a penny above what a single pow() returns", "args": [{ "minor": 100000, "currency": "GBP" }, 1200, 12, 1], "expect": { "principal": { "minor": 100000, "currency": "GBP" }, "interest": { "minor": 12684, "currency": "GBP" }, "total": { "minor": 112684, "currency": "GBP" }, "periods": 12 } },
  { "name": "2500.00 at 3.75 percent monthly for five years: three pence above pow(), and the statement wins", "args": [{ "minor": 250000, "currency": "GBP" }, 375, 12, 5], "expect": { "principal": { "minor": 250000, "currency": "GBP" }, "interest": { "minor": 51472, "currency": "GBP" }, "total": { "minor": 301472, "currency": "GBP" }, "periods": 60 } },
  { "name": "quarterly compounding over two years", "args": [{ "minor": 100000, "currency": "GBP" }, 500, 4, 2], "expect": { "principal": { "minor": 100000, "currency": "GBP" }, "interest": { "minor": 10449, "currency": "GBP" }, "total": { "minor": 110449, "currency": "GBP" }, "periods": 8 } },
  { "name": "zero years accrues nothing and returns the principal untouched", "args": [{ "minor": 100000, "currency": "GBP" }, 500, 1, 0], "expect": { "principal": { "minor": 100000, "currency": "GBP" }, "interest": { "minor": 0, "currency": "GBP" }, "total": { "minor": 100000, "currency": "GBP" }, "periods": 0 } },
  { "name": "a zero rate still runs the periods and still accrues nothing", "args": [{ "minor": 100000, "currency": "GBP" }, 0, 12, 1], "expect": { "principal": { "minor": 100000, "currency": "GBP" }, "interest": { "minor": 0, "currency": "GBP" }, "total": { "minor": 100000, "currency": "GBP" }, "periods": 12 } },
  { "name": "a balance of one penny never earns a second one, ten years running", "args": [{ "minor": 1, "currency": "GBP" }, 500, 1, 10], "expect": { "principal": { "minor": 1, "currency": "GBP" }, "interest": { "minor": 0, "currency": "GBP" }, "total": { "minor": 1, "currency": "GBP" }, "periods": 10 } },
  { "name": "ten pence at 5 percent rounds a half penny up every year and reaches fifteen", "args": [{ "minor": 10, "currency": "GBP" }, 500, 1, 5], "expect": { "principal": { "minor": 10, "currency": "GBP" }, "interest": { "minor": 5, "currency": "GBP" }, "total": { "minor": 15, "currency": "GBP" }, "periods": 5 } },
  { "name": "100 percent a year doubles three pence to twenty-four", "args": [{ "minor": 3, "currency": "GBP" }, 10000, 1, 3], "expect": { "principal": { "minor": 3, "currency": "GBP" }, "interest": { "minor": 21, "currency": "GBP" }, "total": { "minor": 24, "currency": "GBP" }, "periods": 3 } },
  { "name": "an overdraft accrues the mirror image of a savings balance", "args": [{ "minor": -100000, "currency": "GBP" }, 1200, 12, 1], "expect": { "principal": { "minor": -100000, "currency": "GBP" }, "interest": { "minor": -12684, "currency": "GBP" }, "total": { "minor": -112684, "currency": "GBP" }, "periods": 12 } },
  { "name": "a negative rate shrinks the balance rather than erroring", "args": [{ "minor": 100000, "currency": "GBP" }, -50, 4, 1], "expect": { "principal": { "minor": 100000, "currency": "GBP" }, "interest": { "minor": -500, "currency": "GBP" }, "total": { "minor": 99500, "currency": "GBP" }, "periods": 4 } },
  { "name": "zero periods per year is an error, not annual compounding", "args": [{ "minor": 100000, "currency": "GBP" }, 500, 0, 1], "expectError": "must be at least 1" },
  { "name": "negative years is an error, not discounting", "args": [{ "minor": 100000, "currency": "GBP" }, 500, 12, -1], "expectError": "years must not be negative" },
  { "name": "a fractional rate is an error: basis points are integers", "args": [{ "minor": 100000, "currency": "GBP" }, 4.5, 12, 1], "expectError": "must be an integer" },
  { "name": "an absurd period count is a wrong unit, not a long wait", "args": [{ "minor": 100000, "currency": "GBP" }, 500, 365, 400], "expectError": "period limit" }
]