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ACjE,OAAS,KAAY,GACrB,EACI,GACI,MAAM,KACL,SAAS,IACV,MAAM,KACL,SAAS,EACtB,OAAS,OAAc,EAAgB,IACvC,GAAI,EACA,MAAM,IAAI,MAAM,2FAEpB,OAAO,CACX,CAxEA,OAAO,eAAe,QAAS,aAAc,CAAE,OAAO,IACtD,QAAQ,UAAO,EAwEf,MAAM,IAAM,QACZ,SAAS,mBAAkB,OAAE,EAAM,KAAE,IACjC,MAAO,CACH,SACA,KAAM,EAAK,UAEnB,CACA,SAAS,eAAgB,KAAM,IAAO,KAAM,IACxC,OAAO,EAAI,CACf,CACA,SAAS,UAAU,GACf,MAAM,EAAS,EACV,IAAI,mBACJ,KAAK,eACJ,EAAY,EAAO,GAAG,KAC5B,OAAO,EAAO,KAAI,EAAG,SAAQ,WAAW,CACpC,SACA,MAAO,EAAO,GAAa,OAEnC,CAIA,SAAS,KAAK,EAAO,EAAW,EAAY,EAAU,GAClD,OAAO,UAAU,UAAU,GAAQ,EAAW,EAAY,EAAU,EACxE,CACA,QAAQ,KAAO,KACf,QAAQ,QAAU","file":"/npm/@webcarrot/xirr@3.0.1/cjs/mod.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@webcarrot/xirr@3.0.1/cjs/mod.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.xirr = void 0;\nfunction calculateResult(flowsFrom1, r) {\n    let result = 0.0;\n    for (let { date, amount } of flowsFrom1) {\n        result = result + amount / Math.pow(r, date);\n    }\n    return result;\n}\nfunction calculateResultDerivation(flowsFrom1, r) {\n    let result = 0.0;\n    for (let { date, amount } of flowsFrom1) {\n        result = result - (date * amount) / Math.pow(r, date + 1.0);\n    }\n    return result;\n}\nfunction flowGt0({ amount }) {\n    return amount > 0;\n}\nfunction flowLt0({ amount }) {\n    return amount < 0;\n}\nfunction calculate(flows, guessRate = 0.1, maxEpsilon = 1e-10, maxScans = 200, maxIterations = 20) {\n    if (flows.findIndex(flowGt0) === -1) {\n        throw new RangeError(\"No positive amount was found in cash flows\");\n    }\n    if (flows.findIndex(flowLt0) === -1) {\n        throw new RangeError(\"No negative amount was found in cash flows\");\n    }\n    if (guessRate <= -1) {\n        throw new RangeError(\"Guess rate is less than or equal to -1\");\n    }\n    if (maxEpsilon <= 0) {\n        throw new RangeError(\"Max epsilon is less than or equal to 0\");\n    }\n    if (maxScans < 10) {\n        throw new RangeError(\"Max scans is lower than 10\");\n    }\n    if (maxIterations < 10) {\n        throw new RangeError(\"Max iterations is lower than 10\");\n    }\n    let resultRate = guessRate;\n    let resultValue;\n    let iterationScan = 0;\n    let doLoop = false;\n    const firstFlowAmount = flows[0].amount;\n    const flowsFrom1 = flows.slice(1);\n    do {\n        if (iterationScan >= 1) {\n            resultRate = -0.99 + (iterationScan - 1) * 0.01;\n        }\n        let iteration = maxIterations;\n        do {\n            resultValue =\n                firstFlowAmount + calculateResult(flowsFrom1, resultRate + 1);\n            const newRate = resultRate -\n                resultValue / calculateResultDerivation(flowsFrom1, resultRate + 1);\n            const rateEpsilon = Math.abs(newRate - resultRate);\n            resultRate = newRate;\n            doLoop = rateEpsilon > maxEpsilon && Math.abs(resultValue) > maxEpsilon;\n        } while (doLoop && --iteration);\n        doLoop =\n            doLoop ||\n                isNaN(resultRate) ||\n                !isFinite(resultRate) ||\n                isNaN(resultValue) ||\n                !isFinite(resultValue);\n    } while (doLoop && !(++iterationScan < maxScans));\n    if (doLoop) {\n        throw new Error(\"XIRR calculation failed. Try to increase one of: max epsilon, max scans, max iterations\");\n    }\n    return resultRate;\n}\nconst D_N = 365.0 * 86400000;\nfunction normalizeCashFlow({ amount, date }) {\n    return {\n        amount,\n        date: date.getTime(),\n    };\n}\nfunction sortCashFlows({ date: a }, { date: b }) {\n    return a - b;\n}\nfunction normalize(flows) {\n    const flowsN = flows\n        .map(normalizeCashFlow)\n        .sort(sortCashFlows);\n    const firstDate = flowsN[0].date;\n    return flowsN.map(({ amount, date }) => ({\n        amount,\n        date: (date - firstDate) / D_N,\n    }));\n}\n/**\n * Calculates the internal rate of return for a series of future cash flows that do not need to be periodic\n */\nfunction xirr(flows, guessRate, maxEpsilon, maxScans, maxIterations) {\n    return calculate(normalize(flows), guessRate, maxEpsilon, maxScans, maxIterations);\n}\nexports.xirr = xirr;\nexports.default = xirr;\n"]}