房價下跌與資不抵債的房貸
不幸的是,你也很清楚房價不一定總是上漲。
所謂房貸「資不抵債(underwater)」是指你尚需償還的房貸金額其實高於房屋本身的市值。
在這個練習中,你要計算最糟情境:房價以每月 0.45% 的速度持續下跌。為了加快步驟,房價的「累積跌幅」已經替你預先預測並儲存在變數 cumulative_decline_forecast 中。它是一組相對於今日價格的乘法折扣係數,因此不需要在這個報酬率陣列上再加 1。
房貸的未償本金可由 principal_remaining 取得。
本練習屬於課程
Python 金融概念入門
練習說明
- 使用
cumulative_decline_forecast陣列與起始的home_value做簡單運算,預測隨時間變化的房價。 - 計算每一期房貸是否為
underwater,並將條件為真或假的結果儲存為布林值陣列。 - 執行現有的程式碼,繪製「房價」與「尚未償還本金」隨時間變化的圖形。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
import numpy as np
import pandas as pd
# Cumulative drop in home value over time as a ratio
cumulative_decline_forecast = np.cumprod(1+decline_array)
# Forecast the home value over time
home_value_forecast = ____
# Find all periods where your mortgage is underwater
underwater = ____
pd.value_counts(underwater)
# Plot the home value vs principal remaining
plt.plot(home_value_forecast, color='red')
plt.plot(principal_remaining, color='blue')
plt.legend(handles=[homevalue_plot, principal_plot], loc=2)
plt.show()