Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions maths/return_on_investment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

# Calculates Return on Investment (ROI) as a percentage.
# ROI measures the profitability of an investment relative to its cost.
#
# Formula: ROI = (Gain - Cost) / Cost * 100
# Reference: https://www.investopedia.com/terms/r/returnoninvestment.asp
class ReturnOnInvestment
def self.call(gain_from_investment, cost_of_investment)
raise ArgumentError, 'cost_of_investment must be greater than 0' if cost_of_investment <= 0

(gain_from_investment - cost_of_investment).to_f / cost_of_investment * 100
end
end