UNPKG

@investo/invform

Version:

A versatile library of investment formulas...

174 lines (127 loc) โ€ข 4.38 kB
# ๐Ÿ“Š @investo/invform A versatile and developer-friendly library of core investment formulas, including NPV, IRR, ROI, DCF, and more โ€” ideal for financial modeling, analytics, and automation. ## Table of Contents - [Features](#Features) - [Installation](#Installation) - [Examples](#Examples) --- ## Features - ๐Ÿ“ˆ Net Present Value (NPV) - ๐Ÿ“‰ Internal Rate of Return (IRR) - ๐Ÿ’ฐ Return on Investment (ROI) - ๐Ÿ“† Discounted Cash Flow (DCF) - ๐Ÿงฎ Time Value of Money calculations - ๐Ÿ”ง Typed and well-documented functions --- ## Installation ```bash npm install @investo/invform ``` ## Examples ### ๐Ÿ“ˆ calculateInvestment Calculates the total investment based on the number of assets, price per asset, and optional fee. ๐Ÿ“ฆ Import ```ts import { calculateInvestment } from "@inveto/invform" ``` ๐Ÿงฎ Signature ```ts calculateInvestment(amount: number, pricePerAsset: number, fee?: number): number ``` ๐Ÿ“‹ Parameters - `amount (number)`: The number of assets purchased. Must be greater than or equal to 0. - `pricePerAsset (number)`: The price of a single asset. Must be greater than or equal to 0. - `fee (number, optional, default = 0)`: Transaction fee. Must be greater than or equal to 0. ๐Ÿงช Usage Examples ```ts calculateInvestment(10, 100, 5); // => 1005 calculateInvestment(10, 100); // => 1000 (if fee is not provided) ``` ### ๐Ÿ“‰ calculateAssetsFromInvestment Calculates how many assets can be purchased with a given investment, price per coin, and optional fee. ๐Ÿ“ฆ Import ```ts import { calculateAssetsFromInvestment } from "@inveto/invform" ``` ๐Ÿงฎ Signature ```ts calculateAssetsFromInvestment(investment: number, pricePerAsset: number, fee?: number): number ``` ๐Ÿ“‹ Parameters - `investment (number)`: Total amount of money available. Must be โ‰ฅ 0. - `pricePerAsset (number)`: Price of a single asset. Must be > 0. - `fee (number, optional, default = 0)`: Optional transaction fee. Must be โ‰ฅ 0. ๐Ÿงช Usage Examples ```ts calculateAssetsFromInvestment(1000, 100, 50); // => 9.5 ``` ### ๐Ÿ’ฐ calculatePricePerAsset Calculates the effective price per asset based on the total investment amount, the number of assets received, and an optional fee. ๐Ÿ“ฆ Import ```ts import { calculatePricePerAsset } from "@inveto/invform" ``` ๐Ÿงฎ Signature ```ts calculatePricePerAsset(investment: number, amount: number, fee?: number): number ``` ๐Ÿ“‹ Parameters - `investment (number)`: Total amount spent. Must be โ‰ฅ 0. - `amount (number)`: Number of assets received. Must be > 0. - `fee (number, optional, default = 0)`: Optional transaction fee. Must be โ‰ฅ 0. ๐Ÿงช Usage Examples ```ts calculatePricePerAsset(1050, 10, 50); // => 100 ``` ### ๐Ÿ’ต calculateNetSaleProceeds Calculates the net proceeds from selling assets, subtracting any transaction fee from the total sale value. ๐Ÿ“ฆ Import ```ts import { calculateNetSaleProceeds } from "@inveto/invform" ``` ๐Ÿงฎ Signature ```ts calculateNetSaleProceeds(amount: number, price: number, fee?: number): number ``` ๐Ÿ“‹ Parameters - `amount (number)`: Number of assets sold. Must be โ‰ฅ 0. - `price (number)`: Selling price per asset. Must be โ‰ฅ 0. - `fee (number, optional, default = 0)`: Transaction fee. Must be โ‰ฅ 0. ๐Ÿงช Usage Examples ```ts calculateNetSaleProceeds(10, 50, 20); // => 480 ``` ### ๐Ÿ“Š calculateProfit Calculates the profit (or loss) from selling an asset. ๐Ÿ“ฆ Import ```ts import { calculateProfit } from "@inveto/invform" ``` ๐Ÿงฎ Signature ```ts calculateProfit(saleProceeds: number, investment: number): number ``` ๐Ÿ“‹ Parameters - `saleProceeds (number)`: The amount received from selling the asset. Must be โ‰ฅ 0. - `investment (number)`: The total amount originally invested. Must be โ‰ฅ 0. ๐Ÿงช Usage Examples ```ts calculateProfit(1100, 900); // => 200 ``` ### ๐Ÿฆ calculateRemainingInvestment Calculates the remaining investment after a partial withdrawal. ๐Ÿ“ฆ Import ```ts import { calculateRemainingInvestment } from "@inveto/invform" ``` ๐Ÿงฎ Signature ```ts calculateRemainingInvestment(initialInvestment: number, withdrawnAmount: number): number ``` ๐Ÿ“‹ Parameters - `initialInvestment (number)`: The original total investment. Must be โ‰ฅ 0. - `withdrawnAmount (number)`: The amount withdrawn. Must be โ‰ฅ 0. ๐Ÿงช Usage Examples ```ts calculateRemainingInvestment(10000, 4000); // => 6000 ```