Created
October 13, 2023 08:40
-
-
Save edimetia3d/ff4e6215ef4dd900e1b7a30565e972c0 to your computer and use it in GitHub Desktop.
Assets change of buying a apartment in china in tensor?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import numpy_financial as npf | |
def get_irr(loan, X, plan_month): | |
"""Finacial concept""" | |
v = [-loan] | |
for i in range(plan_month): | |
v.append(X) | |
return npf.irr(v) | |
def deng_e_ben_xi(base_loan, month_rate, plan_month, real_month): | |
""" pay_list用于标明每期的账单 depst_list[i] 用于标明在第i期还款后剩余的本金,这个值将用于提前还款使用,1.01是由于银行往往会有1%的违约金,可以只计算前real_month期的,也可以全部计算 """ | |
sum_exp_plan = (1+month_rate)**(plan_month) | |
X = base_loan*month_rate*sum_exp_plan/(sum_exp_plan-1) | |
irr = get_irr(base_loan, X, plan_month) | |
pay_list = [] | |
dept_list = [] | |
remain_dept = base_loan | |
for i in range(real_month): | |
pay_list.append(X) | |
remain_dept = remain_dept-(X-remain_dept*irr) | |
dept_list.append(remain_dept*1.01) | |
return pay_list, dept_list | |
def deng_e_ben_jin(base_loan, month_rate, plan_month, real_month): | |
remain_dept = base_loan | |
base_month = base_loan/plan_month | |
pay_list = [] | |
dept_list = [] | |
for i in range(real_month): | |
interest = remain_dept * month_rate | |
pay_list.append(interest+base_month) | |
remain_dept -= base_month | |
dept_list.append(remain_dept*1.01) | |
return pay_list, dept_list | |
def ten_years(house_pirce=160, # 房屋总价 | |
curent_money=110, # 买房时的现金 | |
avg_gain_month=2.5, # 预期的月平均收入 | |
rent_fee=0.22, # 预期的月平均租金(不买房的话需要租房) | |
real_month=12*10, # 只计算多少期 | |
plan_month=12*30, # 分期计划 | |
first_shot_ratio=0.3, # 首付比例 | |
house_inflation_rate = 1.04, # 房屋价格的膨胀系数(每年) | |
investigate_rate=0.03 / 12, # 现金用于理财/投资的月均收益率 | |
month_rate=0.043 / 12, # 房贷的月均利率 | |
pay_list_fn=deng_e_ben_xi): # 分期方法,默认等额本息 | |
loan = house_pirce * (1-first_shot_ratio) | |
pay_list, dept_list = pay_list_fn(loan, month_rate, plan_month, real_month) | |
money_house = curent_money - house_pirce * first_shot_ratio - house_pirce*0.05 | |
money_no_house = curent_money | |
print("{:>2}.{:>2},{:>20},{:>20},{:>20}".format( | |
"YY", "MM", "cash_no_house", "cash_house", "asset_house")) | |
inflation = house_inflation_rate | |
prod_inflation = inflation # 用于评估房子的增值率 | |
for i in range(len(pay_list)): | |
money_house = money_house * \ | |
(1+investigate_rate) + avg_gain_month - pay_list[i] | |
asset_house = money_house - \ | |
dept_list[i] + house_pirce * prod_inflation | |
prod_inflation *= math.pow(house_inflation_rate, 1/12) | |
money_no_house = money_no_house * \ | |
(1+investigate_rate) + avg_gain_month - rent_fee | |
print("{:>2}.{:>2},{:>20},{:>20},{:>20}".format( | |
round(math.floor(i/12))+1, (i) % 12+1, money_no_house, money_house, asset_house)) | |
ten_years() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment