25 lines
599 B
Python
25 lines
599 B
Python
|
from fastapi import APIRouter
|
||
|
from pydantic import BaseModel
|
||
|
|
||
|
INDEX = "拨备前利润/平均风险加权资产"
|
||
|
|
||
|
router = APIRouter()
|
||
|
|
||
|
|
||
|
class Params(BaseModel):
|
||
|
利润总额: float
|
||
|
减值准备金: float
|
||
|
平均风险加权资产: float
|
||
|
|
||
|
|
||
|
@router.post("/{}".format(INDEX))
|
||
|
def func(p: Params):
|
||
|
try:
|
||
|
result = (p.利润总额 + p.减值准备金) / p.平均风险加权资产
|
||
|
return round(result, 6)
|
||
|
|
||
|
except ZeroDivisionError:
|
||
|
return "+inf" # 此处本应为算式无意义,特殊处理为正无穷大
|
||
|
except Exception:
|
||
|
return "计算错误"
|