The world of finance can be quite complicated. That’s why we chose a Loan Calculator as our next sample application. In this article, we’ll provide a detailed and easy-to-understand technical guide for the sample application and the logic implemented in DecisionRules.
By the end of this article, you’ll have a clear understanding of the application and the individual rules responsible for its functionality. If you want to replicate the rules that are used in our loan calculator, you can download the source files by clicking the download button bellow:
If you don’t know what a sample application is, be sure to check out our previous article: decisionrules.io/articles/decisionrules-in-action.
All available sample applications are available at samples.decisionrules.io.
In order to fully understand what our sample application does and the logic used inside of it, it’s important to answer a few questions:
Now that we know all of these terms, we can answer one final question:
Description of the application runtime diagram:
Our logic inside DecisionRules is divided into 3 main parts. In this section, we’ll describe all of these parts in detail.
This Rule Flow is responsible for the calculation/determination of the interest rate, monthly payment, total payment, and APR values. It calculates/determines these values using the input data (loanAmount and loanDuration values) from the web application, and predefined formulas and conditions inside DecisionRules. As you can see in the diagram image above, the Rule Flow is made up of two Decision Tables and one Scripting Rule.
Description of the Rule Flow diagram:
In the code snippet below, you can see a commented example of the input and output model.
The purpose of this rule is to determine the interestRate value based on predefined conditions for the loanAmount and loanDuration values.
The purpose of this rule is to calculate the monthlyPayment and totalPayment values using predefined financial formulas shown in the code snippets below:
The purpose of this scripting rule is to calculate the APR (Annual Percentage Rate) for a loan based on the loan amount, monthly payment, and loan duration. In order to calculate the value of the APR, the scripting rule uses a “Newton's method” algorithm.
You may be asking, what is an APR?
In the code snippet below, you can see our implementation of the APR calculator scripting rule, accompanied by the individual comments (steps) that walk you through the script and explain what it does in detail:
This Rule Flow is responsible for the determination of the values used in the loan and repayment sliders in the web application, such as the minimal value of the loan slider (loanMin), or the maximal value of the repayment slider (repaymentMonthsMax). It determines these values using the loanAmount value, and predefined conditions inside DecisionRules. As you can see in the diagram image above, the Rule Flow is made up of only two Decision Tables.
Description of the Rule Flow diagram:
In the code snippet below, you can see a commented example of the input and output model:
The purpose of this rule is to determine the loanMin, loanAmount, and loanMax values based on predefined conditions for the loanAmount and loanDuration values. It is also able to determine the "default value" of the loan slider in the web application. This means that when the web application is first loaded, the value of the loan slider will be the value specified in this Loan Slider rule. For instance, if the loanAmount (default value) inside DecisionRules is set to $50,000, then the loan slider will initially show a value of $50,000.
The purpose of this rule is to determine the repaymentMonthsMin and repaymentMonthsMax values based on predefined conditions for the loanAmount and loanDuration values.
This set of rules is responsible for the generation of the Repayment Schedule for an amortized loan based on the loanAmount, loanDuration, and interestRate values. The repayment schedule contains details such as the beginning balance, principal, interest, and ending balance for each payment period. As you can see in the diagram image above, the Rule Flow is made up of one Decision Tables and one Scripting Rule.
Description of the Rule Flow diagram:
In the code snippet below, you can see a commented example of the input and output model:
The purpose of this scripting rule is to generate the Repayment Schedule (calendar array). Each payment period is represented as an object inside the calendar array.
In the code snippet below, you can see our implementation of the Repayment Schedule scripting rule, accompanied by the individual comments (steps) that walk you through the script and explain what it does in detail:
The purpose of this rule is to calculate the values for each repayment period (schedule rows). Each repayment period contains values such as the beginning balance, principal, interest, and ending balance. These values (except beginning balance) are calculated using the predefined financial formulas shown in the code snippets below:
That's all there is to it! With DecisionRules, creating and implementing a complex logic for this loan calculator application is a breeze. In conclusion, the Loan Calculator application is an excellent example of how DecisionRules can be used to perform complex calculations with ease. It also shows how DecisionRules is a powerful tool that can help you automate many of your decision-making processes and reduce the risk of human error. Overall, DecisionRules provides a comprehensive and intuitive platform for developing and deploying automated decision-making systems.
If you want to learn more about how DecisionRules can help and benefit your business, be sure to visit our website or LinkedIn page. You can also speak with our experts about your specific use case or the capabilities of DecisionRules. Our sales team is also available to answer any questions you may have and would be happy to schedule a demo for you to see DecisionRules in action.
Thanks for reading!