Skip to content

Commit

Permalink
Merge pull request #441 from shraddha761/policyPremium
Browse files Browse the repository at this point in the history
Policy premium endpoint is added
  • Loading branch information
ighoshsubho authored Jul 14, 2023
2 parents 1fb7af7 + 8ed3459 commit 1134223
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 3 deletions.
6 changes: 6 additions & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@
| | | - `cost_of_goods_sold` (float): The total cost related to producing goods sold by a business. |
| | | - `net_credit_sales` (float): Sales where the cash is collected at a later date. |
|----------------------------|----------------------------------------|----------------------------------------------------------------------|
| GET /policy_premium | Calculate Policy Premium | - `policy_type` (str): The type of insurance policy. |
| | | - `age` (int): The age of the policyholder. |
| | | - `coverage_amount` (int): The desired coverage amount for the policy. |
| | | - `deductible` (int): The deductible amount for the policy.|
| | | - `num_claims` (int): The number of claims made by the policyholder. |
| | | - `num_accidents` (int): The number of accidents the policyholder has been involved in. |
| GET /price_elasticity | Price Elasticity for Demand Calculator | - `initial_price` (float):
The initial price of the product or service. |
| | | - `final_price` (float): The final price of the product or service. |
Expand Down
11 changes: 11 additions & 0 deletions ENDPOINTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2204,6 +2204,16 @@ Sample Output
"Cash Conversion Cycle": 90.64 days",
}
```
**POST** `/policy-premium`
- Request body : `{
"policy_type": "auto",
"age": 35,
"coverage_amount": 250000,
"deductible": 500,
"num_claims": 0,
"num_accidents": 1
**POST** `/price-elasticity`
- Request body : `{
Expand All @@ -2216,6 +2226,7 @@ Sample Output
```py
{
"premium_amount": 1200.50
"Tag": "Price Elasticity for Demand Calculator",
"price_elasticity": -1.5
}
Expand Down
16 changes: 16 additions & 0 deletions helpers/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2022,6 +2022,22 @@ def cash_conversion_cycle(beginning_inventory: float, ending_inventory: float, b
ccc = days_of_inventory_outstanding + days_of_sales_outstanding - days_of_payables_outstanding
return ccc

# Function to Calculate Policy Premium.

def calculate_policy_premium_ratios(premiums_collected, claims_paid, commissions_paid, operating_expenses):
loss_ratio = (claims_paid / premiums_collected) * 100
expense_ratio = ((commissions_paid + operating_expenses) / premiums_collected) * 100
combined_ratio = loss_ratio + expense_ratio
profit_margin = 100 - combined_ratio

ratios = {
"loss_ratio": loss_ratio,
"expense_ratio": expense_ratio,
"combined_ratio": combined_ratio,
"profit_margin": profit_margin
}

return ratios
# Function to Calculate Price Elasticity for demand Calculator

def calculate_price_elasticity(initial_price: float, final_price: float, initial_quantity: float, final_quantity: float):
Expand Down
20 changes: 18 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@
from tasks.defensive_interval_ratio import defensive_interval_ratio_task
from tasks.RateofReturn import calculate_rate_of_return
from tasks.cash_conversion_cycle import cash_conversion_cycle_task
from validators.request_validators import SimpleInterestRateRequest, calculatePension, compoundInterest, futureSip, paybackPeriod, capmRequest, DebtServiceCoverageRatio, futureValueOfAnnuity, futureValueOfAnnuityDue, ProfitPercentage, LossPercentage, DefensiveIntervalRatio, CashConversionCycle, RateofReturn, financialAssestRatio, PriceElasticity
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 tasks.financialAssestRatio import financial_assest_ratio
from tasks.PriceElasticity import calculate_price_elasticity

Expand Down Expand Up @@ -1924,6 +1926,20 @@ def cash_conversion_cycle(request: CashConversionCycle):
request.beginning_receivables, request.ending_receivables , request.beginning_payable,
request.ending_payable , request.net_credit_sales , request.cost_of_goods_sold)

# Endpoint to calculate Policy Premium

@app.post(
"/policy_premium",
tags=["policy_premium"],
description="Calculate Policy premium",
)
def policy_premium(request: PolicyPremium):
return calculate_policy_premium(request.policy_type,
request.age,
request.coverage_amount,
request.deductible,
request.num_claims,
request.num_accidents)
# Endpoint to calculate Price Elasticity

@app.post(
Expand All @@ -1935,4 +1951,4 @@ def price_elasticity(request: PriceElasticity):
return calculate_price_elasticity(request.initial_price ,
request.final_price ,
request.initial_quantity,
request.final_quantity )
request.final_quantity )
45 changes: 45 additions & 0 deletions tasks/PolicyPremium.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from helpers import functions
from fastapi import HTTPException, status

def calculate_policy_premium(policy_type: str, age: int, coverage_amount: int, deductible: int, num_claims: int, num_accidents: int):
try:
policy_factors = {
"auto": {
"age": {
"18-25": 1.5,
"26-40": 1.2,
"41-60": 1.0,
"61+": 1.3
},
"claims": {
"0": 1.0,
"1-3": 1.2,
"4+": 1.5
},
"accidents": {
"0": 1.0,
"1-2": 1.2,
"3+": 1.5
}
},
}

if policy_type not in policy_factors:
return None

factors = policy_factors[policy_type]

base_premium = coverage_amount * 0.01
age_multiplier = factors["age"].get(age, 1.0)
claims_multiplier = factors["claims"].get(num_claims, 1.0)
accidents_multiplier = factors["accidents"].get(num_accidents, 1.0)
deductible_factor = 1 - (deductible / coverage_amount)

premium_amount = base_premium * age_multiplier * claims_multiplier * accidents_multiplier * deductible_factor

return {
"Tag": "Debt Service Coverage Ratio",
"Premium Amount": premium_amount,
}
except:
return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR)
11 changes: 10 additions & 1 deletion validators/request_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,9 +628,18 @@ class CashConversionCycle(BaseModel):
ending_payable: float
cost_of_goods_sold: float
net_credit_sales: float

class PolicyPremium(BaseModel):
policy_type: str
age: int
coverage_amount: int
deductible: int
num_claims: int
num_accidents: int


class PriceElasticity(BaseModel):
initial_price: float
final_price: float
initial_quantity: float
final_quantity: float
final_quantity: float

0 comments on commit 1134223

Please sign in to comment.