Skip to content
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

Loan eligibility endpoint is added #459

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ 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. |
|----------------------------|----------------------------------------|----------------------------------------------------------------------|


| GET /average_payment_period | Calculate Average Payment Period | - `beginning_accounts_payable` (float): The amount of accounts payable beginning the cycle. |
| | | - `ending_inventory` (float): The final amount of accounts payable ending the cycle. |
| | | - `total_credit_purchases` (float): The amount of purchases on credit during the cycle. |
Expand Down
16 changes: 16 additions & 0 deletions ENDPOINTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2269,17 +2269,33 @@ Sample Output
"price_elasticity": -1.5
}
```

**POST** `/loan_eligibility`

- Request body : `{
"credit_score": 700,
"monthly_income": 4000,
"existing_debt": 1500,
"loan_amount": 20000

**POST** `/average_payment_period`

- Request body : `{
"beginning_accounts_payable": 110000,
"ending_accounts_payable": 95000,
"total_credit_purchases": 1110000

}`
- 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
"Tag": "Average Payment Period",
"Beginning Accounts Payable": 110000,
"Ending Accounts Payable": 95000,
Expand Down
9 changes: 9 additions & 0 deletions helpers/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2047,6 +2047,15 @@ def calculate_price_elasticity(initial_price: float, final_price: float, initial

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
# Function to Calculate Average Payment Period

def average_payment_period(beginning_accounts_payable: float, ending_accounts_payable: float,
Expand Down
20 changes: 20 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@
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, LoanEligibility
from tasks.financialAssestRatio import financial_assest_ratio
from tasks.PriceElasticity import calculate_price_elasticity
from tasks.loan_eligibility import loan_eligibility_check
from validators.request_validators import SimpleInterestRateRequest, calculatePension, compoundInterest, futureSip, paybackPeriod, capmRequest, DebtServiceCoverageRatio, futureValueOfAnnuity, futureValueOfAnnuityDue, ProfitPercentage, LossPercentage, DefensiveIntervalRatio, CashConversionCycle, RateofReturn, financialAssestRatio, PriceElasticity, PolicyPremium, AveragePaymentPeriod
from validators.request_validators import SimpleInterestRateRequest, calculatePension, compoundInterest, futureSip, paybackPeriod, capmRequest, DebtServiceCoverageRatio, futureValueOfAnnuity, futureValueOfAnnuityDue, ProfitPercentage, LossPercentage, DefensiveIntervalRatio, CashConversionCycle, RateofReturn, financialAssestRatio, PriceElasticity, PolicyPremium, AveragePaymentPeriod, ModifiedInternalRateOfReturn
from validators.request_validators import SimpleInterestRateRequest, calculatePension, compoundInterest, futureSip, paybackPeriod, capmRequest, DebtServiceCoverageRatio, futureValueOfAnnuity, futureValueOfAnnuityDue, ProfitPercentage, LossPercentage, DefensiveIntervalRatio, CashConversionCycle, RateofReturn, financialAssestRatio, PriceElasticity, PolicyPremium, AveragePaymentPeriod, ModifiedInternalRateOfReturn, SavingGoal, InterestCoverageRatio
from validators.request_validators import SimpleInterestRateRequest, calculatePension, compoundInterest, futureSip, paybackPeriod, capmRequest, DebtServiceCoverageRatio, futureValueOfAnnuity, futureValueOfAnnuityDue, ProfitPercentage, LossPercentage, DefensiveIntervalRatio, CashConversionCycle, RateofReturn, financialAssestRatio, PriceElasticity, PolicyPremium, AveragePaymentPeriod, ModifiedInternalRateOfReturn, SavingGoal, InterestCoverageRatio, MarginOfSafety, TaxBracketCalculator
from tasks.financialAssestRatio import financial_assest_ratio
from tasks.PriceElasticity import calculate_price_elasticity
Expand Down Expand Up @@ -1980,6 +1987,19 @@ def price_elasticity(request: PriceElasticity):
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 )

# Endpoint to calculate Average Payment Period
@app.post(
"/average_payment_period",
Expand Down
30 changes: 30 additions & 0 deletions tasks/loan_eligibility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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)
8 changes: 7 additions & 1 deletion validators/request_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,12 +644,18 @@ class PriceElasticity(BaseModel):
initial_quantity: float
final_quantity: float

class LoanEligibility(BaseModel):
credit_score: float
monthly_income: float
existing_debt: float
loan_amount: float

class AveragePaymentPeriod(BaseModel):
beginning_accounts_payable: float
ending_accounts_payable: float
total_credit_purchases: float

class SavingGoal(BaseModel):
class SavingGoal(BaseModel):
current_savings: float
monthly_contributions : float
interest_rate: float
Expand Down