{"id":25805996,"url":"https://github.com/alipsa/jfinancials","last_synced_at":"2025-06-15T12:05:56.203Z","repository":{"id":264499617,"uuid":"861389730","full_name":"Alipsa/jfinancials","owner":"Alipsa","description":"Java library for working with financial data","archived":false,"fork":false,"pushed_at":"2024-09-25T07:40:09.000Z","size":46,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-14T10:40:19.899Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Alipsa.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-22T19:00:49.000Z","updated_at":"2024-09-26T15:00:53.000Z","dependencies_parsed_at":"2024-11-24T19:05:46.815Z","dependency_job_id":"17a7195f-07d6-4324-8bc3-83c559d03889","html_url":"https://github.com/Alipsa/jfinancials","commit_stats":null,"previous_names":["alipsa/jfinancials"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/Alipsa/jfinancials","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alipsa%2Fjfinancials","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alipsa%2Fjfinancials/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alipsa%2Fjfinancials/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alipsa%2Fjfinancials/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Alipsa","download_url":"https://codeload.github.com/Alipsa/jfinancials/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Alipsa%2Fjfinancials/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259971379,"owners_count":22940011,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-27T19:52:34.238Z","updated_at":"2025-06-15T12:05:56.187Z","avatar_url":"https://github.com/Alipsa.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jfinancials\nJava library for working with financial data. Based on the [financials R package](https://github.com/Alipsa/financials).\n\nTo use it add the following dependency to your pom\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003ese.alipsa\u003c/groupId\u003e\n    \u003cartifactId\u003ejfinancials\u003c/artifactId\u003e\n    \u003cversion\u003e1.0.0\u003c/version\u003e\n\u003c/dependency\u003e\n```\nAll methods of the public api are in the se.alipsa.jfinancials.Financials class\n\n### Payment\n`double pmt(interestRate, nper, pv, fv = 0, type = 0)`\n\nEquivalent to Excel/Calc's PMT(interest_rate, number_payments, PV, FV, Type)\nfunction, which calculates the payments for a loan or the future value of an investment\n#### Parameters\n- _interestRate_ periodic interest rate represented as a decimal.\n- _nper_ number of total payments / periods.\n- _pv_   present value -- borrowed or invested principal.\n- _fv_   future value of loan or annuity, default to 0 (which is what you want for loans)\n- _type_ when payment is made: beginning of period is 1; end is 0. Default is 0\n\n#### Value\n_returns_ A double representing the periodic payment amount.\n\n#### Example\n__Calulate payment for a loan__\n\nThe following data:\n\n| Item            | amount  |\n|-----------------|---------|\n| Loan Amount\t    | 50000   |\n| Interest rate\t  | 3.50%   |\n| Periods\t        | 60      |\n| Monthly payment | \t909.59 |\n\nThen the Monthly payment can be calculated as\n`pmt(3.5/100, 60, -50000)` ≈ 2004.43\n\n### Monthly Annuity Amount\n`monthlyAnnuityAmount(loanAmount, interestRate, tenureMonths, amortizationFreemonths = 0, type = 0)`\n\nCalculate the monthly annuity amount i.e. the amortization and interest amount each payment period (month)\n\n#### Parameters\n- _loanAmount_ the total loan amount including capitalized fees (e.g. startup fee)\n- _interestRate_ the annual nominal interest\n- _tenureMonths_ the tenure of the loan in number of months\n- _amortizationFreeMonths_ the number of initial amortization free months, default to 0\n- _type_ - when payment is made: beginning of period is 1; end is 0. Default is 0\n\n#### Value\n_returns_ the monthly annuity amount\n\n#### Example\nAssuming the following:\n\n| Item                     | amount |\n|--------------------------|--------|\n| Loan Amount\t             | 50000  |\n| Interest rate\t           | 3.50%  |\n| Tenure\t                  | 60     |\n| Amortization Free months | \t6     |\n\nThe monthly annuity amount would be\n`monthlyAnnuityAmount(50000, 3.5/100, 60, 6)` == 1002.10\n\n### Cash Flow\n`cashFlow(loanAmount, interestRate, tenureMonths, amortizationFreeMonths, invoiceFee)`\n\n#### Parameters\n- _loanAmount_ the total loan amount including capitalized fees (e.g. startup fee)\n- _interestRate_ the annual nominal interest\n- _tenureYears_ the tenure of the loan in number of years\n- _amortizationFreeMonths_ the number of initial amortization free months, default to 0\n- _invoiceFee_ a fee for each statement invoiced, default to 0\n\n#### Value\n_returns_ an array of doubles of cachFlow entries for each period\n\n#### Example\n```r\nvar cf = Financials.cashFlow(50000, 0.035, 5, 6, 30)\n```\n\n### Payment Plan\n`paymentPlan(loanAmount, interestRate, tenureMonths, amortizationFreeMonths = 0, invoiceFee = 0)`\n\n#### Parameters\n- _loanAmount_ the total loan amount including capitalized fees (e.g. startup fee)\n- _interestRate_ the annual nominal interest\n- _tenureMonths_ the total tenure of the loan in number of months\n- _amortizationFreeMonths_ the number of initial amortization free months, default to 0\n- _invoiceFee_ a fee for each statement invoiced, default to 0\n\n#### Value\n_returns_ a List of Payment with the initial payment plan based on the input, based on monthly payment periods\n\n#### Example\n\n```groovy\nvar loanAmt = 10000;\nvar tenureYears = (int)(1.5 * 12);\nvar amortizationFreeMonths = 6;\nvar interest = BigDecimal.valueOf(3.5 / 100);\nvar invoiceFee = BigDecimal.valueOf(30);\n\nvar paymentPlan = Financials.paymentPlan(loanAmt, interest, tenureYears, amortizationFreeMonths, invoiceFee);\nSystem.out.println(paymentPlan);\n```\n\nwhich will the following output:\n\n| month\t | costOfCredit | interestAmt | amortization | invoiceFee | outgoingBalance | cashFlow  |\n|--------|--------------|-------------|--------------|------------|-----------------|-----------|\n| 0      | 0.00         | 0.00        | 0.00         | 0.00       | 10000.00        | -10000.00 |\n| 1      | 29.17        | 29.17       | 0.00         | 30.00      | 10000.00        | 59.17     |\n| 2      | 29.17        | 29.17       | 0.00         | 30.00      | 10000.00        | 59.17     |\n| 3      | 29.17        | 29.17       | 0.00         | 30.00      | 10000.00        | 59.17     |\n| 4      | 29.17        | 29.17       | 0.00         | 30.00      | 10000.00        | 59.17     |\n| 5      | 29.17        | 29.17       | 0.00         | 30.00      | 10000.00        | 59.17     |\n| 6      | 29.17        | 29.17       | 0.00         | 30.00      | 10000.00        | 59.17     |\n| 7      | 849.22       | 29.17       | 820.05       | 30.00      | 9179.95         | 879.22    |\n| 8      | 849.22       | 26.77       | 822.44       | 30.00      | 8357.51         | 879.22    |\n| 9      | 849.22       | 24.38       | 824.84       | 30.00      | 7532.67         | 879.22    |\n| 10     | 849.22       | 21.97       | 827.25       | 30.00      | 6705.42         | 879.22    |\n| 11     | 849.22       | 19.56       | 829.66       | 30.00      | 5875.76         | 879.22    |\n| 12     | 849.22       | 17.14       | 832.08       | 30.00      | 5043.69         | 879.22    |\n| 13     | 849.22       | 14.71       | 834.51       | 30.00      | 4209.18         | 879.22    |\n| 14     | 849.22       | 12.28       | 836.94       | 30.00      | 3372.24         | 879.22    |\n| 15     | 849.22       | 9.84        | 839.38       | 30.00      | 2532.86         | 879.22    |\n| 16     | 849.22       | 7.39        | 841.83       | 30.00      | 1691.03         | 879.22    |\n| 17     | 849.22       | 4.93        | 844.28       | 30.00      | 846.75          | 879.22    |\n| 18     | 849.22       | 2.47        | 846.75       | 30.00      | 0.00            | 879.22    |\n\n### Total Payment amount\n`Financials.totalPaymentAmount(loanAmount, interestRate, tenureMonths, amortizationFreeMonths, invoiceFee)`\n\nTotal Payment amount is the sum of all payments.\n#### Parameters\n- _loanAmount_ the total loan amount including capitalized fees (e.g. startup fee)\n- _interestRate_ the annual nominal interest\n- _tenureMonths_ the total tenure of the loan in number of months\n- _amortizationFreeMonths_ the number of initial amortization free months, default to 0\n- _invoiceFee_ a fee for each statement invoiced, default to 0\n\n#### Value\n_returns_ a double containing the sum of all payments\n\n#### Example\n\n```groovy\nimport static se.alipsa.jfinancials.Financials.*;\n\ndouble loanAmt = 10000;\nint tenureMonths = (int) (1.5 * 12);\nint amortizationFreeMonths = 6;\ndouble interest = 3.5 / 100;\ndouble invoiceFee = 30\n\ndouble totalAmt = totalPaymentAmount(loanAmt, interest, tenureMonths, amortizationFreeMonths, invoiceFee);\nprint(totalAmt);\n```\n```\n11725.645213062116\n```\n\n### Internal Rate of Return\n`double irr(PaymentPlan cf)`\n`double irr(double[] cf)`\n\n#### Parameters\n- _cf_ a cash flow array or PaymentPlan (see the cashFlow or paymentPlan functions)\n#### Value\n_returns_ a double containing the internal return rate\n\n#### Example\nGiven the cache flow above\n\n```groovy\nimport static se.alipsa.jfinancials.Financials.*;\n\nvar internalReturn = irr(paymentPlan.getColumn(\"cashFlow\"));\nSystem.out.println(internalReturn);\n```\noutput:\n```\n 0.00291665871251\n```\n\n### Annual Percentage Rate (a.k.a. effective interest)\n\n`double apr(double monthlyIrr)`\n\n#### Parameters\n- _monthlyIrr_ the MONTHLY internal rate of return (monthly irr)\n\n#### Value\n_Returns_ a double with the annual percentage rate\n\n#### Example\n\n```groovy\nimport static se.alipsa.jfinancials.Financials.*;\n\ndouble annualPercentage = apr(internalReturn)\nprint(annualPercentage)\n```\n```\n0.08934409474458183\n```\n\n### Net present value\n`double npv(double[] cashFlow, double rate)`\n\nNet present value (NPV) is the difference between the present value\nof cash inflows and the present value of cash outflows over a period of time.\nThis function produces the same results as Excel does.\n\n#### Parameters\n- _cashFlow_ cache flow e.g. the cashFlow list of the payment plan\n- _rate_ interest rate\n\n#### Value\n_Returns_ a double with the net present value\n\n#### Examples\n\n```groovy\nimport se.alipsa.jfinancials.Financials.*\n\nSystem.out.println(npv(List.of(-123400, 36200, 54800, 48100), 0.035));\n```\n```\n5908.8656360761\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falipsa%2Fjfinancials","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falipsa%2Fjfinancials","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falipsa%2Fjfinancials/lists"}