银行会不会失败?
将上一个练习得到的违约次数(保存在您的命名空间中的 n_defaults)绘制为一个 CDF。您在第一章编写的 ecdf() 函数可用。
如果利率水平使得一旦有 10 笔或更多贷款发生违约,银行就会亏损,那么银行亏损的概率是多少?
本练习是课程的一部分
Python 中的统计思维(第 1 部分)
练习说明
- 计算
n_defaults的 ECDF 的x和y值。 - 绘制 ECDF,并确保标注坐标轴。在调用
plt.plot()时,除传入x和y外,请包含marker = '.'和linestyle = 'none'。 - 显示图形。
- 计算
n_defaults数组中大于等于 10 的条目总数。为此,先计算一个布尔数组,指示n_defaults的某个条目是否>= 10,然后使用np.sum()对该布尔数组求和。例如,np.sum(n_defaults <= 5)会计算违约次数为 5 次或更少的数量。 - 银行亏损的概率等于
n_defaults中大于等于 10 的比例。按下提交打印该结果!
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Compute ECDF: x, y
# Plot the ECDF with labeled axes
# Show the plot
# Compute the number of 100-loan simulations with 10 or more defaults: n_lose_money
# Compute and print probability of losing money
print('Probability of losing money =', n_lose_money / len(n_defaults))