码迷,mamicode.com
首页 > 编程语言 > 详细

R 语言贷款月供数据分析

时间:2018-05-09 14:59:55      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:color   计算   int   span   数据分析   col   rem   sum   code   

#================================================================
#----------------------------------------------------------------
# 步骤 0:为各个变量赋值
# P: 本金
# m: 还款的总月份
# i: 年利率
# s: 月利率

P=25000
i=0.05
m=120
s=i/12

# step 1: 计算月份向量

t=1:m

# step 2: 计算月还款额

monthly.payment = (1+s)^m*s*P/((1+s)^m-1)

# step 3: 计算每个月应该偿还的本金额度向量

principal.paid.money.t = (1+s)^(t-1)*s*P/((1+s)^m-1)

# step 4:  计算每月未偿还的本金额度向量

principal.remaining= P*(1-((1+s)^t-1)/((1+s)^m-1))


# step 5: 用每月还款额扣除每月应偿还的本金额度向量,计算每个月还的利息

interest.paid.month.t = monthly.payment - principal.paid.money.t

# step 6: 将每个月所付出的利息累加,计算总利息

total.interest.paid=sum(interest.paid.month.t)

# step 7: 在控制台显示计算结果

monthly.payment
total.interest.paid
t
principal.paid.money.t
interest.paid.month.t
principal.remaining

# step 8: 以月份向量为横轴,以未偿还的本金额度向量为纵轴来绘图

plot(t,principal.remaining,type="l")

选自 《R 语言初学指南》

R 语言贷款月供数据分析

标签:color   计算   int   span   数据分析   col   rem   sum   code   

原文地址:https://www.cnblogs.com/reycg-blog/p/9013201.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!