누적 상환액과 주택 순자산
매달 성실히 모기지를 상환하고 있지만, 실제로 집의 얼마를 소유하고 있는지, 또 그동안 총 이자 비용이 얼마인지 파악하기가 쉽지 않아요.
np.cumsum()을 사용해 시간에 따라 모든 이자 지급액의 누적합과 원금 상환액의 누적합을 구해, 시간이 지나면서 소유 지분이 어떻게 변하는지 확인해 보세요.
np.cumsum()은 시계열에 대한 누적 합계를 계산한다는 점을 기억하세요. 단일 숫자가 아니라, 반복적으로 더해진 합계의 시리즈를 반환합니다.
이전 연습 문제에서 사용한 principal_paid, interest_paid, home_value, down_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()