@investo/invform
Version:
A versatile library of investment formulas...
174 lines (127 loc) โข 4.38 kB
Markdown
# ๐ @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
```