Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: Added NPV, Compound Interest and Payback Period #936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
siriak merged 8 commits into TheAlgorithms:master from showmyth:finstuff
Oct 27, 2025

Conversation

@showmyth
Copy link
Contributor

@showmyth showmyth commented Oct 26, 2025

Pull Request Template

Description

Added 3 different algotrithms, namely:

  1. NPV (Net Present Value): Tells us how much a given series of future payments and receipts is worth in today's money.
  2. Compound Interest: Interest calculated on the initial principal amount as well as the accumulated interest from previous periods.
  3. Payback Period: Tells one how long it will take to recover his/her initial investment using the project's cash flow.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

Checklist:

  • I ran bellow commands using the latest version of rust nightly.
  • I ran cargo clippy --all -- -D warnings just before my last commit and fixed any issue that was found.
  • I ran cargo fmt just before my last commit.
  • I ran cargo test just before my last commit and all tests passed.
  • I added my algorithm to the corresponding mod.rs file within its own folder, and in any parent folder(s).
  • I added my algorithm to DIRECTORY.md with the correct link.
  • I checked COUNTRIBUTING.md and my code follows its guidelines.

Please make sure that if there is a test that takes too long to run ( > 300ms), you #[ignore] that or
try to optimize your code or make the test easier to run. We have this rule because we have hundreds of
tests to run; If each one of them took 300ms, we would have to wait for a long time.

Copy link

codecov-commenter commented Oct 26, 2025
edited
Loading

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.37%. Comparing base (bd8418f) to head (5b64143).

Additional details and impacted files
@@ Coverage Diff @@
## master #936 +/- ##
=======================================
 Coverage 95.37% 95.37% 
=======================================
 Files 327 327 
 Lines 21153 21153 
=======================================
 Hits 20174 20174 
 Misses 979 979 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor Author

Hey @siriak ! Pinging for a review again for when you're free. Thanks!

@siriak siriak requested a review from Copilot October 26, 2025 19:40
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds three new financial calculation algorithms to the financial module: Net Present Value (NPV), Compound Interest, and Payback Period. These algorithms enable users to perform common financial computations such as evaluating investment profitability, calculating accumulated interest, and determining investment recovery timelines.

  • Implements NPV algorithm to calculate present value of cash flows with discount rate
  • Implements compound interest calculation using the formula A = P(1+r/n)^nt
  • Implements payback period calculation to determine investment recovery time

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/financial/npv.rs Adds NPV calculation function with test coverage for basic cases, zero rate, and empty inputs
src/financial/compound_interest.rs Implements compound interest formula with quarterly compounding test case
src/financial/payback.rs Adds payback period calculation with tests for successful and failed payback scenarios
src/financial/mod.rs Exports the three new financial calculation functions
DIRECTORY.md Documents the new financial algorithms in the project directory

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

siriak commented Oct 26, 2025

Check comments

Copy link
Contributor Author

should be fixed now

@siriak siriak requested a review from Copilot October 27, 2025 07:24
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Member

@siriak siriak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@siriak siriak merged commit b39484d into TheAlgorithms:master Oct 27, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot Copilot left review comments

@siriak siriak siriak approved these changes

@imp2002 imp2002 Awaiting requested review from imp2002

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /