【问题标题】:What is the proper formula for calculating the future value of compound interest with end of period deposits用期末存款计算复利未来价值的正确公式是什么
【发布时间】:2019-05-03 04:08:36
【问题描述】:

我正在尝试重新创建此app。但是,对于存款频率与复利周期不匹配的情况,我的函数输出与链接应用程序的投资总价值输出不匹配。

这是我的功能...

def compound_interest(principal, pmt, rate, frequency, period, time):

    contribution_frequencies = {'weekly' : 52, 'biweekly' : 26, 'monthly' : 12, 'quarterly' : 4, 'semiannually' : 2, 'yearly' : 1}
    compounding_periods = {'monthly' : 12, 'quarterly' : 4, 'semiannually' : 2, 'yearly' : 1}

    frequency = contribution_frequencies[frequency]
    period = compounding_periods[period]

    rate = rate / 100

    principal_interest = principal * (1 + (rate / period)) ** (period * time)
    fv =  (pmt * frequency) / period  * ((1 + (rate / period)) ** (period * time) - 1) / (rate / period)

    total = principal_interest + fv

    return round(total, 2)

这是我的测试,存款频率与复利周期相同...

print(compound_interest(5000, 100, 5, 'monthly', 'monthly', 15))
print(compound_interest(5000, 100, 5, 'yearly', 'yearly', 15))
print(compound_interest(5000, 100, 5, 'quarterly', 'quarterly', 15))
print(compound_interest(5000, 100, 5, 'semiannually', 'semiannually', 15))

下面从我的函数返回的实际值与我从链接应用的输出中获得的实际值相同...

37297.41
12552.5
19393.36
14878.11

对于上述以外的情况,测试的实际值与链接应用的实际值不同。比如……

print(compound_interest(5000, 100, 5, 'weekly', 'monthly', 15))

返回...

126393.73

而链接的app 返回...

126579.19

请记住,我的公式计算的是在复利期结束时进行的额外存款(或者它是 says),这似乎与链接应用程序的相同。

对于存款频率和复利周期的所有组合,我将如何重写我的函数,使其返回的实际值与链接应用程序的实际值相同?

谢谢!

【问题讨论】:

    标签: python financial


    【解决方案1】:

    我想我看到了函数中的错误。通常(即,当复利和额外贡献以相同频率发生时),复利周期率确实是rate/period。因此,例如,按季度复利的名义年利率为 5%,可以除以 4 以获得季度复利(即每季度 1.25% - 即rate),得到有效年利率为 5.095%。

    但是,当供款期更改为每月供款时,例如,在复利期没有等效变化时,有效年利率保持不变。因此,仅将名义利率除以 12(这样rate 为 0.41667%)就夸大了您赚取的利息。

    当复利为季度时,要获得实际的每月rate,您需要计算相同投资(不含供款)的每月 IRR,从而得出一年后的未来值等于相同投资的未来值(没有贡献)使用季度复利的有效利率(至少这是我能想到的唯一方法)。

    因此,例如,1,000 美元的未来价值,名义年利率为 5%,每季度复利(无供款)为 1,050.95 美元(这反映了上述有效年利率)。要以相同的利率获得相同的未来价值但每月复利,您的每月 rate 为 0.41494%,小于您将名义年利率除以 12 得到的利率。如果你在计算器网站上检查这个场景,这就是你会看到的结果。

    要做到这一点,您必须制定用于在每对复利/供款期(半年/月、半年/季度等)之间进行转换的公式。这些可能存在于那里,但我找不到它们。获得这些公式后,您必须将它们合并到您的函数中。

    最后,为了让事情变得更复杂,您必须处理每周计算的问题。虽然每年可以整除 4 个季度和 12 个月,但不能整除 52 周。因此,例如,15 年有 782.143 周,而不是 780 周。这必须单独考虑。

    希望 - 如果您仍在尝试这样做 - 这不会让您退出。毕竟,这是一个有趣的项目。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-16
      • 2020-07-20
      • 2016-06-07
      相关资源
      最近更新 更多