計算你的淨值
既然你已經在考量職涯發展與通膨的情況下,預測了未來一段時間的薪資與儲蓄,你就建立了一個時間序列,可以像第 1 章那樣用來計算你的現金流。
在這個範例中,你只需要用預測的每月薪資減去預測的每月支出。每個月剩下的現金流都會直接存入你的儲蓄帳戶。
你想要推估一段時間內的累積儲蓄,以檢視在這些預測之下,你的預算規劃有多有效。
前面練習中的 salary_forecast 與 expenses_forecast 已可使用。
本練習屬於課程
Python 金融概念入門
練習說明
- 以預測的每月支出與每月薪資來推算你的每月儲蓄。
- 計算一段時間內的累積儲蓄。
- 印出在努力儲蓄 15 年後,你的儲蓄帳戶金額。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
import numpy as np
# Calculate your savings for each month
savings_forecast = ____
# Calculate your cumulative savings over time
cumulative_savings = ____
# Print the final cumulative savings after 15 years
final_net_worth = ____
print("Your final net worth: " + str(round(final_net_worth, 2)))
# Plot the forecasted savings
plt.plot(cumulative_savings, color='blue')
plt.show()