{"id":"loan-apr-compute","version":"1.0.0","description":"APR of an equal-payment loan net of prepaid fees under US Reg Z or the EU consumer credit directive.","supported_operations":["APR of a loan with origination fee","annual percentage rate including prepaid finance charges","Regulation Z APR calculation","EU APRC effective annual rate of a consumer loan","true cost of a loan with fees","compare loan offers by APR","finance charge and total of payments of a loan","real interest rate of a loan after fees"],"unsupported_operations":["odd first periods, odd days, irregular payments or multiple advances","the Regulation Z 1/8 percent tolerance test and disclosure rounding","converting a known nominal rate to an effective rate (use rate-nominal-effective-convert)","credit card, revolving or variable-rate APR disclosures"],"semantics":["Inputs: method (required, us-reg-z or eu-ccd), principal (the loan amount before prepaid charges, greater than 0), fees (prepaid finance charges deducted from the advance, decimal at least 0 and below principal; default \"0\"), payment (greater than 0, the regular payment), periods (integer 1 to 1200, the number of payments), payments_per_year P (one of 1, 2, 4, 12, 24, 26, 52; default 12), final_payment (optional decimal greater than 0: the last payment when it differs, for example a balloon; default equal to payment), scale (0 to 12, default 2, for amounts), rate_scale (0 to 12, default 4, for rates) and rounding (default half-up). The payments are equally spaced one unit period 1/P year apart, the first one full unit period after the advance; odd first periods, odd days, irregular payments and multiple advances are not supported.","Stream: amount_financed A = principal - fees. Payment k (k = 1 .. periods) equals payment, except payment number periods equals final_payment when it is supplied. total_of_payments = sum of all payments and finance_charge = total_of_payments - amount_financed (interest plus prepaid charges).","Periodic (unit-period) rate i is the actuarial root of A = sum over k of payment_k / (1+i)^k (12 CFR 1026 Appendix J general equation for equal unit periods, and Directive 2008/48/EC Annex I with t_k = k/P years). The root is unique for i > 0 because the equation has one sign change.","method us-reg-z: apr = P * i (a nominal annual rate, the unit-period rate times unit periods per year, Appendix J (b)(5)(ii)). method eu-ccd: apr = (1+i)^P - 1, the effective annual rate X of Annex I (the APRC). Both use the same i, so for P = 1 they are equal.","If total_of_payments < amount_financed the result is not_computable (details.reason payments_below_amount_financed). If total_of_payments equals amount_financed exactly, i and apr are 0 and no solver runs. Otherwise i is found in binary64 on the fixed unit-period rate grid [0, 0.005, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1, 0.125, 0.15, 0.175, 0.2, 0.25, 0.3, 0.4, 0.5, 0.75, 1, 1.5, 2, 3, 5, 10, 20, 50, 100, 1000] by f(i) = sum payment_k*exp(-k*log1p(i)) - A (pinned fdlibm exp and log1p, terms summed in ascending k) and Brent's method (tolerance 1e-14, at most 200 iterations) on the bracketing interval. A root above 1000 is not_computable (no_root_in_range); non-convergence is not_computable (no_convergence). Accuracy is about 1e-12 absolute on i, so digits beyond rate_scale 10 are not guaranteed.","apr and periodic_rate are computed from the exact binary value of the float root (apr = P*i exactly for us-reg-z, or (1+i)^P - 1 in exact arithmetic for eu-ccd) and rounded once to rate_scale. amount_financed, finance_charge and total_of_payments are exact sums rounded once to scale. method echoes the input.","For method eu-ccd, an effective annual rate (1+i)^P - 1 of 1e20 or more (for example a unit-period rate near 1000 with 52 payments per year) cannot be represented: not_computable (details.reason overflow). us-reg-z apr = P*i is at most 52 * 1000 and cannot overflow.","Regulation Z tolerance rules (1026.22(a)(2), 1/8 of 1 percentage point) and the disclosure rounding of the APR are not applied; the result is the mathematical APR at the requested precision.","Every rounded output is rounded exactly once from the unrounded value using the rounding mode: half-up (ties away from zero, the default), half-even, half-down (ties toward zero), up (away from zero), down (toward zero), ceiling, floor. Amount outputs print exactly scale fractional digits and rate-like outputs exactly rate_scale fractional digits; a result that rounds to zero prints without a minus sign (never '-0.00').","Decimal string fields (amounts, rates) must match ^-?(0|[1-9][0-9]*)(\\.[0-9]+)?$ with at most 20 integer digits and at most 20 fractional digits; a JSON number, exponent form, leading plus, surrounding spaces, percent sign, missing integer part or trailing dot is invalid_input. Rates are decimal fractions (0.065 means 6.5 percent; \"6.5\" means 650 percent). A decimal string longer than 64 UTF-8 bytes is limit_exceeded, checked before parsing.","Disclaimer: arithmetic calculation only; not financial, tax, legal, or investment advice."],"limits":{"max_periods":1200,"max_string_bytes":64},"pricing":{"status":"unpriced","charge_usd":null},"input_schema":{"type":"object","additionalProperties":false,"required":["method","principal","payment","periods"],"properties":{"method":{"type":"string","enum":["us-reg-z","eu-ccd"]},"principal":{"type":"string","pattern":"^-?(0|[1-9][0-9]*)(\\.[0-9]+)?$","maxLength":64},"fees":{"type":"string","pattern":"^-?(0|[1-9][0-9]*)(\\.[0-9]+)?$","maxLength":64},"payment":{"type":"string","pattern":"^-?(0|[1-9][0-9]*)(\\.[0-9]+)?$","maxLength":64},"periods":{"type":"integer","minimum":1,"maximum":1200},"payments_per_year":{"type":"integer","enum":[1,2,4,12,24,26,52]},"final_payment":{"type":"string","pattern":"^-?(0|[1-9][0-9]*)(\\.[0-9]+)?$","maxLength":64},"scale":{"type":"integer","minimum":0,"maximum":12},"rate_scale":{"type":"integer","minimum":0,"maximum":12},"rounding":{"type":"string","enum":["half-up","half-even","half-down","up","down","ceiling","floor"]}}},"output_schema":{"type":"object","additionalProperties":false,"required":["apr","periodic_rate","amount_financed","finance_charge","total_of_payments","method"],"properties":{"apr":{"type":"string","pattern":"^-?(0|[1-9][0-9]*)(\\.[0-9]+)?$","maxLength":64},"periodic_rate":{"type":"string","pattern":"^-?(0|[1-9][0-9]*)(\\.[0-9]+)?$","maxLength":64},"amount_financed":{"type":"string","pattern":"^-?(0|[1-9][0-9]*)(\\.[0-9]+)?$","maxLength":64},"finance_charge":{"type":"string","pattern":"^-?(0|[1-9][0-9]*)(\\.[0-9]+)?$","maxLength":64},"total_of_payments":{"type":"string","pattern":"^-?(0|[1-9][0-9]*)(\\.[0-9]+)?$","maxLength":64},"method":{"type":"string","enum":["us-reg-z","eu-ccd"]}}},"examples":[{"input":{"method":"us-reg-z","principal":"5000","payment":"166.07","periods":36,"rate_scale":4},"output":{"apr":"0.1200","periodic_rate":"0.0100","amount_financed":"5000.00","finance_charge":"978.52","total_of_payments":"5978.52","method":"us-reg-z"}},{"input":{"method":"eu-ccd","principal":"5000","fees":"100","payment":"166.07","periods":36,"rate_scale":6},"output":{"apr":"0.142658","periodic_rate":"0.011175","amount_financed":"4900.00","finance_charge":"1078.52","total_of_payments":"5978.52","method":"eu-ccd"}}],"execute_url":"/v1/tools/loan-apr-compute/versions/1.0.0/execute"}