guarantee-admin-api-v0.2/Modules/Models/ScoreAndRankModel.py

231 lines
11 KiB
Python
Raw Permalink Normal View History

2022-06-02 16:57:45 +08:00
"""
打分评级模型
"""
2022-06-06 16:58:08 +08:00
from DBHelper.MongoHelperInstance import DB_GUA
from Utils.CommonUtil import sub_dict
2022-06-02 16:57:45 +08:00
from Utils.ObjUtil import SpecObject
2022-06-06 16:58:08 +08:00
from Utils.ScoreUtils import ScoreUtils
2022-06-02 16:57:45 +08:00
from Utils.ValidateUtil import ValidateAttr, Validate
2022-06-06 16:58:08 +08:00
refs = dict()
ref_items = DB_GUA.find_all_data(
"模型数据",
"ScoreRefs_v0.1",
{},
["name", "weight", "b1", "b2", "b3", "b4", "b5"]
)
for item in ref_items:
refs = {**refs, **{item['name']: sub_dict(item, ["weight", "b1", "b2", "b3", "b4", "b5"])}}
2022-06-02 16:57:45 +08:00
class CreditIndexScore(SpecObject):
compensation = ValidateAttr(field="compensation", type=[float, int], default=None)
compensation_rate = ValidateAttr(field="compensation_rate", type=[float, int], default=None)
compensation_reserve_ratio = ValidateAttr(field="compensation_reserve_ratio", type=[float, int], default=None)
cash_assets_ratio = ValidateAttr(field="cash_assets_ratio", type=[float, int], default=None)
risk_reserve_adequacy_ratio = ValidateAttr(field="risk_reserve_adequacy_ratio", type=[float, int], default=None)
current_ratio = ValidateAttr(field="current_ratio", type=[float, int], default=None)
growth_ability = ValidateAttr(field="growth_ability", type=[float, int], default=None)
guaranteed_insured_balance_growth_rate = ValidateAttr(field="guaranteed_insured_balance_growth_rate", type=[float, int], default=None)
guaranteed_revenue_growth_rate = ValidateAttr(field="guaranteed_revenue_growth_rate", type=[float, int], default=None)
growth_rate_of_total_assets = ValidateAttr(field="growth_rate_of_total_assets", type=[float, int], default=None)
guaranteed_asset_quality = ValidateAttr(field="guaranteed_asset_quality", type=[float, int], default=None)
single_customer_concentration = ValidateAttr(field="single_customer_concentration", type=[float, int], default=None)
current_guarantee_compensation_rate = ValidateAttr(field="current_guarantee_compensation_rate", type=[float, int], default=None)
financing_guarantee_magnification = ValidateAttr(field="financing_guarantee_magnification", type=[float, int], default=None)
industry_concentration = ValidateAttr(field="industry_concentration", type=[float, int], default=None)
current_compensation_recovery_rate = ValidateAttr(field="current_compensation_recovery_rate", type=[float, int], default=None)
enterprise_size = ValidateAttr(field="enterprise_size", type=[float, int], default=None)
paid_capital = ValidateAttr(field="paid_capital", type=[float, int], default=None)
guarantee_business_income = ValidateAttr(field="guarantee_business_income", type=[float, int], default=None)
profitability = ValidateAttr(field="profitability", type=[float, int], default=None)
return_total_assets = ValidateAttr(field="return_total_assets", type=[float, int], default=None)
operating_margin = ValidateAttr(field="operating_margin", type=[float, int], default=None)
roe = ValidateAttr(field="roe", type=[float, int], default=None)
capital_structure = ValidateAttr(field="capital_structure", type=[float, int], default=None)
actual_asset_liability_ratio = ValidateAttr(field="actual_asset_liability_ratio", type=[float, int], default=None)
capital_adequacy_ratio = ValidateAttr(field="capital_adequacy_ratio", type=[float, int], default=None)
2022-06-06 16:58:08 +08:00
def score_compensation(self):
"""代偿能力"""
self.compensation = sum([
self.compensation_rate,
self.compensation_reserve_ratio,
self.cash_assets_ratio,
self.risk_reserve_adequacy_ratio
])
def score_compensation_rate(self, value):
"""代偿保障率(%)"""
2022-06-13 14:59:04 +08:00
self.compensation_rate = ScoreUtils.ladder_score_positive(value, refs['代偿保障率(%)'])
2022-06-06 16:58:08 +08:00
def score_compensation_reserve_ratio(self, value):
"""代偿准备金比率(%)"""
2022-06-13 14:59:04 +08:00
self.compensation_reserve_ratio = ScoreUtils.ladder_score_negative(value, refs['代偿准备金比率(%)'])
2022-06-06 16:58:08 +08:00
def score_cash_assets_ratio(self, value):
"""现金类资产比率(%)"""
2022-06-13 14:59:04 +08:00
self.cash_assets_ratio = ScoreUtils.ladder_score_positive(value, refs['现金类资产比率(%)'])
2022-06-06 16:58:08 +08:00
def score_risk_reserve_adequacy_ratio(self, value):
"""风险准备金充足率(%)"""
2022-06-13 14:59:04 +08:00
self.risk_reserve_adequacy_ratio = ScoreUtils.ladder_score_positive(value, refs['风险准备金充足率(%)'])
2022-06-06 16:58:08 +08:00
def score_current_ratio(self, value):
"""流动比率(%)"""
2022-06-13 14:59:04 +08:00
self.current_ratio = ScoreUtils.ladder_score_positive(value, refs['流动比率(%)'])
2022-06-06 16:58:08 +08:00
def score_growth_ability(self):
"""成长能力"""
self.growth_ability = sum([
self.guaranteed_insured_balance_growth_rate,
self.guaranteed_revenue_growth_rate,
self.growth_rate_of_total_assets
])
def score_guaranteed_insured_balance_growth_rate(self, value):
"""担保在保余额增长率(%)"""
2022-06-13 14:59:04 +08:00
self.guaranteed_insured_balance_growth_rate = ScoreUtils.ladder_score_positive(value, refs['担保在保余额增长率(%)'])
2022-06-06 16:58:08 +08:00
def score_guaranteed_revenue_growth_rate(self, value):
"""担保收入增长率(%)"""
2022-06-13 14:59:04 +08:00
self.guaranteed_revenue_growth_rate = ScoreUtils.ladder_score_positive(value, refs['担保收入增长率(%)'])
2022-06-06 16:58:08 +08:00
def score_growth_rate_of_total_assets(self, value):
"""资产总额增长率(%)"""
2022-06-13 14:59:04 +08:00
self.growth_rate_of_total_assets = ScoreUtils.ladder_score_positive(value, refs['资产总额增长率(%)'])
2022-06-06 16:58:08 +08:00
def score_guaranteed_asset_quality(self):
"""担保资产质量"""
self.guaranteed_asset_quality = sum([
self.single_customer_concentration,
self.current_guarantee_compensation_rate,
self.financing_guarantee_magnification,
self.industry_concentration,
self.current_compensation_recovery_rate
])
def score_single_customer_concentration(self, value):
"""单一客户集中度(%)"""
2022-06-13 14:59:04 +08:00
self.single_customer_concentration = ScoreUtils.ladder_score_negative(value, refs['单一客户集中度(%)'])
2022-06-06 16:58:08 +08:00
def score_current_guarantee_compensation_rate(self, value):
"""当期担保代偿率(%)"""
2022-06-13 14:59:04 +08:00
self.current_guarantee_compensation_rate = ScoreUtils.ladder_score_negative(value, refs['当期担保代偿率(%)'])
2022-06-06 16:58:08 +08:00
def score_financing_guarantee_magnification(self, value):
"""融资担保放大倍数(倍)"""
2022-06-13 14:59:04 +08:00
self.financing_guarantee_magnification = ScoreUtils.ladder_score_centered(value, refs['融资担保放大倍数(倍)'])
2022-06-06 16:58:08 +08:00
def score_industry_concentration(self, value):
"""行业集中度(%)"""
2022-06-13 14:59:04 +08:00
self.industry_concentration = ScoreUtils.ladder_score_negative(value, refs['行业集中度(%)'])
2022-06-06 16:58:08 +08:00
def score_current_compensation_recovery_rate(self, value):
"""当期代偿回收率(%)"""
2022-06-13 14:59:04 +08:00
self.current_compensation_recovery_rate = ScoreUtils.ladder_score_positive(value, refs['当期代偿回收率(%)'])
2022-06-06 16:58:08 +08:00
def score_enterprise_size(self):
"""企业规模"""
self.enterprise_size = sum([
self.paid_capital,
self.guarantee_business_income
])
def score_paid_capital(self, value):
"""实收资本(亿元)"""
2022-06-13 14:59:04 +08:00
self.paid_capital = ScoreUtils.ladder_score_positive(value, refs['实收资本(亿元)'])
2022-06-06 16:58:08 +08:00
def score_guarantee_business_income(self, value):
"""担保业务收入(万元)"""
2022-06-13 14:59:04 +08:00
self.guarantee_business_income = ScoreUtils.ladder_score_positive(value, refs['担保业务收入(万元)'])
2022-06-06 16:58:08 +08:00
def score_profitability(self):
"""盈利能力"""
self.profitability = sum([
self.return_total_assets,
self.operating_margin,
self.roe
])
def score_return_total_assets(self, value):
"""总资产收益率(%)"""
2022-06-13 14:59:04 +08:00
self.return_total_assets = ScoreUtils.ladder_score_positive(value, refs['总资产收益率(%)'])
2022-06-06 16:58:08 +08:00
def score_operating_margin(self, value):
"""营业利润率(%)"""
2022-06-13 14:59:04 +08:00
self.operating_margin = ScoreUtils.ladder_score_positive(value, refs['营业利润率(%)'])
2022-06-06 16:58:08 +08:00
def score_roe(self, value):
"""净资产收益率(%)"""
2022-06-13 14:59:04 +08:00
self.roe = ScoreUtils.ladder_score_positive(value, refs['净资产收益率(%)'])
2022-06-06 16:58:08 +08:00
def score_capital_structure(self):
"""资本结构"""
self.capital_structure = sum([
self.actual_asset_liability_ratio,
self.capital_adequacy_ratio
])
def score_actual_asset_liability_ratio(self, value):
"""实际资产负债率(%)"""
2022-06-13 14:59:04 +08:00
self.actual_asset_liability_ratio = ScoreUtils.ladder_score_negative(value, refs['实际资产负债率(%)'])
2022-06-06 16:58:08 +08:00
def score_capital_adequacy_ratio(self, value):
"""资本充足率(%)"""
2022-06-13 14:59:04 +08:00
self.capital_adequacy_ratio = ScoreUtils.ladder_score_positive(value, refs['资本充足率(%)'])
2022-06-06 16:58:08 +08:00
2022-06-02 16:57:45 +08:00
fields_map = {
"compensation": "代偿能力",
"compensation_rate": "代偿保障率(%)",
"compensation_reserve_ratio": "代偿准备金比率(%)",
"cash_assets_ratio": "现金类资产比率(%)",
"risk_reserve_adequacy_ratio": "风险准备金充足率(%)",
"current_ratio": "流动比率(%)",
"growth_ability": "成长能力",
"guaranteed_insured_balance_growth_rate": "担保在保余额增长率(%)",
"guaranteed_revenue_growth_rate": "担保收入增长率(%)",
"growth_rate_of_total_assets": "资产总额增长率(%)",
"guaranteed_asset_quality": "担保资产质量",
"single_customer_concentration": "单一客户集中度(%)",
"current_guarantee_compensation_rate": "当期担保代偿率(%)",
"financing_guarantee_magnification": "融资担保放大倍数(倍)",
"industry_concentration": "行业集中度(%)",
"current_compensation_recovery_rate": "当期代偿回收率(%)",
"enterprise_size": "企业规模",
2022-06-06 16:58:08 +08:00
"paid_capital": "实收资本(亿元)",
2022-06-02 16:57:45 +08:00
"guarantee_business_income": "担保业务收入(万元)",
"profitability": "盈利能力",
"return_total_assets": "总资产收益率(%)",
"operating_margin": "营业利润率(%)",
"roe": "净资产收益率(%)",
"capital_structure": "资本结构",
"actual_asset_liability_ratio": "实际资产负债率(%)",
"capital_adequacy_ratio": "资本充足率(%)"
}
class ScoreAndRankModel(SpecObject):
rid = ValidateAttr(field="rid", type=str)
cid = ValidateAttr(field="cid", type=str)
report_date = ValidateAttr(field="report_date", func=Validate.date_format)
rank_level = ValidateAttr(field="rank_level", type=str)
rank_score = ValidateAttr(field="rank_score", type=float)
credit_index_score = ValidateAttr(field="credit_index_score", type=CreditIndexScore)
fields_map = {
2022-06-16 15:46:40 +08:00
"rid": "评级ID",
2022-06-02 16:57:45 +08:00
"cid": "企业ID",
"report_date": "报告期",
"rank_level": "信用级别",
"rank_score": "信用得分",
"credit_index_score": "信用指标得分"
}