Code cleanups and one more place to use money class.
authorScott Gasch <[email protected]>
Thu, 16 Jan 2020 00:10:55 +0000 (16:10 -0800)
committerScott Gasch <[email protected]>
Thu, 16 Jan 2020 00:10:55 +0000 (16:10 -0800)
retire.py

index 17c4f5ae15264cc7d4b7d18e05af643b1350c89c..fa86bdaaf2e641f38303960a40069c4fb1e98b8b 100755 (executable)
--- a/retire.py
+++ b/retire.py
@@ -43,11 +43,12 @@ class simulation(object):
         for x in self.accounts:
             if not x.is_age_restricted():
                 amount_to_withdraw = min(amount_needed, x.get_balance())
-                print "## Withdrawing %s from %s" % (amount_to_withdraw,
-                                                     x.get_name())
-                x.withdraw(amount_to_withdraw, taxes)
-                amount_needed -= amount_to_withdraw
-                if amount_needed <= 0: return
+                if amount_to_withdraw > 0:
+                    print "## Withdrawing %s from %s" % (amount_to_withdraw,
+                                                         x.get_name())
+                    x.withdraw(amount_to_withdraw, taxes)
+                    amount_needed -= amount_to_withdraw
+                    if amount_needed <= 0: return
 
         # Next try age restircted accounts
         for x in self.accounts:
@@ -57,11 +58,12 @@ class simulation(object):
                  (x.belongs_to_scott() and self.scott_age > 60))):
 
                 amount_to_withdraw = min(amount_needed, x.get_balance())
-                print "## Withdrawing %s from %s" % (amount_to_withdraw,
-                                                     x.get_name())
-                x.withdraw(amount_to_withdraw, taxes)
-                amount_needed -= amount_to_withdraw
-                if amount_needed <= 0: return
+                if amount_to_withdraw > 0:
+                    print "## Withdrawing %s from %s" % (amount_to_withdraw,
+                                                         x.get_name())
+                    x.withdraw(amount_to_withdraw, taxes)
+                    amount_needed -= amount_to_withdraw
+                    if amount_needed <= 0: return
 
         # Last try Roth accounts
         for x in self.accounts:
@@ -71,11 +73,12 @@ class simulation(object):
                  (x.belongs_to_scott() and self.scott_age > 60))):
 
                 amount_to_withdraw = min(amount_needed, x.get_balance())
-                print "## Withdrawing %s from %s" % (amount_to_withdraw,
-                                                     x.get_name())
-                x.withdraw(amount_to_withdraw, taxes)
-                amount_needed -= amount_to_withdraw
-                if amount_needed <= 0: return
+                if amount_to_withdraw > 0:
+                    print "## Withdrawing %s from %s" % (amount_to_withdraw,
+                                                         x.get_name())
+                    x.withdraw(amount_to_withdraw, taxes)
+                    amount_needed -= amount_to_withdraw
+                    if amount_needed <= 0: return
         raise Exception("Unable to find enough money this year, still need %s more!" % amount_needed)
 
     def get_social_security(self,
@@ -121,7 +124,7 @@ class simulation(object):
             self.scott_age, self.lynn_age, self.alex_age)
 
         # Print out how much money is in each account + overall net worth.
-        total = 0
+        total = money(0)
         for x in self.accounts:
             total += x.get_balance()
             print "{:<50}: {:>14}".format(x.get_name(), x.get_balance())
@@ -173,9 +176,10 @@ class simulation(object):
 
                 # When we reach a certain age we are eligible for SS
                 # payments.
-                ss = self.get_social_security(adjusted_scott_annual_social_security_dollars,
-                                              adjusted_lynn_annual_social_security_dollars,
-                                              taxes)
+                ss = self.get_social_security(
+                    adjusted_scott_annual_social_security_dollars,
+                    adjusted_lynn_annual_social_security_dollars,
+                    taxes)
                 if ss > 0:
                     print "## Social security paid %s" % ss
                     total_income += ss
@@ -228,20 +232,20 @@ class simulation(object):
                 #   * Social security benefits increase
                 #   * Tax brackets are adjusted for inflation
                 inflation_multiplier = self.params.get_average_inflation_multiplier()
+                returns_multiplier = self.params.get_average_investment_return_multiplier()
+                ss_multiplier = self.params.get_average_social_security_multiplier()
                 adjusted_annual_expenses *= inflation_multiplier
                 for x in self.accounts:
-                    x.appreciate(self.params.get_average_investment_return_multiplier())
+                    x.appreciate(returns_multiplier)
                 if self.scott_age >= self.params.get_initial_social_security_age(constants.SCOTT):
-                    adjusted_scott_annual_social_security_dollars *= self.params.get_average_social_security_multiplier()
+                    adjusted_scott_annual_social_security_dollars *= ss_multiplier
                 if self.lynn_age >= self.params.get_initial_social_security_age(constants.LYNN):
-                    adjusted_lynn_annual_social_security_dollars *= self.params.get_average_social_security_multiplier()
-
+                    adjusted_lynn_annual_social_security_dollars *= ss_multiplier
                 self.params.get_federal_ordinary_income_tax_brackets().adjust_with_multiplier(inflation_multiplier)
                 self.params.get_federal_dividends_and_long_term_gains_income_tax_brackets().adjust_with_multiplier(inflation_multiplier)
         except Exception as e:
             print "Exception: %s" % e
-            print "Ran out of money!!!"
-            pass
+            print "Ran out of money!?!"
 
         finally:
             self.dump_final_report(taxes)