Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Commit

Permalink
第二次提交
Browse files Browse the repository at this point in the history
  • Loading branch information
Ernest DONG committed Apr 7, 2022
1 parent 4087208 commit 2cd0c90
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 43 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@
*.el
*.pdf
/inbox/inbox.tex
/ignore/
thesis.docx
4 changes: 2 additions & 2 deletions chap/abs.tex
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
%!TEX root = ../thesis.tex
\begin{cabstract}
偶发的债券违约是经济体排除不稳定因素、自发降低系统性风险的正常现象,维持“刚兑”的债券市场反而是不健康的。但违约结果造成的影响是多方面的,处理得当可以使短期遭受困难的企业焕发新生,处理不当则可能影响金融市场稳定,进而对实体经济造成巨大影响。
本文计划从债券违约影响因素出发,使用计量手段描述我国债券市场上违约发行人的共性特征,抽离出重要的导致企业违约的关键因素,并通过机器学习的方式佐证和拓展计量模型,以期对债券市场违约有一个比较好的刻画。
本文从债券违约影响因素出发,使用计量手段描述我国债券市场上违约发行人的共性特征,抽离出重要的导致企业违约的关键因素,并通过机器学习的方式佐证和拓展计量模型,以期对债券市场违约有一个比较好的刻画。
\end{cabstract}
\begin{eabstract}
Occasional bond defaults are a normal phenomenon for an economy to eliminate unstable factors and spontaneously reduce systemic risks, and it is unusual to maintain a bail out bond market. However, the impact of the default results is multi-faceted. A proper handling can rejuvenate companies that have suffered short-term difficulties. But an improper handling may affect the stability of the financial market and have a huge impact on the economy.
This paper plans to start from the influencing factors of bond defaults. We use measurement methods to describe the common characteristics of default issuers in China bond market, extract important key factors that lead to corporate defaults. And finally we use machine learning to corroborate and expand our model in order to have a better characterization of bond market defaults.
This paper start from the influencing factors of bond defaults. We use measurement methods to describe the common characteristics of default issuers in China bond market, extract important key factors that lead to corporate defaults. And finally we use machine learning to corroborate and expand our model in order to have a better characterization of bond market defaults.
\end{eabstract}
65 changes: 27 additions & 38 deletions chap/chap1.tex

Large diffs are not rendered by default.

15 changes: 13 additions & 2 deletions chap/chap2.tex
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
%!TEX root = ../thesis.tex

\chapter{理论模型}
综合 \ref{sec:zs} 中各学者的观点,以及现实中的违约案例,本文将从宏观、中观以及微观角度,拆解可能影响违约的因素。
\section{微观层次}
迄今为止我国尚未发生类似金融危机时的大片企业集中倒下,违约更多是非系统性风险造成的,绝大多数违约都是公司层面发生了一些问题导致的。因此本文的分析重点将集中在微观层次
本文将微观层面影响企业违约的因素分为以下四类,主要包含企业层面的指标:
Expand Down Expand Up @@ -33,8 +32,20 @@ \subsection{财务层面}
对于会计指标,\Textcite{blochlinger2018ratings}指出以美国债券市场发行人作为研究对象, Altman's Z 指标是一个比较综合的、很好的预测违约会计指标。因此本文尝试引入 \(Z\) 值作为综合的财务指标。

此外违约本质上是企业持有的现金及其等价物无法偿还到期债务,存在一定的可能公司真的遇到了短期流动性危机而未来长期表现将会王者归来,如盐湖股份短期流动性告急,通过银行等机构的债转股使其资产不至于低价贱卖流失,重整两年后成为锂矿龙头。因此本文也将考虑现金短债比这一因素。

\subsection{评级指标}
\ref{sec:zs} 中各学者对评级指标的批判非常有借鉴意义。但即便以预测的角度看评级并不完全准确,但以后验的角度看,评级也反映了一定的公开与非公开信息,因此本文也将主体评级纳入考虑。
信用评级是企业违约风险最直观的表述之一。难以否认的是,我国信用评级市场存在很大的不完善,信用评级比较扭曲,如图\ref{fig:rating}所示,新发行债券有一半为最高评级 AAA 。
\begin{figure}[h]
\centering
\includegraphics[width=0.9\linewidth]{./data/rating_from_2014.png}
\caption{\label{fig:rating}信用债发行评级统计}
\end{figure}


正如\ref{sec:zs} 中各学者对评级指标的批判,这很大程度上是由于发行人付费的模式引起的。但即便以预测的角度看评级并不完全准确,但以后验的角度看,评级也反映了一定的公开与非公开信息,因此本文也将主体评级纳入考虑。

尽管有研究指出,相比于评级,债券交易的价格可能更有效\cite{badoer2019relevance}。我国也是如此,债券价格大幅偏离估值往往是违约的先兆,一般认为面值100的债券价格下跌至60元左右相当于即将违约,已经违约的债券往往价格只有20元左右。但单纯以价格异动预测违约存在不少假阳性情况,特别是在城投债中,弱省市的城投债成交收益率有时能达到20\%乃至更高,但至今仍未有城投债违约出现。

