creditrating-wcq/IndexCalculation/基本信用评级指标/盈利能力/EBIT利润率_三年加权计算.py

36 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from fastapi import APIRouter
from pydantic import BaseModel
INDEX = "EBIT利润率_三年加权计算%"
router = APIRouter()
class Params(BaseModel):
当期利润总额: float
当期计入财务费用的利息支出: float
当期营业收入: float
上期利润总额: float
上期计入财务费用的利息支出: float
上期营业收入: float
上二期利润总额: float
上二期计入财务费用的利息支出: float
上二期营业收入: float
@router.post("/{}".format(INDEX))
def func(p: Params):
try:
ebit1 = (p.当期利润总额 + p.当期计入财务费用的利息支出) / p.当期营业收入 * 100
ebit2 = (p.上期利润总额 + p.上期计入财务费用的利息支出) / p.上期营业收入 * 100
ebit3 = (p.上二期利润总额 + p.上二期计入财务费用的利息支出) / p.上二期营业收入 * 100
result = ebit1 * 0.5 + ebit2 * 0.3 + ebit3 * 0.2
return round(result, 2)
except ZeroDivisionError:
return "+inf" # 此处本应为算式无意义,特殊处理为正无穷大
except Exception:
return "计算错误"