From b6f45c8f05edbb27d2925cd86dcc1541bef40e41 Mon Sep 17 00:00:00 2001 From: AshirMehmood Date: Mon, 10 Jul 2023 20:46:20 +0500 Subject: [PATCH 1/6] remove bug at line#2903 --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index e56452df..99486258 100644 --- a/main.py +++ b/main.py @@ -2900,7 +2900,7 @@ def calculate_salary(base:int, ptax:int, deduction:int): try: - calculate_salary = functions.calculate_salary(base,jb,stock,pb,bonus,ptax,deduction): + calculate_salary = functions.calculate_salary(base,jb,stock,pb,bonus,ptax,deduction) return { "Tag":"Net Salary Calculator", From b6c0c0119fa2541ec0c314a3ea06c79fc8937e71 Mon Sep 17 00:00:00 2001 From: AshirMehmood Date: Mon, 10 Jul 2023 23:15:00 +0500 Subject: [PATCH 2/6] removed unclear text on line 1668,1693 and 1703 --- main.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index cf9b463d..f1d93cf9 100644 --- a/main.py +++ b/main.py @@ -1665,7 +1665,7 @@ def calculate_expected_return_of_portfolio(no_of_investments: int, "/calculate_salary", tags=["calculate_salary"], description="Calculate Net annual salary of an employee", -<<<<<<< HEAD + ) def calculate_salary(base:int, jb:int, @@ -1690,8 +1690,7 @@ def calculate_salary(base:int, } except: return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR) -======= -) + def calculate_salary(base: int, jb: int, stock: int, @@ -1700,7 +1699,6 @@ def calculate_salary(base: int, ptax: int, deduction: int): return calculate_salary_task(base, jb, stock, pb, bonus, ptax, deduction) ->>>>>>> 9378a9693d83ad3ee0f6894332ad225cca633534 @app.get( From 2543c6ffa0bcf674a98aaeb05acc424184da91c1 Mon Sep 17 00:00:00 2001 From: AshirMehmood Date: Mon, 10 Jul 2023 23:25:37 +0500 Subject: [PATCH 3/6] completed issue #421 --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index f1d93cf9..7bb48c81 100644 --- a/main.py +++ b/main.py @@ -131,7 +131,7 @@ from tasks.profit_percentage import profit_percentage_task from tasks.loss_percentage import loss_percentage_task from tasks.defensive_interval_ratio import defensive_interval_ratio_task -from validators.request_validators import SimpleInterestRateRequest, calculatePension, compoundInterest, futureSip, paybackPeriod, capmRequest, DebtServiceCoverageRatio, futureValueOfAnnuity, ProfitPercentage, LossPercentage, DefensiveIntervalRatio, +from validators.request_validators import SimpleInterestRateRequest, calculatePension, compoundInterest, futureSip, paybackPeriod, capmRequest, DebtServiceCoverageRatio, futureValueOfAnnuity, ProfitPercentage, LossPercentage, DefensiveIntervalRatio # Creating the app app = FastAPI( From edb74180d3c2c0f2710d19c85c40a53589ca07a0 Mon Sep 17 00:00:00 2001 From: AshirMehmood Date: Mon, 10 Jul 2023 23:36:52 +0500 Subject: [PATCH 4/6] typo fix in readme.md --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 56f0e249..83da925c 100644 --- a/Readme.md +++ b/Readme.md @@ -22,7 +22,7 @@ Welcome to FinTech API, our powerful API is designed to simplify your life by of ## ✨ Features -- **Modular structure**: Not the API has a clean structure which benifits in improved code organizationqn and enhanced reusability of components +- **Modular structure**: Not the API has a clean structure which benefits in improved code organization and enhanced reusability of components - **Request validation**: It improves security, prevents errors and vulnerabilities to the API From ba16ee37f94d925859bd8ee8f7496279c6169761 Mon Sep 17 00:00:00 2001 From: AshirMehmood Date: Sun, 23 Jul 2023 17:35:02 +0500 Subject: [PATCH 5/6] added quick and cash ratio --- DOCUMENTATION.md | 42 ++++++- ENDPOINTS.md | 191 ++++++++++++++++++++++++++++--- Readme.md | 1 - helpers/functions.py | 87 ++++++++++++++ main.py | 128 +++++++++++++++++++-- tasks/PolicyPremium.py | 45 ++++++++ tasks/PriceElasticity.py | 15 +++ tasks/RateofReturn.py | 25 ++++ tasks/average_payment_period.py | 20 ++++ tasks/cash_conversion_cycle.py | 33 ++++++ tasks/cash_ratio.py | 17 +++ tasks/financialAssestRatio.py | 27 +++++ tasks/lumpsum.py | 3 +- tasks/quick_ratio.py | 16 +++ validators/request_validators.py | 59 +++++++++- 15 files changed, 678 insertions(+), 31 deletions(-) create mode 100644 tasks/PolicyPremium.py create mode 100644 tasks/PriceElasticity.py create mode 100644 tasks/RateofReturn.py create mode 100644 tasks/average_payment_period.py create mode 100644 tasks/cash_conversion_cycle.py create mode 100644 tasks/cash_ratio.py create mode 100644 tasks/financialAssestRatio.py create mode 100644 tasks/quick_ratio.py diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index 8004f7ee..4429a0ec 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -25,4 +25,44 @@ | | | - `marketable_securities` (float): The amount of marketable_securities.| | | | - `net_receivables` (float): The amount of net_receivables.| | | | - `annual_operating_expenses` (float): The amount of annual_operating_expenses.| -| | | - `non_cash_charges` (float): The amount of non cash charges.| \ No newline at end of file +| | | - `non_cash_charges` (float): The amount of non cash charges.| +|-----------------------------|----------------------------------------------|-----------------------------------------------------------| +| post /rate_of_return | Calculate Rate of Return | - `initial_investment` (float): Initial amount invested. | +| | | - `final_value` (float): the value of the investment at the end of the investment. | +| | | - `time_period` (float): The number of months. | +| | | - `cash_flows` (float): A list of cash flows over the investment period. | +| | | - `holding_period` (float): The specific holding period of the investment. | +| --------------------------- | ---------------------------------------- | --------------------------------------------------------- | +| GET /financial_assest_ratio | Calculate financial assest ratio | - `current_assets` (float): used up within a short period. | +| | | - `current_liabilities` (float): debts that are due . | +| | | - `total_debt` (float): aggregate amount of money. | +| | | - `total_equity`(float): residual interest in the assets. | +| | | - `net_income` (float): net earnings. | +| | | - `total_revenue` (float): sum of all sales. | + +|----------------------------|----------------------------------------|-------------------------------------------------------------------------------| +| GET /cash_conversion_cycle | Calculate Cash Conversion Cycle | - `beginning_inventory` (float): The amount of inventory beginning the cycle. | +| | | - `ending_inventory` (float): The final amount of inventory ending the cycle. | +| | | - `beginning_receivables` (float): The amount of receivables beginning the cycle. | +| | | - `ending_receivables` (float): The final amount of receivables ending the cycle. | +| | | - `beginning_payable` (float): The amount of payable beginning the cycle. | +| | | - `ending_payable` (float): The final amount of payable ending the cycle. | +| | | - `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. | +| | | - `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 /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. | +|-----------------------------|----------------------------------------|---------------------------------------------------------------------| diff --git a/ENDPOINTS.md b/ENDPOINTS.md index d8d581cb..73819f58 100644 --- a/ENDPOINTS.md +++ b/ENDPOINTS.md @@ -2083,7 +2083,16 @@ Sample Output - Request body : `{ "profit": 1560.8, "cost_price": 7500.4 -======= +}` +```py +{ + "Tag": "Profit Percentage", + "Profit": 1560.86, + "Cost Price": 7500.47, + "Profit Percentage": 20.81, +} +``` + **POST** `/defensive_interval_ratio` - Request body : `{ @@ -2094,15 +2103,19 @@ Sample Output "non_cash_charges": 25000.00 }` - Sample output - ```py { - "Tag": "Profit Percentage", - "Profit": 1560.86, - "Cost Price": 7500.47, - "Profit Percentage": 20.81, + "Tag": "Defensive Interval Ratio", + "Cash": 40000.00, + "Marketable Securites": 20000.00, + "Net Receivables": 10000.00, + "Annual Operating Expenses": 300000.00, + "Non Cash Charges": 25000.00, + "Current Assets": 70000.0, + "Daily Operational Expenses": 753.42, + "Defensive Interval Ratio": 92.90 } -``` +``` **POST** `/loss_percent` @@ -2119,15 +2132,159 @@ Sample Output "Cost Price": 7500.47, "Loss Percentage": 6.67, } +``` +**POST** `/rate_return_calculator` + +- Request body : `{ + "initial_investment": 10000, + "final_value": 12500, + "time_period": 3, + "cash_flows": [500, 800, -200], + "holding_period": 2, + +**POST** `/financial_assest_ratio` + +- Request body : `{ + "current_assets": 500000, + "current_liabilities": 300000, + "total_debt": 200000, + "total_equity": 400000, + "net_income": 100000, + "total_revenue": 800000, +}` +- Sample output + +```py +{ + "Tag": "Rate of return", + "rate_of_return": 25.0, + "annualized_return": 8.333333333333334, + "holding_period_return": 50.0, + "Tag": "Financial assest ratio", + "current_ratio": 1.5, + "debt_to_equity_ratio": 0.8, + "return_on_assets": 0.1, + "return_on_equity": 0.15, + "asset_turnover_ratio": 1.8, + "gross_profit_margin": 0.35, + "net_profit_margin": 0.2, + "price_to_earnings_ratio": 20.5 +} ``` - "Tag": "Defensive Interval Ratio", - "Cash": 40000.00, - "Marketable Securites": 20000.00, - "Net Receivables": 10000.00, - "Annual Operating Expenses": 300000.00, - "Non Cash Charges": 25000.00, - "Current Assets": 70000.0, - "Daily Operational Expenses": 753.42, - "Defensive Interval Ratio": 92.90 + +**POST** `/cash_conversion_cycle` + +- Request body : `{ + "beginning_inventory": 1000, + "ending_inventory": 2000, + "beginning_receivables": 100 + "ending_receivables": 90, + "beginning_payable": 800, + "ending_payable": 900, + "cost_of_goods_sold": 3000, + "net_credit_sales": 3000 +}` +- Sample output + +```py +{ + "Tag": "Cash Conversion Cycle", + "Beginning Inventory": 1000, + "Ending Inventory": 2000, + "Average Inventory": 1500, + "Beginning Receivables": 100, + "Ending Receivables": 90, + "Average Receivables": 95, + "Beginning Payable": 800, + "Ending Payable": 900, + "Average Payable": 850, + "Days of inventory_outstanding": 182.5, + "Days of Sales Outstanding": 11.56, + "Days of Payables Outstanding": 103.42, + "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 : `{ + "initial_price": 10.0, + "final_price": 8.0, + "initial_quantity": 1000, + "final_quantity": 1200 +}` +- Sample output + +```py +{ + "premium_amount": 1200.50 + "Tag": "Price Elasticity for Demand Calculator", + "price_elasticity": -1.5 +} +``` + +**POST** `/average_payment_period` + +- Request body : `{ + "beginning_accounts_payable": 110000, + "ending_accounts_payable": 95000, + "total_credit_purchases": 1110000 +}` +- Sample output + +```py +{ + "Tag": "Average Payment Period", + "Beginning Accounts Payable": 110000, + "Ending Accounts Payable": 95000, + "Total Credit Purchases": 1110000, + "Average Accounts Payable": 102500, + "Average Payment Period": "33.7days", +} +``` + +**GET** `/quick_ratio` +- Request body : `{ + "cash" : 20000, + "marketable security" : 10000, + "accounts receivable" : 25000, + "current liabilities" : 5000, +}` +- Sample output + +```py +{ + "Tag": "quick_ratio", + "Total cash as asset" : 20000, + "Total receivable cash": 25000, + "Total marketable security" : 10000, + "Total current liabilities" : 5000, + "quick ratio": 2.0 % +} +``` +**GET** `/cash_ratio` +- Request body : `{ + "cash" : 5000, + "marketable security" : 5000, + "current liabilities" : 10000, +}` +- Sample output + +```py +{ + "Tag" : "cash ratio", + "cash" : 5000, + "marketable security" : 5000, + "current liabilities" : 10000, + "cash ratio" : 1.0 % } -``` \ No newline at end of file +``` \ No newline at end of file diff --git a/Readme.md b/Readme.md index 83da925c..215a05d0 100644 --- a/Readme.md +++ b/Readme.md @@ -1,4 +1,3 @@ -

