diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index 45244cd1..14aae8b4 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -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. | diff --git a/ENDPOINTS.md b/ENDPOINTS.md index 07b6f905..a5f4f349 100644 --- a/ENDPOINTS.md +++ b/ENDPOINTS.md @@ -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 : `{ @@ -2216,6 +2226,7 @@ Sample Output ```py { + "premium_amount": 1200.50 "Tag": "Price Elasticity for Demand Calculator", "price_elasticity": -1.5 } diff --git a/helpers/functions.py b/helpers/functions.py index 7f09ff09..e399efe2 100644 --- a/helpers/functions.py +++ b/helpers/functions.py @@ -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): diff --git a/main.py b/main.py index 3673b28c..da264914 100644 --- a/main.py +++ b/main.py @@ -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 @@ -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( @@ -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 ) \ No newline at end of file + request.final_quantity ) diff --git a/tasks/PolicyPremium.py b/tasks/PolicyPremium.py new file mode 100644 index 00000000..f5214559 --- /dev/null +++ b/tasks/PolicyPremium.py @@ -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) \ No newline at end of file diff --git a/validators/request_validators.py b/validators/request_validators.py index 1420bdb1..6d224033 100644 --- a/validators/request_validators.py +++ b/validators/request_validators.py @@ -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 \ No newline at end of file + final_quantity: float