私は、方程式で毎年ランダムな収益率を使用する人々の 401k の財務モデルに取り組んでいます。ループを実行しているときに、リターン率を次から次へと変更する方法を知りたいです。言い換えれば、ワックスボールが毎年計算されるたびに使用されるランダムな返品率が必要です。
たとえば、1 年目 2000 * 1.10 = 2,200 2 年目 2,100 * 1.2 = 2,520*
*これには、私のコードからの wax_ball と貢献変数は含まれません。私の問題は選択機能にあるようです...3つの異なる返品率から選択するようにインポートしました。
以下は私のコードです。
ご協力いただきありがとうございます。XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
print "How much do you want to contribute to your 401k?"
contribution = int(raw_input())
# money contributed to 401k
print "What is your 401k worth now?"
wax_ball = int(raw_input())
# sum of all contribution plus interest of every year
print "When do you want to withdraw on it?"
time= int(raw_input())
# time in years
interest_rate = [.25,.1,.01]
#average return rate randomized
from random import choice
choice(interest_rate)
for x in range (0, time):
wax_ball= contribution+(wax_ball*(1+interest_rate))
print round(wax_ball,2)