python-CFA-计算实现理财目标需要准备的现金流期数

简介: python-CFA-计算实现理财目标需要准备的现金流期数

An individual wants to be able to spend €80,000 per year for an anticipated 25 years in retirement. To fund this retirement account, he will make annual deposits of €6,608 at the end of each of his working years. He can earn 6% compounded annually on all investments. The minimum number of deposits that are needed to reach his retirement goal is closest to:

def calculate_needed_num(deposit_money,cost_money,cost_years,return_rate):
    count=1
    while True:
        net_money=0
        for i in range(count):
            net_money=net_money*(1+return_rate)+deposit_money
        for i in range(25):
            net_money=(net_money-cost_money)*(1+return_rate)
        if net_money>=0:
            return count
        count+=1

calculate_needed_num(6608,80000,25,0.06)

得到41

目录
相关文章
|
18天前
|
Python
python幂运算——计算x的y次方
python幂运算——计算x的y次方
38 0
|
13天前
|
算法 程序员 Python
年底工资总结,实例教你用Python计算个税 依法纳税做好公民(1)
年底工资总结,实例教你用Python计算个税 依法纳税做好公民(1)
|
16天前
|
数据采集 数据挖掘 关系型数据库
Excel计算函数(计算机二级)(1),2024年最新2024Python架构面试指南
Excel计算函数(计算机二级)(1),2024年最新2024Python架构面试指南
|
16天前
|
Python
【Python 百练成钢】高精度加法、阶乘计算、矩阵幂运算、矩阵面积交
【Python 百练成钢】高精度加法、阶乘计算、矩阵幂运算、矩阵面积交
|
16天前
|
存储 算法 Python
【Python 百练成钢】高精度加法、阶乘计算、矩阵幂运算、矩阵面积交(2)
【Python 百练成钢】高精度加法、阶乘计算、矩阵幂运算、矩阵面积交(2)
|
16天前
|
存储 算法 Python
【Python 百练成钢】高精度加法、阶乘计算、矩阵幂运算、矩阵面积交(1)
【Python 百练成钢】高精度加法、阶乘计算、矩阵幂运算、矩阵面积交(1)
|
18天前
|
Python
python计算线段角度
python计算线段角度
12 0
|
18天前
|
安全 数据安全/隐私保护 Python
Python的整型在计算中具有以下优势
【5月更文挑战第6天】Python整型提供任意精度整数计算,无溢出风险;支持多种算术运算,操作简便;作为不可变类型保证数据安全;能进行高级数学运算,并有NumPy等库加持,适合数值分析和科学计算。
24 0
|
18天前
|
Python
Python的整型在计算中的精度可以通过使用二进制或十进制表示来体现
【5月更文挑战第6天】Python整型支持十、二、八、十六进制表示,其中十进制默认,二进制(0b前缀)、八进制(0o前缀)、十六进制(0x前缀)。计算时以二进制精度处理,确保结果准确。例如:123的二进制是0b1111011,八进制是0o173,十六进制是0x7b。
19 0
|
18天前
|
Python
Python计算股票投资组合的风险价值(VaR)
Python计算股票投资组合的风险价值(VaR)