This repository has been archived by the owner on Jun 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ernest DONG
committed
Apr 7, 2022
1 parent
4087208
commit 2cd0c90
Showing
10 changed files
with
126 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,5 @@ | |
*.el | ||
/inbox/inbox.tex | ||
/ignore/ | ||
thesis.docx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ view: | |
open "thesis.pdf" | ||
clean: | ||
latexmk -c | ||
docx: | ||
pandoc -s thesis.tex --bibliography=thesis.bib -o thesis.docx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters