List of stock prices over 4 years = [10,15,17,20] List if dividents = [1,2,3,4]…
- User
List of stock prices over 4 years = [10,15,17,20] List if dividents = [1,2,3,4]
Calculate the total return of said stock with dividents reinvested
- Assistant
- User
Create a python script
- Assistant
Certainly! Below is a simple Python script that will calculate the total return of the stock with dividends reinvested:
# List of stock prices over 4 years stock_prices = [10, 15, 17, 20] # List of dividends over 4 years dividends = [1, 2, 3, 4] # Assume we start with purchasing 1 share at the initial stock price initial_shares = 1 total_shares = initial_shares # Reinvest dividends to get additional shares for i in range(len(dividends) - 1): # We reinvest until the year before last # Calculate the additional shares from dividends additional_shares = (total_shares * dividends[i]) / stock_prices[i + 1] # Update the total shares total_shares += additional_shares # Calculate the total value from stock (without the last year's dividend) final_stock_value = total_shares * stock_prices[-1] # Add the last year's dividend to the final stock value final_total_value = final_stock_value + (total_shares * dividends[-1]) # Output the result print(f"The total return of the stock with dividends reinvested is: ${final_total_value:.2f}")Run this script, and it will output the total return of the stock with dividends reinvested. Just copy and paste it into a Python interpreter or a script file.
- Assistant
It seems like there might have been an error in your message as it was left blank. If there's anything specific you would like to know or if you have any questions regarding the Python script or the calculations, please feel free to follow up with more details, and I'll be happy to help you!