目标和背景
目标:建立一个宏观经济周期和信用卡违约率的领先指标。
数据:美国 1990-2008 年月度宏观经济数据:共 228 个观测值,pce: 个人
消费支出、debt: 未偿还个人消费贷款、Charge-off Rate:违约率。
解决方案和程序
- 对 debt 和 log(pce) 做散点图:两者有很强的线性关系
- 建立一元线性回归模型,并得到残差。(经济学解释)
- 画违约率和残差的序列图以及对迟滞残差的散点图,如下。
- 可以进一步建立违约率对迟滞残差的一元线性模型,
或直接建立违约率对带迟滞的 debt 和 log(pce) 的二元线性模型。
import pandas as pd
path = ‘data/macro_econ_data.xls’
data = pd.read_excel(path)
debt = data[‘Revolving Credit’].values[:,np.newaxis]
pce = data[‘Nominal PCE’].values[:,np.newaxis]
rate = data[‘Charge-off Rate’].values[:,np.newaxis]
y = debt
x = np.log(pce)
plt.plot(x,y,‘o’)
n,p = x.shape
c = np.ones((n,1))
X = np.hstack((c,x))
beta = la.inv(X.T.dot(X)).dot(X.T).dot(y)
res = y - X.dot(beta)
res2 = (res - res.mean(axis=0)) / res.std(axis=0)
rate2 = (rate - rate.mean(axis=0)) / rate.std(axis=0)
plt.figure()
plt.plot(res2)
plt.plot(rate2)
plt.legend([‘residual’,‘charge-off rate’])
plt.savefig(r’fig\drate-res-ts’)
corr_list = [np.corrcoef(res2[:-k].T,rate2[k:].T)[0,1]
for k in np.arange(1,15)]
lag = np.array(corr_list).argmax()
plt.plot(res2[:-lag],rate2[lag:],‘o’)
plt.xlabel(‘lagged residual’)
plt.ylabel(‘charge-off rate’)
plt.savefig(r’fig\drate-res’)