Add ReturnOnInvestment to maths#7446
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7446 +/- ##
============================================
- Coverage 79.72% 79.72% -0.01%
- Complexity 7298 7300 +2
============================================
Files 803 804 +1
Lines 23762 23771 +9
Branches 4674 4675 +1
============================================
+ Hits 18945 18952 +7
Misses 4059 4059
- Partials 758 760 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Thanks for the contribution. The implementation itself is correct and the tests cover the basic cases well. However, I am not fully convinced that this belongs in TheAlgorithms/Java as an algorithm. This is essentially a direct one-line financial formula rather than an algorithmic implementation. Accepting this may also set a precedent for many similar financial-ratio helper methods. I would not approve this as-is... |
|
Thanks for the feedback! I've expanded the implementation to address the concern. The class now includes Annualized ROI = ((1 + ROI/100)^(1/n) - 1) x 100 This chains the simple ROI calculation, applies |
Extends the ROI class with annualizedReturnOnInvestment(), which applies the geometric-mean formula to convert a total ROI over n years into an equivalent annual rate. Adds 8 new tests covering one-year identity, multi-year, fractional-year, break-even, negative ROI, and invalid inputs.
7bee01c to
2bced69
Compare
Description
Adds
ReturnOnInvestmentto themathspackage.Return on Investment (ROI) is a fundamental financial metric that quantifies how profitable an investment is relative to its cost:
What's included
ReturnOnInvestment.java— clean implementation with Javadoc andIllegalArgumentExceptionfor invalid costReturnOnInvestmentTest.java— 6 JUnit 5 tests covering positive, zero, and negative ROI, plus error pathsChecklist
Reference: https://www.investopedia.com/terms/r/returnoninvestment.asp