Skip to content

Conversation

@alberto-art3ch
Copy link
Contributor

Description

In order to calculate the monthly payment, we first need to calculate something called the Rate Factor. We're going to be using simple interest. The Rate Factor for simple interest is calculated by the following formula:

FINERACT-1981

Checklist

Please make sure these boxes are checked before submitting your pull request - thanks!

  • Write the commit message as per https://github.com/apache/fineract/#pull-requests

  • Acknowledge that we will not review PRs that are not passing the build ("green") - it is your responsibility to get a proposed PR to pass the build, not primarily the project's maintainers.

  • Create/update unit or integration tests for verifying the changes made.

  • Follow coding conventions at https://cwiki.apache.org/confluence/display/FINERACT/Coding+Conventions.

  • Add required Swagger annotation and update API documentation at fineract-provider/src/main/resources/static/legacy-docs/apiLive.htm with details of any API changes

  • Submission is not a "code dump". (Large changes can be made "in repository" via a branch. Ask on the developer mailing list for guidance, if required.)

FYI our guidelines for code reviews are at https://cwiki.apache.org/confluence/display/FINERACT/Code+Review+Guide.

@alberto-art3ch alberto-art3ch force-pushed the enhancement/loan_simple_interest branch 3 times, most recently from 74155cb to 7a3d244 Compare May 25, 2024 21:09
@alberto-art3ch alberto-art3ch changed the title FINERACT-1981: Rate factor using simple interest for EMI calculation FINERACT-1981: Calculate EMI using rate factor May 25, 2024
Copy link
Contributor

Choose a reason for hiding this comment

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

this can be final as well, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! updated

Copy link
Contributor

Choose a reason for hiding this comment

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

I dont think we need to convert this to BigDecimal

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe the fnValue calculation was not part of the original PR... I am hesitant whether these methods should be moved to the next PR, or this PR to be renamed as it is not only calculating the rate factor now.

periodFrom and periodEnd sounds a little bit confusing to me. I would recommend: previous period and actual period to be used.

Also i would prefer if not the objects are provided, rather the required parameters. This way we can avoid getting object as parameter and working on the objects and returning one of the object (which in this case it is unnecessary).

Something like this:
public static BigDecimal fnValue(BigDecimal previousFnValue, BigDecimal rateFactor)

This way the method is focusing on the calculation only and not focusing on what object needs to be built.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! code removed from this PR

Copy link
Contributor

@adamsaghy adamsaghy May 27, 2024

Choose a reason for hiding this comment

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

Why do we need to set the precision to 8? I believe the MoneyHelper MathContext is working with 12 precision and database we support 6 after the decimal point (usually). We might need to discuss whether we need something different here... i would say the MoneyHelper MathContext precision is the favoured to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! We are using the MatchContext from MoneyHelper

Copy link
Contributor

Choose a reason for hiding this comment

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

We dont need to rescale. The MathContext should contain the required precision.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! code removed from this PR

Copy link
Contributor

Choose a reason for hiding this comment

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

This condition is unnecessary:
rnValue = rnValue.multiply(rateFactorPeriod.getRateFactor(), mc); gives you the right value even it is the 1st period.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! code removed from this PR

Copy link
Contributor

Choose a reason for hiding this comment

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

I am assuming this one is mimicking when we convert it to Money object, but it would be better instead of mimicking actually convert it to Money

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done! code removed from this PR

Copy link
Contributor

@adamsaghy adamsaghy left a comment

Choose a reason for hiding this comment

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

Kindly see my comments!

@alberto-art3ch alberto-art3ch force-pushed the enhancement/loan_simple_interest branch from 7a3d244 to d52fd93 Compare May 27, 2024 14:11
@alberto-art3ch alberto-art3ch changed the title FINERACT-1981: Calculate EMI using rate factor FINERACT-1981: Rate factor using simple interest for EMI calculation May 27, 2024
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be better if the MathContext comes as parameter ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@alberto-art3ch alberto-art3ch force-pushed the enhancement/loan_simple_interest branch from d52fd93 to d554d62 Compare May 27, 2024 18:23
Copy link
Contributor

@adamsaghy adamsaghy left a comment

Choose a reason for hiding this comment

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

LGTM

@alberto-art3ch alberto-art3ch force-pushed the enhancement/loan_simple_interest branch from d554d62 to f2d58cb Compare May 27, 2024 18:59
Copy link
Contributor

@adamsaghy adamsaghy left a comment

Choose a reason for hiding this comment

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

LGTM

@adamsaghy adamsaghy merged commit 8853166 into apache:develop May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants