File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /**
2+ * @function returnOnInvestment
3+ * @description Calculates Return on Investment (ROI) as a percentage.
4+ * ROI measures the profitability of an investment relative to its cost.
5+ * Formula: ROI = (Gain - Cost) / Cost * 100
6+ * @param {number } gainFromInvestment - Total value gained from the investment
7+ * @param {number } costOfInvestment - Total cost of the investment
8+ * @return {number } ROI as a percentage
9+ * @see https://www.investopedia.com/terms/r/returnoninvestment.asp
10+ * @example returnOnInvestment(1000, 500) = 100
11+ * @example returnOnInvestment(500, 500) = 0
12+ * @example returnOnInvestment(200, 500) = -60
13+ */
14+ export const returnOnInvestment = (
15+ gainFromInvestment : number ,
16+ costOfInvestment : number
17+ ) : number => {
18+ if ( costOfInvestment <= 0 ) {
19+ throw new RangeError ( 'costOfInvestment must be greater than 0' )
20+ }
21+ return ( ( gainFromInvestment - costOfInvestment ) / costOfInvestment ) * 100
22+ }
You can’t perform that action at this time.
0 commit comments