0

I am trying to create a while loop to simulate a withdrawal of an equity portfolio. I have created the variables and the code beforehand works when entering a float displays the remaining portfolio balance however I don't know how to create the while loop for this function (Withdrawals increasing with "US CPI" column so you have the same purchasing power each year. It should start the annual withdrawal at 0.01% and increase 0.01% each time it loops through until the Remaining portfolio variable = $0 then print the last working withdrawal percent. I have tried a few times but the answer is going into 1000's the real answer should be from like 8-20% maximum per year withdrawal.

    while Withdrawal_Percentage_Test:
    Withdrawal_Percentage_Test = Withdrawal_Percentage_Test + float(0.01)

else: 
    df3["Portfolio_Value"] == float(0) 
    print("Unfortunately you don't not have enough money to last the duration please amend your portfolio allocation")

df3["Withdrawal $ Adj Inflation"] = df3["Withdrawal $"] * (1 + df3["US CPI"]).cumprod()

df3["Portfolio_Remaining"] = df3["Equity Portfolio Value"] - df3["Withdrawal $ Adj Inflation"]

print(Withdrawal_Percentage_Test)
OTheDev
  • 2,916
  • 2
  • 4
  • 20
  • Could you provide a minimal amount of code that will run? The `if` statement is missing. – Guy Keogh Apr 23 '22 at 23:24
  • `while ... else ...` is a valid Python statement so it's maybe indentation error on the OP's part. https://stackoverflow.com/questions/3295938/else-clause-on-python-while-statement – Code Different Apr 24 '22 at 01:36

0 Answers0