\section{中观层次}
中观层次为非企业级、非全国级的因素。如行业、流动性和地理因素。

Expand Down
2 changes: 2 additions & 0 deletions chap/chap3.tex
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ \section{机器学习验证与比较}

\ref{fig:decision_tree}决策树算法的关键节点如波动率、主营收入、企业性质、\(Z\) 值等在 Logit 模型中显著,在 Logit 模型中不显著的大股东持股比例分枝后判断的概率值仅勉强超过阈值,与 Logit 模型互相印证。

此外, \ref{fig:decision_tree}也揭示了违约因素间的相互作用。例如,决策树右侧主营收入到波动率的分叉显示了宏观经济和微观因素间的相互作用:低主营业务收入会对违约造成影响,但是当宏观经济波动率较低时,这种微观因素的作用会降低。稳定的宏观经济环境下,企业的股权债券质押融资不容易爆仓,生产经营更加稳定,主营收入减少的影响可以暂时性地降低。典型的例子有乐视网、保千里,创始人通过资本运作和股权质押在资本市场上如鱼得水,可当股灾来临时,质押爆仓资金流断裂,最终走向违约。

\begin{table}
\caption{\label{tab:acc}不同模型的比较}
\centering
Expand Down
Binary file added doc/reference.docx
Binary file not shown.
2 changes: 2 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ view:
open "thesis.pdf"
clean:
latexmk -c
docx:
pandoc -s thesis.tex --bibliography=thesis.bib -o thesis.docx
77 changes: 77 additions & 0 deletions src/ml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#%%
import graphviz
import matplotlib.pyplot as plt
import pandas as pd
import seaborn as sns
from sklearn import tree
from sklearn.ensemble import RandomForestClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import (
ConfusionMatrixDisplay,
PrecisionRecallDisplay,
accuracy_score,
confusion_matrix,
f1_score,
plot_confusion_matrix,
plot_roc_curve,
precision_score,
recall_score,
roc_auc_score,
roc_curve,
)
from sklearn.model_selection import train_test_split
from sqlalchemy import create_engine
sns.set(style="white", context="paper")
#%%

engine = create_engine("mysql+pymysql://root:Lyj822919@localhost:3306/thesis")
res = pd.read_sql("logit_model", engine, index_col="index")
dt = tree.DecisionTreeClassifier(
criterion="entropy",
random_state=30,
max_depth=4,
# min_samples_leaf=10,
min_samples_split=10,
)
rf = RandomForestClassifier()
lr = LogisticRegression()
Xtrain, Xtest, Ytrain, Ytest = train_test_split(
res.drop(columns=["default"]), res["default"], test_size=0.3
)
# Xtrain, Ytrain = res.drop(columns=["default"]), res["default"]
dt = dt.fit(Xtrain, Ytrain)
rf = rf.fit(Xtrain, Ytrain)
lr = lr.fit(Xtrain, Ytrain)
# score = clf.score(Xtest, Ytest)

dot_data = tree.export_graphviz(
dt,
feature_names=res.drop(columns=["default"]).columns,
class_names=["no default", "default"],
filled=True,
rounded=True,
)

graph = graphviz.Source(dot_data)
graph.format = "png"
graph.render("ml/decision_tree", view=False)
#%%
for model in [lr, dt, rf]:
predictions = model.predict(Xtest)
cm = confusion_matrix(Ytest, predictions, labels=dt.classes_)
disp = ConfusionMatrixDisplay(confusion_matrix=cm, display_labels=dt.classes_)
name = str(model.__class__.__name__) + "\t"
print(name + "Accuracy: {:.2f}".format(accuracy_score(Ytest, predictions)))
print(name + "Error rate: {:.2f}".format(1 - accuracy_score(Ytest, predictions)))
print(name + "Precision: {:.2f}".format(precision_score(Ytest, predictions)))
print(name + "Recall: {:.2f}".format(recall_score(Ytest, predictions)))
print(name + "f1_score: {:.2f}".format(f1_score(Ytest, predictions)))
disp.plot()
plt.savefig(f"ml/{str(model.__class__.__name__)}.png")

#%%
disp = plot_roc_curve(lr, Xtest, Ytest)
plot_roc_curve(dt, Xtest, Ytest, ax=disp.ax_)
plot_roc_curve(rf, Xtest, Ytest, ax=disp.ax_)
plt.savefig("ml/roc.png")
# %%
Binary file added thesis.docx
Binary file not shown.
2 changes: 1 addition & 1 deletion thesis.tex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
\documentclass[UTF8,oneside]{pkuthss}
\documentclass[UTF8,oneside,fontset=mac]{pkuthss}
\usepackage[backend = biber, style = gb7714-2015ay, url=false,gbtitlelink=true]{biblatex}
\usepackage{longtable}
\usepackage{multirow}
Expand Down

0 comments on commit 2cd0c90

Please sign in to comment.