Skip to content

Commit 28f4bf1

Browse files
Add ReturnOnInvestment to maths
1 parent bda11bd commit 28f4bf1

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

maths/return_on_investment.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
# Calculates Return on Investment (ROI) as a percentage.
4+
# ROI measures the profitability of an investment relative to its cost.
5+
#
6+
# Formula: ROI = (Gain - Cost) / Cost * 100
7+
# Reference: https://www.investopedia.com/terms/r/returnoninvestment.asp
8+
class ReturnOnInvestment
9+
def self.call(gain_from_investment, cost_of_investment)
10+
raise ArgumentError, 'cost_of_investment must be greater than 0' if cost_of_investment <= 0
11+
12+
(gain_from_investment - cost_of_investment).to_f / cost_of_investment * 100
13+
end
14+
end

0 commit comments

Comments
 (0)