{"id":24744601,"url":"https://github.com/piyush-bhatt/finance","last_synced_at":"2026-05-01T02:33:37.732Z","repository":{"id":62421868,"uuid":"330153154","full_name":"piyush-bhatt/finance","owner":"piyush-bhatt","description":"Deno module for common financial calculations","archived":false,"fork":false,"pushed_at":"2021-01-16T14:11:28.000Z","size":14,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-20T22:07:39.224Z","etag":null,"topics":["deno","finance","typescript"],"latest_commit_sha":null,"homepage":"https://deno.land/x/finance","language":"TypeScript","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/piyush-bhatt.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}},"created_at":"2021-01-16T12:03:29.000Z","updated_at":"2023-09-25T02:48:06.000Z","dependencies_parsed_at":"2022-11-01T17:32:36.903Z","dependency_job_id":null,"html_url":"https://github.com/piyush-bhatt/finance","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/piyush-bhatt/finance","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piyush-bhatt%2Ffinance","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piyush-bhatt%2Ffinance/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piyush-bhatt%2Ffinance/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piyush-bhatt%2Ffinance/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/piyush-bhatt","download_url":"https://codeload.github.com/piyush-bhatt/finance/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/piyush-bhatt%2Ffinance/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32483406,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"online","status_checked_at":"2026-05-01T02:00:05.856Z","response_time":64,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["deno","finance","typescript"],"created_at":"2025-01-28T02:19:08.184Z","updated_at":"2026-05-01T02:33:37.705Z","avatar_url":"https://github.com/piyush-bhatt.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Finance\n==========\n\n\u003cdiv class=\"wrappper\"\u003e\n\n \u003ch2 id=\"intro\"\u003eIntroduction\u003c/h2\u003e\n\n \u003cp\u003eFinance is a Deno module based on \u003ca href=\"https://github.com/ebradyjobory/finance.js\"\u003eFinance.js\u003c/a\u003e. It makes it easy to incorporate common financial calculations into your application.\u003c/p\u003e\n\n \u003cp\u003eThis project is available on \u003ca href=\"https://github.com/piyush-bhatt/finance\"\u003eGitHub\u003c/a\u003e and \u003ca href=\"https://deno.land/x/finance\"\u003eDenoLand\u003c/a\u003e. You can report bugs and discuss features on the \u003ca href=\"https://github.com/piyush-bhatt/finance/issues\"\u003eGitHub issues page\u003c/a\u003e. It is available for use under the \u003ca href=\"https://github.com/piyush-bhatt/finance/blob/master/LICENSE\"\u003eMIT software license\u003c/a\u003e.\n\n \u003ch2 id=\"import\"\u003eImport Module\u003c/h2\u003e\n\n\timport { Finance } from \"https://deno.land/x/finance@1.0.0/mod.ts\"\n\t// or\n\timport { Finance } from \"https://github.com/piyush-bhatt/finance/raw/main/mod.ts\"\n \n \u003ch2 id=\"usage\"\u003eUsage\u003c/h2\u003e\n\n\tconst finance = new Finance();\n\t// To calculate Amortization\n\tfinance.AM(20000, 7.5, 5, 0);\n\t// =\u003e 400.76\n\n \u003ch2 id=\"tests\"\u003eTests\u003c/h2\u003e\n\n \u003cpre\u003e\u003ccode\u003edeno test mod_test.ts\u003c/code\u003e\u003c/pre\u003e\n\n\n\u003ch2 id=\"methods\"\u003eAvailable Methods\u003c/h2\u003e\n\n \u003ch3 id=\"Amortization\"\u003eAmortization\u003cbr\u003e\n\n \u003ccode class=\"highlight\"\u003efinance.AM(principal, rate, total number of payments, [type]);\u003c/code\u003e\u003c/h3\u003e\n\n \u003cp\u003eAmortization is the paying off of debt with a fixed repayment schedule in regular installments over a period of time.\u003csup\u003e\u003ca href=\"http://www.investopedia.com/terms/a/amortization.asp\" target=\"_blank\"\u003e1\u003c/a\u003e\u003c/sup\u003e\u003c/p\u003e\n\n \u003cp\u003eFor total number of payments which are entered as years, \u003ccode\u003e[type]\u003c/code\u003e takes a \u003ccode\u003e0\u003c/code\u003e, whereas for months \u003ccode\u003e[type]\u003c/code\u003e takes a \u003ccode\u003e1\u003c/code\u003e.\u003c/p\u003e\n\n \u003cpre\u003e\u003ccode\u003e#Total Number of Payments Type = Years\n // e.g., If principal is $20,000, rate is 7.5%, total number of payments is 5, and payment type is 0 (years), monthly payment is $400.76.\n\n finance.AM(20000, 7.5, 5, 0);\n =\u003e 400.76\n\n #Total Number of Payments Type = Months\n // e.g.,If principal is $20,000, rate is 7.5%, total number of payments is 60, and payment type is 1 (months), monthly payment is $400.76.\n\n finance.AM(20000, 7.5, 60, 1);\n =\u003e 400.76\u003c/code\u003e\u003c/pre\u003e\n\n \u003ch3 id=\"CAGR\"\u003eCompound Annual Growth Rate (CAGR)\u003cbr\u003e\n\n \u003ccode class=\"highlight\"\u003efinance.CAGR(beginning value, ending value, number of periods);\u003c/code\u003e\u003c/h3\u003e\n\n \u003cp\u003eCompound Annual Growth Rate (CAGR) is the year-over-year growth rate of an investment over a specified period of time.\u003csup\u003e\u003ca href=\"http://www.investopedia.com/terms/c/cagr.asp\" target=\"_blank\"\u003e2\u003c/a\u003e\u003c/sup\u003e\u003c/p\u003e\n\n \u003cpre\u003e\u003ccode\u003e// e.g., If the beginning value is $10,000, the ending value is $19,500, and the number of periods is 3, the CAGR is 24.93%.\n\n finance.CAGR(10000, 19500, 3);\n =\u003e 24.93\u003c/code\u003e\u003c/pre\u003e\n\n \u003ch3 id=\"CI\"\u003eCompound Interest (CI)\u003cbr\u003e\n\n \u003ccode class=\"highlight\"\u003efinance.CI(rate, compoundings per period, principal, number of periods);\u003c/code\u003e\u003c/h3\u003e\n\n \u003cp\u003eCompound Interest is the interest calculated on the initial principal and also on the accumulated interest of previous periods of a deposit or loan.\u003csup\u003e\u003ca href=\"http://www.investopedia.com/terms/c/compoundinterest.asp\" target=\"_blank\"\u003e3\u003c/a\u003e\u003c/sup\u003e\u003c/p\u003e\n\n \u003cpre\u003e\u003ccode\u003e// e.g., If rate is 4.3%, the compoundings per period is 4, the principal is $1,500, and the number of periods is 6, the compound interest is $1,938.84.\n\n finance.CI(4.3, 4, 1500, 6 );\n =\u003e 1938.84\u003c/code\u003e\u003c/pre\u003e\n\n \u003ch3 id=\"DF\"\u003eDiscount Factor (DF)\u003cbr\u003e\n\n \u003ccode class=\"highlight\"\u003efinance.DF(rate, number of periods);\u003c/code\u003e\u003c/h3\u003e\n\n \u003cp\u003eThe Discount Factor (DF) is the factor by which a future cash flow must be multiplied in order to obtain the present value.\u003csup\u003e\u003ca href=\"http://en.wikipedia.org/wiki/Discounting#Discount_factor\" target=\"_blank\"\u003e4\u003c/a\u003e\u003c/sup\u003e\u003c/p\u003e\n\n \u003cpre\u003e\u003ccode\u003e// e.g., If rate is 10% and the number of periods is 6, the result is an array of discount factors: [1, 0.91, 0.827, 0.752, 0.684].\n\n finance.DF(10, 6);\n =\u003e [1, 0.91, 0.827, 0.752, 0.684]\u003c/code\u003e\u003c/pre\u003e\n\n \u003ch3 id=\"FV\"\u003eFuture Value (FV)\u003cbr\u003e\n\n \u003ccode class=\"highlight\"\u003efinance.FV(rate, cash flow, number of periods);\u003c/code\u003e\u003c/h3\u003e\n\n \u003cp\u003eFuture Value (FV) is the value of an asset or cash at a specified date in the future that is equivalent in value to a specified sum today\u003csup\u003e\u003ca href=\"http://www.investopedia.com/terms/f/futurevalue.asp\" target=\"_blank\"\u003e5\u003c/a\u003e\u003c/sup\u003e\u003c/p\u003e\n\n \u003cpre\u003e\u003ccode\u003e// e.g., If rate is 0.5%, cash flow is $1,000, and the number of periods is 12, the FV is $1,061.68.\n\n finance.FV(0.5, 1000, 12);\n =\u003e 1061.68\u003c/code\u003e\u003c/pre\u003e\n\n \u003ch3 id=\"IRR\"\u003eInternal Rate of Return (IRR)\u003cbr\u003e\n\n \u003ccode class=\"highlight\"\u003efinance.IRR(initial investment, [cash flows]);\u003c/code\u003e\u003c/h3\u003e\n\n \u003cp\u003eInternal Rate of Return (IRR) is the discount rate often used in capital budgeting that makes the net present value of all cash flows from a particular project equal to zero.\u003csup\u003e\u003ca href=\"http://www.investopedia.com/terms/i/irr.asp\" target=\"_blank\"\u003e6\u003c/a\u003e\u003c/sup\u003e\u003c/p\u003e\n\n \u003cpre\u003e\u003ccode\u003e// e.g., If initial investment is -$500,000 and the cash flows are $200,000, $300,000, and $200,000, IRR is 18.82%.\n\n finance.IRR(-500000, [200000, 300000, 200000]);\n =\u003e 18.82\u003c/code\u003e\u003c/pre\u003e\n\n\u003ch3 id=\"XIRR\"\u003eXIRR\u003cbr\u003e\n\n \u003ccode class=\"highlight\"\u003efinance.XIRR([cash flows], [dates], guess);\u003c/code\u003e\u003c/h3\u003e\n\n \u003cp\u003eXIRR is used to determine the Internal Rate of Return when the cash flows are at Irregular intervals.\u003csup\u003e\u003ca href=\"http://www.financialwisdomforum.org/gummy-stuff/xirr.htm\" target=\"_blank\"\u003e15\u003c/a\u003e\u003c/sup\u003e\u003c/p\u003e\n\n \u003cpre\u003e\u003ccode\u003e// e.g., If the cash flows are -$1,000 on 1st Nov 2015, -$100 on 01 Jul 2016 and $1,200 on 19 Jul 2016, the XIRR is 14.11%.\n\n finance.XIRR([-1000, -100, 1200],[new Date(2015, 11, 1 ), new Date(2016, 7, 1 ), new Date(2016, 7, 19 )],0 );\n =\u003e 14.11\u003c/code\u003e\u003c/pre\u003e\n\n \u003ch3 id=\"LR\"\u003eLeverage Ratio (LR)\u003cbr\u003e\n\n \u003ccode class=\"highlight\"\u003efinance.LR(total liabilities, total debts, total income);\u003c/code\u003e\u003c/h3\u003e\n\n \u003cp\u003eLeverage Ratio (LR) is used to calculate the financial leverage of a company or individual to get an idea of the methods of financing or to measure ability to meet financial obligations.\u003csup\u003e\u003ca href=\"http://www.investopedia.com/terms/l/leverageratio.asp\" target=\"_blank\"\u003e7\u003c/a\u003e\u003c/sup\u003e\u003c/p\u003e\n\n \u003cpre\u003e\u003ccode\u003e// e.g., If total liabilities are $25, total debts are $10, and total income is $20, the leverage ratio is 1.75.\n\n finance.LR(25, 10, 20);\n =\u003e 1.75\u003c/code\u003e\u003c/pre\u003e\n\n \u003ch3 id=\"NPV\"\u003eNet Present Value (NPV)\u003cbr\u003e\n\n \u003ccode class=\"highlight\"\u003efinance.NPV(rate, initial investment, [cash flows]);\u003c/code\u003e\u003c/h3\u003e\n\n \u003cp\u003eNet Present Value (NPV) compares the money received in the future to an amount of money received today, while accounting for time and interest [through the discount rate]. It's based on the principal of time value of money (TVM), which explains how time affects monetary value.\u003csup\u003e\u003ca href=\"http://www.investopedia.com/articles/fundamental-analysis/09/net-present-value.asp\" target=\"_blank\"\u003e8\u003c/a\u003e\u003c/sup\u003e\u003c/p\u003e\n\n \u003cp\u003e\u003ccode\u003e[cash flows]\u003c/code\u003e takes any number of projected cash flows.\u003c/p\u003e\n\n \u003cpre\u003e\u003ccode\u003e// e.g., If discount rate is 10%, initial investment is -$1,000, cash flow in year 1 is $200,000, year 2 is $300,000, and year 3 is $200,000, the NPV is $80,015.03.\n\n finance.NPV(10, -500000, [200000, 300000, 200000]);\n =\u003e 80015.03\u003c/code\u003e\u003c/pre\u003e\n\n \u003ch3 id=\"PP\"\u003ePayback Period (PP)\u003cbr\u003e\n\n \u003ccode class=\"highlight\"\u003efinance.PP(number of periods, [cash flows]);\u003c/code\u003e\u003c/h3\u003e\n\n \u003cp\u003ePayback Period (PP) is the length of time required to recover the cost of an investment.\u003csup\u003e\u003ca href=\"http://www.investopedia.com/terms/p/paybackperiod.asp\" target=\"_blank\"\u003e9\u003c/a\u003e\u003c/sup\u003e\u003c/p\u003e\n\n \u003cp\u003e\u003ccode\u003enumber of periods\u003c/code\u003e takes a \u003ccode\u003e0\u003c/code\u003e value for even cash flows;\u003cbr\u003efor uneven cash flows, \u003ccode\u003enumber of periods\u003c/code\u003e takes any number of projected periods.\u003c/p\u003e\n\n \u003cp\u003e\u003ccode\u003e[cash flows]\u003c/code\u003e takes any number of projected cash flows.\u003c/p\u003e\n\n \u003cpre\u003e\u003ccode\u003e#Even Cash Flows\n // e.g., Because even cash flows have the same inflow during each period, we set 'number of periods' to '0.' If initial investment is -$105 and the annual cash flow is $25, the payback period is 4.2 years.\n\n finance.PP(0, [-105, 25]);\n =\u003e 4.2\n\n #Uneven Cash Flows\n // e.g., If number of periods is 5, initial investment is -$50, and the cash flows are $10, $13, $16, $19, and $22 for each year, the payback period is 3.42 years.\n\n finance.PP(5, [-50, 10, 13, 16, 19, 22]);\n =\u003e 3.42\u003c/code\u003e\u003c/pre\u003e\n\n \u003ch3 id=\"PV\"\u003ePresent Value (PV)\u003cbr\u003e\n\n \u003ccode class=\"highlight\"\u003efinance.PV(rate, cash flow, number of periods);\u003c/code\u003e\u003c/h3\u003e\n\n \u003cp\u003ePresent Value (PV) is the current worth of a future sum of money or stream of cash flows given a specified rate of return.\u003csup\u003e\u003ca href=\"http://www.investopedia.com/terms/p/presentvalue.asp\" target=\"_blank\"\u003e10\u003c/a\u003e\u003c/sup\u003e\u003c/p\u003e\n\n\u003cp\u003e\u003ccode\u003enumber of periods\u003c/code\u003e is optional and defaults to \u003ccode\u003e1\u003c/code\u003e.\u003c/p\u003e\n\n \u003cpre\u003e\u003ccode\u003e// e.g., If rate is 5% and cash flow is $100, the PV is $95.24.\n\n finance.PV(5, 100);\n =\u003e 95.24\n\n// e.g., If rate is 5%, cash flow is $100, and number of periods is 5, the PV is $78.35.\n\n finance.PV(5, 100, 5);\n =\u003e 78.35\u003c/code\u003e\u003c/pre\u003e\n\n\n \u003ch3 id=\"PI\"\u003eProfitability Index (PI)\u003cbr\u003e\n\n \u003ccode class=\"highlight\"\u003efinance.PI(rate, initial investment, [cash flows]);\u003c/code\u003e\u003c/h3\u003e\n\n \u003cp\u003eProfitability Index (PI) is an index that attempts to identify the relationship between the costs and benefits of a proposed project through the use of a ratio calculated.\u003csup\u003e\u003ca href=\"http://www.investopedia.com/terms/p/profitability.asp\" target=\"_blank\"\u003e11\u003c/a\u003e\u003c/sup\u003e\u003c/p\u003e\n\n \u003cp\u003e\u003ccode\u003e[cash flows]\u003c/code\u003e takes any number of projected cash flows.\u003c/p\u003e\n\n \u003cpre\u003e\u003ccode\u003e// e.g., If rate is 10%, initial investment is -$40,000, cash flows are $18,000, $12,000, $10,000, $9,000, and $6,000, PI is 1.09.\n\n finance.PI(10, -40000, [18000, 12000, 10000, 9000, 6000]);\n =\u003e 1.09\u003c/code\u003e\u003c/pre\u003e\n\n \u003ch3 id=\"ROI\"\u003eReturn on Investment (ROI)\u003cbr\u003e\n\n \u003ccode class=\"highlight\"\u003efinance.ROI(initial investment, earnings);\u003c/code\u003e\u003c/h3\u003e\n\n \u003cp\u003eReturn on Investment (ROI) is a simple calculation that tells you the bottom line return of any investment.\u003csup\u003e\u003ca href=\"http://www.investopedia.com/articles/basics/10/guide-to-calculating-roi.asp\" target=\"_blank\"\u003e12\u003c/a\u003e\u003c/sup\u003e\u003c/p\u003e\n\n \u003cpre\u003e\u003ccode\u003e// e.g., If initial investment is -$55,000 and the earnings are $60,000, the return on investment is 9.09%.\n\n finance.ROI(-55000, 60000);\n =\u003e 9.09\u003c/code\u003e\u003c/pre\u003e\n\n \u003ch3 id=\"R72\"\u003eRule of 72 (R72)\u003cbr\u003e\n\n \u003ccode class=\"highlight\"\u003efinance.R72(rate);\u003c/code\u003e\u003c/h3\u003e\n\n \u003cp\u003eRule of 72 (R72) is a rule stating that in order to find the number of years required to double your money at a given interest rate, you divide the compound return into 72.\u003csup\u003e\u003ca href=\"http://www.investopedia.com/terms/r/ruleof72.asp\" target=\"_blank\"\u003e13\u003c/a\u003e\u003c/sup\u003e\u003c/p\u003e\n\n \u003cpre\u003e\u003ccode\u003e// e.g., If annual rate is 10%, rule of 72 is 7.2 years.\n\n finance.R72(10);\n =\u003e 7.2\u003c/code\u003e\u003c/pre\u003e\n\n \u003ch3 id=\"WACC\"\u003eWeighted Average Cost of Capital (WACC)\u003cbr\u003e\n\n \u003ccode class=\"highlight\"\u003efinance.WACC(market value of equity, market value of debt, cost of equity, cost of debt, tax rate);\u003c/code\u003e\u003c/h3\u003e\n\n \u003cp\u003eWeighted Average Cost of Capital (WACC) is the rate that a company is expected to pay on average to all its security holders to finance its assets.\u003csup\u003e\u003ca href=\"http://en.wikipedia.org/wiki/Weighted_average_cost_of_capital\" target=\"_blank\"\u003e14\u003c/a\u003e\u003c/sup\u003e\u003c/p\u003e\n\n \u003cpre\u003e\u003ccode\u003e// e.g., If market value of equity is $600,000, market value of debt is $400,000, cost of equity is 6%, cost of debt is 5%, and tax rate is 35%, WACC is 4.9%.\n\n finance.WACC(600000, 400000, 6, 5, 35);\n =\u003e 4.9\u003c/code\u003e\u003c/pre\u003e\n\n \u003ch3 id=\"PMT\"\u003eLoan Payment Per Period (PMT)\u003cbr\u003e\n\n \u003ccode class=\"highlight\"\u003efinance.PMT(fractional interest rate, number of payments, principal);\u003c/code\u003e\u003c/h3\u003e\n\n  \u003cp\u003ePayment for a loan based on constant payments and a constant interest rate\u003c/p\u003e\n\n \u003cpre\u003e\u003ccode\u003e\n   finance.PMT(0.02,36,-1000000);\n =\u003e 39232.8526\u003c/code\u003e\u003c/pre\u003e\n\n \u003ch3 id=\"IAR\"\u003eInflation-adjusted Return\u003cbr\u003e\n\n \u003ccode class=\"highlight\"\u003efinance.IAR(investment Return, inflation Rate);\u003c/code\u003e\u003c/h3\u003e\n\n  \u003cp\u003eMeasure the return taking into account the time period's inflation rate\u003c/p\u003e\n\n \u003cpre\u003e\u003ccode\u003e\n   finance.IAR(0.08, 0.03)\n =\u003e 4.85\u003c/code\u003e\u003c/pre\u003e\n\n### Contributing\n\nContributions are welcome to aid in the expansion of the module. In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality, and please lint and test your code.\n\n### Licensing\n\nMIT Licensed\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiyush-bhatt%2Ffinance","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpiyush-bhatt%2Ffinance","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpiyush-bhatt%2Ffinance/lists"}