以收入的一定比例投資(I)
很可惜,你真的負擔不起每月存下 $3,000,想在短短 15 年內累積到 $1,000,000。
不過,你可以慢慢開始,每個月先投資你稅後收入的一小部分。隨著收入成長,投資金額也會跟著增加。
在這個練習中,你會先打好基礎,來模擬這個隨時間推進的投資過程。
salary_forecast 與 expenses_forecast 變數可沿用自前一個練習。
cash_flow_forecast 也已提供,它是由你預測的薪資減去預測的支出所得到的陣列。monthly_investment_percentage 變數已設定為 0.30。
本練習屬於課程
Python 金融概念入門
練習說明
- 根據投資比例,計算
investment_deposit_forecast:依每期預測的現金流所得到的每月投資金額。 - 計算每期的每月儲蓄存款(也就是未拿去投資、剩下的金額)。
- 計算隨時間推移的累積儲蓄。
- 執行提供的程式碼,繪製預測的每月儲蓄與投資的比較圖。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
import numpy as np
# Calculate your monthly deposit into your investment account
investment_deposit_forecast = ____
# The rest goes into your savings account
savings_forecast_new = ____ * ____
# Calculate your cumulative savings over time
cumulative_savings_new = ____
# Plot your forecasted monthly savings vs investments
plt.plot(investment_deposit_forecast, color='red')
plt.plot(savings_forecast_new, color='blue')
plt.legend(handles=[investments_plot, savings_plot], loc=2)
plt.show()