creditrating-wcq/IndexCalculation/基本信用评级指标/盈利能力/总资产报酬率_三年加权计算.py

41 lines
1.2 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 = "总资产报酬率_三年加权计算%"
router = APIRouter()
class Params(BaseModel):
当期净利润: float
当期所得税: float
当期利息: float
上期资产总计: float
当期资产总计: float
上期净利润: float
上期所得税: float
上期利息: float
上二期资产总计: float
上二期净利润: float
上二期所得税: float
上二期利息: float
上三期资产总计: float
# 计算接口
@router.post("/{}".format(INDEX))
def func(p: Params):
try:
ratio1 = (p.当期净利润 + p.当期所得税 + p.当期利息) / ((p.上期资产总计 + p.当期资产总计) / 2) * 100
ratio2 = (p.上期净利润 + p.上期所得税 + p.上期利息) / ((p.上二期资产总计 + p.上期资产总计) / 2) * 100
ratio3 = (p.上二期净利润 + p.上二期所得税 + p.上二期利息) / ((p.上三期资产总计 + p.上二期资产总计) / 2) * 100
result = ratio1 * 0.5 + ratio2 * 0.3 + ratio3 * 0.3
return round(result, 2)
except ZeroDivisionError:
return "算式无意义"
except Exception:
return "计算错误"