From 79fcd46e8f0ac0dfd1abcbcf9f80823ff5a2320d Mon Sep 17 00:00:00 2001 From: Shraddha Singh Date: Fri, 21 Jul 2023 22:23:58 +0530 Subject: [PATCH 1/2] Loan eligibility endpoint is added --- DOCUMENTATION.md | 6 ++++++ ENDPOINTS.md | 21 +++++++++++++++++++++ helpers/functions.py | 10 ++++++++++ main.py | 17 +++++++++++++++-- tasks/loan_eligibility.py | 30 ++++++++++++++++++++++++++++++ validators/request_validators.py | 6 ++++++ 6 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 tasks/loan_eligibility.py diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index 14aae8b4..9a371487 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -62,5 +62,11 @@ The initial price of the product or service. | | | | - `initial_quantity` (float): The initial quantity demanded of the product or service. | | | | - `final_quantity` (float): The final quantity demanded of the product or service. | |----------------------------|----------------------------------------|----------------------------------------------------------------------| +| GET /loan_eligibility_check | Loan Eligibility Calculator | - `credit_score` (float): + An individual's credit score. | +| | | - `monthly_income` (float): The total income earned by the individual on a monthly basis. | +| | | - `existing_debt` (float): The amount of debt the individual already owes. | +| | | - `loan_amount` (float): TThe requested amount of money the individual wants to borrow as a loan. | +|----------------------------|----------------------------------------|----------------------------------------------------------------------| diff --git a/ENDPOINTS.md b/ENDPOINTS.md index a5f4f349..f613326e 100644 --- a/ENDPOINTS.md +++ b/ENDPOINTS.md @@ -2230,4 +2230,25 @@ Sample Output "Tag": "Price Elasticity for Demand Calculator", "price_elasticity": -1.5 } +``` + +**POST** `/loan_eligibility` + +- Request body : `{ + "credit_score": 700, + "monthly_income": 4000, + "existing_debt": 1500, + "loan_amount": 20000 +}` +- Sample output + +```py +{ + "Tag": "Loan Eligibility check", + "loan_eligibility": -1.5 + "loan_terms": 5 years + "loan_amount": 20000 + "interest_rate": 5.5 + "monthly_payment": 375.8333333333333 +} ``` \ No newline at end of file diff --git a/helpers/functions.py b/helpers/functions.py index e399efe2..683ab13c 100644 --- a/helpers/functions.py +++ b/helpers/functions.py @@ -2046,3 +2046,13 @@ def calculate_price_elasticity(initial_price: float, final_price: float, initial price_elasticity = percentage_change_quantity / percentage_change_price return price_elasticity + +# Function to Calculate Loan Eligibility check + +def loan_eligibility_check(credit_score: float, monthly_income: float, existing_debt: float, loan_amount: float): + max_debt_to_income_ratio = 0.4 + max_loan_amount = monthly_income * max_debt_to_income_ratio + if loan_amount > max_loan_amount: + return False + else: + return True \ No newline at end of file diff --git a/main.py b/main.py index da264914..fd18f055 100644 --- a/main.py +++ b/main.py @@ -135,10 +135,10 @@ from tasks.cash_conversion_cycle import cash_conversion_cycle_task from tasks.financialAssestRatio import financial_assest_ratio from tasks.PolicyPremium import calculate_policy_premium -from validators.request_validators import SimpleInterestRateRequest, calculatePension, compoundInterest, futureSip, paybackPeriod, capmRequest, DebtServiceCoverageRatio, futureValueOfAnnuity, futureValueOfAnnuityDue, ProfitPercentage, LossPercentage, DefensiveIntervalRatio, CashConversionCycle, RateofReturn, financialAssestRatio, PriceElasticity, PolicyPremium +from validators.request_validators import SimpleInterestRateRequest, calculatePension, compoundInterest, futureSip, paybackPeriod, capmRequest, DebtServiceCoverageRatio, futureValueOfAnnuity, futureValueOfAnnuityDue, ProfitPercentage, LossPercentage, DefensiveIntervalRatio, CashConversionCycle, RateofReturn, financialAssestRatio, PriceElasticity, PolicyPremium, LoanEligibility from tasks.financialAssestRatio import financial_assest_ratio from tasks.PriceElasticity import calculate_price_elasticity - +from tasks.loan_eligibility import loan_eligibility_check # Creating the app app = FastAPI( title="FinTech API", @@ -1952,3 +1952,16 @@ def price_elasticity(request: PriceElasticity): request.final_price , request.initial_quantity, request.final_quantity ) + +# Endpoint to calculate Loan Eligibility + +@app.post( + "/loan_eligibility_check", + tags=["loan_eligibility_check"], + description="Calculate Loan Eligibility", +) +def loan_eligibility_check(request: LoanEligibility): + return loan_eligibility_check(request.credit_score , + request.monthly_income , + request.existing_debt, + request.loan_amount ) \ No newline at end of file diff --git a/tasks/loan_eligibility.py b/tasks/loan_eligibility.py new file mode 100644 index 00000000..76e9ca66 --- /dev/null +++ b/tasks/loan_eligibility.py @@ -0,0 +1,30 @@ +from helpers import functions +from fastapi import HTTPException, status +def loan_eligibility_check(credit_score: float, monthly_income: float, loan_amount:float): + + try: + max_debt_to_income_ratio = 0.4 + max_loan_amount = monthly_income * max_debt_to_income_ratio + + if loan_amount > max_loan_amount: + loan_eligibility = -1 + loan_terms = "" + interest_rate = 0 + monthly_payment = 0 + loan_agreement = "" + else: + loan_eligibility = loan_amount / 1000 + loan_terms = "5 years" + interest_rate = 5.5 + monthly_payment = (loan_amount * (1 + interest_rate / 100)) / (5 * 12) + loan_agreement = "Loan agreement details" + return { + "loan_eligibility": loan_eligibility, + "loan_terms": loan_terms, + "loan_amount": loan_amount, + "interest_rate": interest_rate, + "monthly_payment": monthly_payment, + "loan_agreement": loan_agreement + } + except: + return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR) \ No newline at end of file diff --git a/validators/request_validators.py b/validators/request_validators.py index 6d224033..33a760f9 100644 --- a/validators/request_validators.py +++ b/validators/request_validators.py @@ -643,3 +643,9 @@ class PriceElasticity(BaseModel): final_price: float initial_quantity: float final_quantity: float + +class LoanEligibility(BaseModel): + credit_score: float + monthly_income: float + existing_debt: float + loan_amount: float From f6f763c6cfc8cc9f5aff462b968bf6cf3e1cc968 Mon Sep 17 00:00:00 2001 From: shraddha761 <106100728+shraddha761@users.noreply.github.com> Date: Sat, 29 Jul 2023 22:05:25 +0530 Subject: [PATCH 2/2] Update loan_eligibility.py --- tasks/loan_eligibility.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/loan_eligibility.py b/tasks/loan_eligibility.py index 76e9ca66..c3c84bb9 100644 --- a/tasks/loan_eligibility.py +++ b/tasks/loan_eligibility.py @@ -1,5 +1,5 @@ -from helpers import functions from fastapi import HTTPException, status + def loan_eligibility_check(credit_score: float, monthly_income: float, loan_amount:float): try: @@ -27,4 +27,4 @@ def loan_eligibility_check(credit_score: float, monthly_income: float, loan_amo "loan_agreement": loan_agreement } except: - return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR) \ No newline at end of file + return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)