🛠️ToolsShed

複利計算機

時間の経過に伴う投資の複利成長を計算。

複利計算機は、元本だけでなく前期間に蓄積された利息にも利息が付く場合に、投資や預金が時間とともにどのように成長するかを示します。アインシュタインは複利を世界第8の不思議と呼んだと言われています — 利率や期間のわずかな違いが、長期間にわたって劇的に異なる結果をもたらす可能性があります。

元本、年利率、複利計算の頻度(日次、月次、四半期、年次)、期間(年数)を入力すると、最終残高、総利息収入、成長がどのように加速するかがわかる年度別内訳が表示されます。

複利の理解は、退職計画、預金口座の評価、ローンコストの比較、情報に基づいた投資決定に不可欠です。重要な洞察は、早期に開始し、収益を再投資することで、後で高い利率で始めるよりもはるかに多くの富を生み出せるということです。

よくある質問

コード実装

def compound_interest(principal, annual_rate, years, n=12, contribution=0):
    """
    Calculate compound interest with optional regular contributions.

    Parameters:
        principal    - initial investment
        annual_rate  - annual interest rate (e.g. 0.07 for 7%)
        years        - investment duration in years
        n            - compounding frequency per year (12 = monthly)
        contribution - periodic contribution (same frequency as n)

    Returns dict with final balance, total invested, and total interest.
    """
    r = annual_rate / n
    periods = int(years * n)
    balance = principal
    for _ in range(periods):
        balance = balance * (1 + r) + contribution
    total_invested = principal + contribution * periods
    return {
        "final_balance":  balance,
        "total_invested": total_invested,
        "total_interest": balance - total_invested,
    }

def rule_of_72(annual_rate):
    """Estimate years to double at a given annual rate."""
    return 72 / (annual_rate * 100)

# Simple formula (no contributions)
def compound_formula(P, r, n, t):
    """A = P(1 + r/n)^(nt)"""
    return P * (1 + r / n) ** (n * t)

# Examples
result = compound_interest(10000, 0.07, 20, n=12, contribution=500)
print(f"Final balance:   ${result['final_balance']:,.2f}")
print(f"Total invested:  ${result['total_invested']:,.2f}")
print(f"Total interest:  ${result['total_interest']:,.2f}")
print(f"Years to double: {rule_of_72(0.07):.1f} years at 7%")

# Compounding frequency comparison
for label, n in [("Annual", 1), ("Monthly", 12), ("Daily", 365)]:
    A = compound_formula(10000, 0.12, n, 10)
    print(f"{label:8}: ${A:,.2f}  (EAR = {((1 + 0.12/n)**n - 1)*100:.4f}%)")

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.