indexcalculation/基本信用评级指标/流动性/高流动性资产占比.py

28 lines
769 B
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
@router.post("/{}".format(INDEX))
def func(p: Params):
try:
d = p.货币资金 + p.以公允价值且其变动计入其他综合收益的金融资产 + p.买入返售金融资产 + p.一年内到期的定期存款
result = d / p.总资产 * 100
return round(result, 2)
except ZeroDivisionError:
return "算式无意义"
except Exception:
return "计算错误"