开始使用免费开始使用

累计还款与房屋净值

您每月按时还房贷,但很难看清这些年里您实际拥有哪些房屋产权,以及累计支付了多少利息。

使用 np.cumsum() 随时间累计求和所有利息支付,同时也累计所有本金支付,看看您的持有比例如何随时间变化。

回顾:np.cumsum() 会进行累计求和,返回一系列逐步累加的结果,而不是单个数值。

上一练习中的 principal_paidinterest_paidhome_valuedown_payment_percent 已可用。

本练习是课程的一部分

Python 金融概念入门

查看课程

练习说明

  • 使用 np.cumsum() 对已支付本金进行累计,计算随时间变化的 cumulative_home_equity
  • 用相同方法计算 cumulative_interest_paid
  • 计算随时间变化的房屋净值占比(别忘了加上首付比例!)。

交互式实操练习

通过完成这段示例代码来试试这个练习。

import numpy as np

# Calculate the cumulative home equity (principal) over time
cumulative_home_equity = ____

# Calculate the cumulative interest paid over time
cumulative_interest_paid = ____

# Calculate your percentage home equity over time
cumulative_percent_owned = ____ + (____/____)
print(cumulative_percent_owned)

# Plot the cumulative interest paid vs equity accumulated
plt.plot(cumulative_interest_paid, color='red')
plt.plot(cumulative_home_equity, color='blue')
plt.legend(handles=[interest_plot, principal_plot], loc=2)
plt.show()
编辑并运行代码