UNPKG

@investo/invform

Version:

A versatile library of investment formulas...

60 lines (59 loc) 1.75 kB
const o = (t, r, n) => t * (1 + r * n), c = (t, r, n) => o(t, r, n) - t, s = (t, r) => { if (t <= 0) throw new Error("Investment must be greater than 0."); return (r - t) / t * 100; }, a = (t, r) => { if (t < 0 || r < 0 || r > 100) throw new Error("Invalid input: investment must be ≥ 0 and targetPercentage between 0 and 100."); return t * (r / 100); }; function l(t, r) { if (t <= 0) throw new Error("Investment must be greater than 0."); return r / t * 100; } const i = (t, r, n = 0) => { if (t < 0 || r < 0 || n < 0) throw new Error("All inputs must be ≥ 0."); return t * r + n; }, w = (t, r, n = 0) => { if (t < 0 || r <= 0 || n < 0) throw new Error("Invalid input: all values must be ≥ 0 and pricePerAsset must be > 0."); const e = t - n; return e < 0 ? 0 : e / r; }, f = (t, r, n = 0) => { if (t < 0 || r <= 0 || n < 0) throw new Error("Invalid input: investment and fee must be ≥ 0, amount must be > 0."); const e = t - n; return e < 0 ? 0 : e / r; }; function m(t, r, n = 0) { if (t < 0 || r < 0 || n < 0) throw new Error("All inputs must be ≥ 0."); const u = t * r - n; return u >= 0 ? u : 0; } function I(t, r) { if (t < 0 || r < 0) throw new Error("Inputs must be ≥ 0."); return t - r; } function b(t, r) { if (t < 0 || r < 0) throw new Error("Inputs must be ≥ 0."); const n = t - r; return n >= 0 ? n : 0; } export { o as calcSimpleInterest, c as calcSimpleProfit, w as calculateAssetsFromInvestment, i as calculateInvestment, m as calculateNetSaleProceeds, a as calculatePartialReturn, f as calculatePricePerAsset, I as calculateProfit, s as calculateROI, b as calculateRemainingInvestment, l as calculateReturnPercentage };