adamsaghy commented on code in PR #3902:
URL: https://github.com/apache/fineract/pull/3902#discussion_r1615778262


##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanproduct/ratefactor/RateFactorFunctions.java:
##########
@@ -0,0 +1,134 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.portfolio.loanproduct.ratefactor;
+
+import java.math.BigDecimal;
+import java.math.MathContext;
+import java.time.LocalDate;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.fineract.infrastructure.core.service.DateUtils;
+import org.apache.fineract.organisation.monetary.domain.MoneyHelper;
+import org.apache.fineract.portfolio.common.domain.DaysInYearType;
+import 
org.apache.fineract.portfolio.loanaccount.domain.LoanRepaymentScheduleInstallment;
+
+public class RateFactorFunctions {
+
+    public static final Integer PRECISION = 8;
+
+    protected RateFactorFunctions() {}
+
+    /**
+     * 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:
+     *
+     *
+     * R = 1 + (r * d / y)
+     *
+     * @param interestRate
+     *            (r)
+     * @param daysInPeriod
+     *            (d)
+     * @param daysInYear
+     *            (y)
+     */
+    public static BigDecimal rateFactor(final BigDecimal interestRate, final 
Long daysInPeriod, final Integer daysInYear,
+            final Integer precision) {
+        final BigDecimal daysPeriod = BigDecimal.valueOf(daysInPeriod);
+        BigDecimal daysYear = BigDecimal.valueOf(daysInYear);
+        final MathContext mc = new MathContext(precision, 
MoneyHelper.getRoundingMode());
+
+        return 
BigDecimal.ONE.add(interestRate.multiply(daysPeriod.divide(daysYear, mc), mc), 
mc);
+    }
+
+    /**
+     * To calculate the function value for each period, we are going to use 
the next formula:
+     *
+     * fn = 1 + fnValueFrom * rateFactorEnd
+     *
+     * @param periodFrom
+     *
+     * @param periodEnd
+     *
+     * @param mathContext
+     *
+     */
+    public static RateFactorPeriodData fnValue(RateFactorPeriodData 
periodFrom, final RateFactorPeriodData periodEnd,

Review Comment:
   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.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to