プログラミング

Pythonで投資の複利計算をする

Pythonプログラミング言語で投資の複利計算をする方法について紹介します。

https://yuis.xsrv.jp/images/ss/ShareX_ScreenShot_f64e3e89-9471-4acd-8943-73ccff0dcecb.png

https://yuis.xsrv.jp/images/ss/ShareX_ScreenShot_8e278c02-ca98-498f-967e-c56085215323.png

60万円からはじめて年10%の利益を10年間続けた場合の値

>>> compound_interest(600000, 10, 10)
1556245.4760600014

60万円からはじめて年10%の利益を20年間続けた場合の値

>>> compound_interest(600000, 10, 20)
4036499.9695953666

コード


def compound_interest(principle, rate, time): 
    print( principle * (pow((1 + rate / 100), time)) )

Bash


calc_compound_interest(){

  : e.g. calc_compound_interest [principle] [rate percentage] [years]
  : e.g. calc_compound_interest 100000 10 20

python3 - $@ <<EOF
# -*- coding: utf-8 -*-

import sys
import re
args = sys.argv


def compound_interest(principle, rate, time):
    print( principle * (pow((1 + rate / 100), time)) )

compound_interest(${1}, ${2}, ${3})

EOF

}

Python Program for compound interest – GeeksforGeeks

毎年ではなく毎月だとか四半期毎とかという場合には以下の方程式が使えそう

Compound Interest Formula

関連記事:

Windows 11にPythonをインストールする
Pythonのバージョン管理をする方法とpyenvの使い方
Pycharmの有料版を無料でインストールするには
Imagededupで類似画像を抽出、検出する(Python)
自然言語テキストが何語なのか判定する [fastText]

関連広告:

Pythonコース by テックアカデミー
Pythonコース by Udemy

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です