FinTech API v2

diff --git a/helpers/functions.py b/helpers/functions.py index 97358a5b..fcf70bc1 100644 --- a/helpers/functions.py +++ b/helpers/functions.py @@ -1982,3 +1982,90 @@ def defensive_interval_ratio(cash: float, marketable_securities: float, ratio = current_assets / daily_operational_expenses return ratio +# Function to Calculate Debt Service Coverage Ratio. + +def rate_of_return(initial_investment: float, final_value: float ): + rate_of_return = ((final_value - initial_investment) / initial_investment) * 100 + return rate_of_return + + ## Function to Calculate Financial Assest Ratio + +def calculate_financial_asset_ratios(current_assets, current_liabilities, total_debt, total_equity, net_income, total_revenue, total_assets): + + current_ratio = current_assets / current_liabilities + debt_to_equity_ratio = total_debt / total_equity + return_on_assets = net_income / total_assets + return_on_equity = net_income / total_equity + profit_margin = net_income / total_revenue + + ratios = { + "current_ratio": current_ratio, + "debt_to_equity_ratio": debt_to_equity_ratio, + "return_on_assets": return_on_assets, + "return_on_equity": return_on_equity, + "profit_margin": profit_margin + } + + return ratios + +# Function to Calculate Cash Conversion Cycle + +def cash_conversion_cycle(beginning_inventory: float, ending_inventory: float, beginning_receivables: float, +ending_receivables: float, beginning_payable: float, ending_payable: float, cost_of_goods_sold: float, +net_credit_sales: float): + average_inventory = beginning_inventory - ending_inventory / 2 + average_receivables = beginning_receivables - ending_receivables / 2 + average_payable = beginning_payable - ending_payable / 2 + days_of_inventory_outstanding = (average_inventory / cost_of_goods_sold) * 365 + days_of_sales_outstanding = (average_receivables / net_credit_sales) * 365 + days_of_payables_outstanding = (average_payable / cost_of_goods_sold / 365) + 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): + percentage_change_price = (final_price - initial_price) / initial_price + percentage_change_quantity = (final_quantity - initial_quantity) / initial_quantity + price_elasticity = percentage_change_quantity / percentage_change_price + + return price_elasticity + +# Function to Calculate Average Payment Period + +def average_payment_period(beginning_accounts_payable: float, ending_accounts_payable: float, +total_credit_purchases: float): + average_accounts_payable = (beginning_accounts_payable + ending_accounts_payable) / 2 + app = average_accounts_payable / (total_credit_purchases / 365) + return app + +# Function to Calculate Liquidity ratios + +# 1: Quick ratio +def quick_ratio(cash: float, accounts_recievable: float, marketable_security: float, current_liabilities: float): + quickRatio = (cash + accounts_recievable + marketable_security) / current_liabilities + return quickRatio +# 2: Current ratio (already exists) +# def current_ratio(current_assets: float, current_liabilities: float): +# currentRatio = (current_assets / current_liabilities) +# return currentRatio +# 3: Cash ratio +def cash_ratio(cash: float, marketable_securities: float, current_liabilities: float): + cashRatio = (cash + marketable_securities)/current_liabilities + return cashRatio diff --git a/main.py b/main.py index 7bb48c81..f4d46081 100644 --- a/main.py +++ b/main.py @@ -131,7 +131,16 @@ from tasks.profit_percentage import profit_percentage_task from tasks.loss_percentage import loss_percentage_task from tasks.defensive_interval_ratio import defensive_interval_ratio_task -from validators.request_validators import SimpleInterestRateRequest, calculatePension, compoundInterest, futureSip, paybackPeriod, capmRequest, DebtServiceCoverageRatio, futureValueOfAnnuity, ProfitPercentage, LossPercentage, DefensiveIntervalRatio +from tasks.RateofReturn import calculate_rate_of_return +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, AveragePaymentPeriod +from tasks.financialAssestRatio import financial_assest_ratio +from tasks.PriceElasticity import calculate_price_elasticity +from tasks.average_payment_period import average_payment_period_task +from tasks.quick_ratio import quick_ratio_task +from tasks.quick_ratio import cash_ratio_task # Creating the app app = FastAPI( @@ -263,6 +272,7 @@ def index(): "/portfolio_return_monte_carlo":"Calculates Portfolio returns based on Monte Carlo Simulation", "/profit_percent": "Calculates the profit percentage", "/loss_percent": "Calculates the loss percentage", + "/average_payment_period": "Calculate Average Payment Period a metric that allows a business to see how long it takes on average to pay its vendors." }, } @@ -323,7 +333,7 @@ def future_sip( def calculate_pension( request: calculatePension ): - return calculate_pension_task(request.current_age, request.retirement_age, request.current_salary, request.percentage_saved, request.employer_match, request.expected_annual_raise, request.savings_goal) + return calculate_pension_task(request.monthly_investment_amount, request.no_of_years, request.annuity_rates, request.annuity_purchased, request.yearly_interest_rates) # endpoint for payback period @@ -345,9 +355,9 @@ def payback_period( description="Calculate compound interest amount", ) def compound_interest( - request: compoundInterest, + request: compoundInterest ): - return compound_interest_task(request.principal_amount, request.interest_rate, request.time) + return compound_interest_task(request.principal_amount, request.interest_rate, request.years ,request.compounding_period) # Endpoints to calculate certificate of deposit (CD) @@ -902,15 +912,15 @@ def future_value_of_ordinary_due( # Endpoint to calculate future value of the annuity due -@app.get( +@app.post( "/future_value_of_annuity_due", tags=["future_value_of_annuity_due"], description="Calculating future value of annuity due", ) def future_value_of_annuity_due( - request: futureValueOfAnnuity, + request: futureValueOfAnnuity ): - return future_value_of_annuity_due_task(request.periodic_payment, request.number_of_periods, request.rate_per_period) + return future_value_of_annuity_due_task(request.periodic_payment, request.interest_rate, request.number_of_payments) # Endpoint to calculate present value of the annuity due @@ -1554,7 +1564,9 @@ def asdcr( description="Calculate VAT for both excluding and including amounts", ) async def calculate_vat(price: float, vat_rate: float): - return calculate_vat_task(price, vat_rate) + calculate_vat_price = await calculate_vat_task(price, vat_rate) + return calculate_vat_price + # Endpoint For calculating bond equivalent yield @@ -1723,7 +1735,7 @@ def calculate_post_tax_return_percentage(tax_rate_percentage: float, # Endpoint for function Treynor Ratio -@app.get( +@app.post( "/treynor_ratio", tags=["treynor_ratio"], description="Calculate Treynor ratio", @@ -1902,3 +1914,101 @@ def defensive_interval_ratio(request: DefensiveIntervalRatio): return defensive_interval_ratio_task(request.cash, request.marketable_securities, request.net_receivables, request.annual_operating_expenses , request.non_cash_charges) +# Endpoint to calculate Rate of return + +@app.post( + "/rate_of_return", + tags=["rate_of_return"], + description="Calculate Rate of return", +) +def rate_of_return(request: RateofReturn): + return calculate_rate_of_return(request.initial_investment, + request.final_value, + request.cash_flows, + request.time_period, + request.holding_period) +# Endpoint to calculate Financial assest Ratio + +@app.post( + "/financial_assest_ratio", + tags=["financial_assest_ratio"], + description="Calculate financial assest Ratio", +) +def financial_assest_ratio(request: financialAssestRatio): + return financial_assest_ratio(request.current_assets, + request.current_liabilities, + request.total_debt, + request.total_equity, + request.net_income, + request.total_revenue) + + +# Endpoint to calculate Cash Conversion Cycle + +@app.post( + "/cash_conversion_cycle", + tags=["cash_conversion_cycle"], + description="Calculate Cash Conversion Cycle", +) +def cash_conversion_cycle(request: CashConversionCycle): + return cash_conversion_cycle_task(request.beginning_inventory , request.ending_inventory , + 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( + "/price_elasticity", + tags=["price_elasticity"], + description="Calculate Cash Conversion Cycle", +) +def price_elasticity(request: PriceElasticity): + return calculate_price_elasticity(request.initial_price , + request.final_price , + request.initial_quantity, + request.final_quantity ) + + +# Endpoint to calculate Average Payment Period +@app.post( + "/average_payment_period", + tags=["average_payment_period"], + description="Calculate Average Payment Period", +) +def average_payment_period(request: AveragePaymentPeriod): + return average_payment_period_task(request.beginning_accounts_payable , + request.ending_accounts_payable , request.total_credit_purchases) + +# Endpoint to calculate Quick Ratio +@app.post( + "/quick_ratio", + tags=["quick_ratio"], + description="Calculate Quick Ratio", +) +def quick_ratio(cash: float , accounts_receivable: float , + marketable_security: float , current_liabilities: float): + return quick_ratio_task(cash , accounts_receivable , + marketable_security , current_liabilities) + +# Endpoint to get Cash Ratio +@app.post( + "/cash_ratio", + tags=["/cash_ratio"], + description="Calculate Cash Ratio", +) +def cash_ratio(cash: float , marketable_securities: float , current_liabilities: float): + return cash_ratio_task(cash , marketable_securities , current_liabilities) \ No newline at end of file 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/tasks/PriceElasticity.py b/tasks/PriceElasticity.py new file mode 100644 index 00000000..7ada0b43 --- /dev/null +++ b/tasks/PriceElasticity.py @@ -0,0 +1,15 @@ +from helpers import functions +from fastapi import HTTPException, status + +def calculate_price_elasticity(initial_price: float, final_price: float, initial_quantity: float, final_quantity: float): + try: + percentage_change_price = (final_price - initial_price) / ((final_price + initial_price) / 2) + percentage_change_quantity = (final_quantity - initial_quantity) / ((final_quantity + initial_quantity) / 2) + price_elasticity = percentage_change_quantity / percentage_change_price + + return { + "Tag": "Price Elasticity for demand Calculator", + "Price Elasticity": price_elasticity, + } + except: + return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR) \ No newline at end of file diff --git a/tasks/RateofReturn.py b/tasks/RateofReturn.py new file mode 100644 index 00000000..c3c04429 --- /dev/null +++ b/tasks/RateofReturn.py @@ -0,0 +1,25 @@ +from helpers import functions +from fastapi import HTTPException, status + +def calculate_rate_of_return(initial_investment: float, final_value: float, cash_flows: float, +time_period: float, holding_period: float): + try: + net_cash_flows = sum(cash_flows) + final_value += net_cash_flows + + if holding_period > 0: + rate_of_return = ((final_value - initial_investment) / (initial_investment + net_cash_flows)) * 100 + holding_period_return = ((final_value - initial_investment) / initial_investment) * 100 + else: + rate_of_return = ((final_value - initial_investment) / initial_investment) * 100 + holding_period_return = rate_of_return + + annualized_return = rate_of_return / time_period + return { + "Tag": "Rate of return", + "rate_of_return": rate_of_return, + "annualized_return": annualized_return, + "holding_period_return": holding_period_return + } + except: + return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR) \ No newline at end of file diff --git a/tasks/average_payment_period.py b/tasks/average_payment_period.py new file mode 100644 index 00000000..799adc26 --- /dev/null +++ b/tasks/average_payment_period.py @@ -0,0 +1,20 @@ +from helpers import functions +from fastapi import HTTPException, status + + +def average_payment_period_task(beginning_accounts_payable: float, ending_accounts_payable: float, +total_credit_purchases: float): + try: + average_accounts_payable = (beginning_accounts_payable + ending_accounts_payable) / 2 + app = functions.average_payment_period(beginning_accounts_payable, ending_accounts_payable, total_credit_purchases) + return { + "Tag": "Average Payment Period", + "Beginning Accounts Payable": beginning_accounts_payable, + "Ending Accounts Payable": ending_accounts_payable, + "Total Credit Purchases": total_credit_purchases, + "Average Accounts Payable": average_accounts_payable, + "Average Payment Period": f"{app} days", + } + except: + return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR) + diff --git a/tasks/cash_conversion_cycle.py b/tasks/cash_conversion_cycle.py new file mode 100644 index 00000000..557f4dfb --- /dev/null +++ b/tasks/cash_conversion_cycle.py @@ -0,0 +1,33 @@ +from helpers import functions +from fastapi import HTTPException, status + +def cash_conversion_cycle_task(beginning_inventory: float, ending_inventory: float, beginning_receivables: float, +ending_receivables: float, beginning_payable: float, ending_payable: float, cost_of_goods_sold: float, +net_credit_sales: float): + try: + average_inventory = beginning_inventory - ending_inventory / 2 + average_receivables = beginning_receivables - ending_receivables / 2 + average_payable = beginning_payable - ending_payable / 2 + days_of_inventory_outstanding = (average_inventory / cost_of_goods_sold) * 365 + days_of_sales_outstanding = (average_receivables / net_credit_sales) * 365 + days_of_payables_outstanding = (average_payable / cost_of_goods_sold / 365) + ccc = functions.cash_conversion_cycle(beginning_inventory, ending_inventory, beginning_receivables, + ending_receivables, beginning_payable, ending_payable, cost_of_goods_sold, net_credit_sales) + return { + "Tag": "Cash Conversion Cycle", + "Beginning Inventory": beginning_inventory, + "Ending Inventory": ending_inventory, + "Average Inventory": average_inventory, + "Beginning Receivables": beginning_receivables, + "Ending Receivables": ending_receivables, + "Average Receivables": average_receivables, + "Beginning Payable": beginning_payable, + "Ending Payable": ending_payable, + "Average Payable": average_payable, + "Days of inventory_outstanding": days_of_inventory_outstanding, + "Days of Sales Outstanding": days_of_sales_outstanding, + "Days of Payables Outstanding": days_of_payables_outstanding, + "Cash Conversion Cycle": f"{ccc} days", + } + except: + return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR) diff --git a/tasks/cash_ratio.py b/tasks/cash_ratio.py new file mode 100644 index 00000000..9eb494d9 --- /dev/null +++ b/tasks/cash_ratio.py @@ -0,0 +1,17 @@ +from helpers import functions +from fastapi import HTTPException, status + +def cash_ratio(cash: float, marketable_securities: float, current_liabilities: float): + try: + ratio=functions.cash_ratio(cash, marketable_securities, current_liabilities) + return { + "Tag": "cash ratio ~higher than 1 means better debt paying capacity", + "Total cash as asset": cash, + "marketable securities": marketable_securities, + "Total current liabilities": current_liabilities, + "cash ratio": "f{ratio}%" + } + except: + return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR) + + \ No newline at end of file diff --git a/tasks/financialAssestRatio.py b/tasks/financialAssestRatio.py new file mode 100644 index 00000000..8a067ffd --- /dev/null +++ b/tasks/financialAssestRatio.py @@ -0,0 +1,27 @@ +from helpers import functions +from fastapi import HTTPException, status + +def financial_assest_ratio(current_assets: float, current_liabilities: float, total_debt: float, +total_equity: float, net_income: float, total_assets:float, total_revenue: float, gross_profit: float, stock_price: float, earnings_per_share:float): + try: + current_ratio = current_assets / current_liabilities + debt_to_equity_ratio = total_debt / total_equity + return_on_assets = net_income / total_assets + return_on_equity = net_income / total_equity + asset_turnover_ratio = total_revenue / total_assets + gross_profit_margin = gross_profit / total_revenue + net_profit_margin = net_income / total_revenue + price_to_earnings_ratio = stock_price / earnings_per_share + return { + "Tag": "financial assest ratio", + "current_ratio": current_ratio, + "debt_to_equity_ratio": debt_to_equity_ratio, + "return_on_assets": return_on_assets, + "return_on_equity": return_on_equity, + "asset_turnover_ratio": asset_turnover_ratio, + "gross_profit_margin": gross_profit_margin, + "net_profit_margin": net_profit_margin, + "price_to_earnings_ratio": price_to_earnings_ratio, + } + except: + return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR) \ No newline at end of file diff --git a/tasks/lumpsum.py b/tasks/lumpsum.py index dae1e6b5..48c34d03 100644 --- a/tasks/lumpsum.py +++ b/tasks/lumpsum.py @@ -1,7 +1,6 @@ from helpers import functions from fastapi import HTTPException, status - -async def calculate_lumpsum_task(principal: float, interest_rate: float, years: int): +def calculate_lumpsum_task(principal: float, interest_rate: float, years: int): try: total_amount = principal * ( diff --git a/tasks/quick_ratio.py b/tasks/quick_ratio.py new file mode 100644 index 00000000..e1e64808 --- /dev/null +++ b/tasks/quick_ratio.py @@ -0,0 +1,16 @@ +from helpers import functions +from fastapi import HTTPException, status + +def quick_ratio(cash: float, accounts_receivable: float, marketable_security: float, current_liabilities: float): + try: + QR=functions.quick_ratio(cash, accounts_receivable, marketable_security, current_liabilities) + return{ + "Tag": "quick_ratio", + "Total cash as asset": cash, + "Total recievable cash": accounts_receivable, + "Total marketable security": marketable_security, + "Total current liabilities": current_liabilities, + "quick ratio":f"{QR}%" + } + except: + return HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR) diff --git a/validators/request_validators.py b/validators/request_validators.py index 076ddd24..0ffcc969 100644 --- a/validators/request_validators.py +++ b/validators/request_validators.py @@ -602,4 +602,61 @@ class DefensiveIntervalRatio(BaseModel): marketable_securities: float net_receivables: float annual_operating_expenses: float - non_cash_charges: float \ No newline at end of file + non_cash_charges: float + +class RateofReturn(BaseModel): + initial_investment: float + final_value: float + cash_flows: float + time_period: float + holding_period: float + +class financialAssestRatio(BaseModel): + current_assets: float + current_liabilities: float + total_debt: float + total_equity: float + net_income: float + total_revenue: float + +class CashConversionCycle(BaseModel): + beginning_inventory: float + ending_inventory: float + beginning_receivables: float + ending_receivables: float + beginning_payable: float + 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 + +class AveragePaymentPeriod(BaseModel): + beginning_accounts_payable: float + ending_accounts_payable: float + total_credit_purchases: float + +class QuickRatio(BaseModel): + cash: float + accounts_receivable: float + marketable_security: float + current_liabilities: float + +class CashRatio(BaseModel): + cash: float + marketable_securities: float + current_liabilities: float + \ No newline at end of file From 1397dfc7a7cd492926acb5cc6dd62892622d3b9a Mon Sep 17 00:00:00 2001 From: AshirMehmood Date: Sun, 23 Jul 2023 17:42:23 +0500 Subject: [PATCH 6/6] updated docs --- DOCUMENTATION.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index 4429a0ec..476568c1 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -66,3 +66,13 @@ The initial price of the product or service. | | | | - `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. | |-----------------------------|----------------------------------------|---------------------------------------------------------------------| +|---------------------------|----------------------------------------|---------------------------------------------------------| +| GET /quick-ratio | Calculate quick ratio | - `cash` (float): Total cash as asset. | +| | | - `marketable_security` (float): Expected within an year amount. | +| | | - `current_liabilities` (float): current liabilities | +| | | - `accounts_receivable` (float): expected income | +|---------------------------|----------------------------------------|---------------------------------------------------------| +| GET /cash-ratio | Calculate cash ratio | - `cash` (float): Total cash as asset. | +| | | - `marketable_security` (float): Expected within an year amount. | +| | | - `current_liabilities` (float): current liabilities | +