python: compounding

Write a financial calculator, to achieve the daily interest / month / year were calculated complex investment

fuli.py

``````# coding: utf-8
# 写一个理财计算器，实现将每日/月/年的利息进行复投进行计算

money = float(input('请输入您打算用来投资的本金:PV: '))
year = int(input('请输入投资期限(单位：年):N: '))
rate = float(input('请输入投资年化收益率:I: '))
mm = int(input('''1.每月 3.每3月 6.每6月 12.每年 请选择利息复投方式: '''))

def day_return(money,year,rate=0.06):
'''方案：每日利息加入本金复投'''
for y in range(year):
for day in range(365):
money = money*rate/365 + money
print('第%d年结束时，本金为：%.2f' % (y+1,money))

def month_return(money,year,mm,rate=0.06):
'''方案：每月利息加入本金复投'''
for y in range(year):
cs = 12//mm
for month in range(cs):
money = money*rate/cs + money
print('第%d年结束时，本金为：%.2f' % (y+1,money))

def year_return(money,year,rate=0.06):
'''方案：每年利息加入本金复投'''
for y in range(year):
money = money*rate + money
print('第%d年结束时，本金为：%.2f' % (y+1,money))

if mm in (1,2,3,4,6):
month_return(money,year,mm,rate)
elif mm == 12:
year_return(money,year,rate)
else:
print('mm 输入有误！')

``````

1. example of a company into the bank in early 2007 to 50,000 yuan of funds, annual interest rate of 8%, according to the semiannual compounding interest, you can get when due 2017 and the principal and interest are:

python fuli.py

Enter your intention to invest in capital: PV: 50000
Please enter the investment period (unit: Year): N: 10
Please enter the annualized rate of return of investment: the I: 0.08
1. 3. Each month March 6. Each June 12. Please select the annual interest re-cast mode: 6
At the end of the first year, the principal amount of: 54,080.00
at the end of the second year, the principal amount of: 58,492.93
at the end of the third year, the principal amount of: 63,265.95
4th year end , the principal amount of: 68,428.45
at the end of the fifth year, the principal amount of: 74,012.21
at the end of the sixth year, the principal amount of: 80,051.61
at the end of the seven years, the principal amount of: 86,583.82
at the end of the eighth year, the principal amount of: 93649.06
at the end of the ninth year, the principal amount of: 101,290.83
at the end of the tenth year, the principal amount of: 109,556.16

Published 106 original articles · won praise 27 · views 330 000 +

Guess you like

Origin blog.csdn.net/belldeep/article/details/103939689
Recommended
Ranking
Daily