房價上漲
每年房價都在穩定上漲,而這對你來說是一筆相當大的投資。
請在每月固定成長率 0.25% 的條件下,計算一段時間內你的自有資產(房屋淨值)。這個成長率已重複建立為一個長度等於房貸繳款期數的陣列,並存放在 growth_array。
上個練習中的 home_value 與 cumulative_percent_owned 變數都可供使用。
本練習屬於課程
Python 金融概念入門
練習說明
- 使用
np.cumprod()和growth_array計算隨時間累積的成長率。 - 使用累積成長陣列與初始的
home_value,預測各期的房屋價值。 - 根據
home_value_forecast與cumulative_percent_owned,預測各期自有資產的金額。 - 執行提供的程式碼,查看房屋價值與自有資產隨時間變化的圖表。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
import numpy as np
# Calculate the cumulative growth over time
cumulative_growth_forecast = ____
# Forecast the home value over time
home_value_forecast = ____
# Forecast the home equity value owned over time
cumulative_home_value_owned = ____
# Plot the home value vs equity accumulated
plt.plot(home_value_forecast, color='red')
plt.plot(cumulative_home_value_owned, color='blue')
plt.legend(handles=[homevalue_plot, homeequity_plot], loc=2)
plt.show()