I am working on a project using python:
this is broken into two parts
I have completed the first part and need assistance with part 2:
PART 1 COMPLETED CODE :
# global variable
multiplier_amount = 1000000
def calculate_gains(amount_inv=0.0):
""" Calculating the return gains of an investment.
# base amount gain margin"""
gain_margin = .001
total_amount_gains=0
total_gains=0
if amount_inv > 1000:
# check whether the invested amount is greater than the multiplier amount
if amount_inv > multiplier_amount:
# gather the value of the division
mod = amount_inv // multiplier_amount
# update the `gain_margin` by the multiplier mod
gain_margin = ((mod / 100) + gain_margin)
# calculate the total amount of gains
total_amount_gains = (amount_inv * gain_margin) + amount_inv
# calculate the total amount plus the gain margin
total_gains = amount_inv * gain_margin
# return the gains, the full amount and the gain margin
return total_gains, total_amount_gains, gain_margin
print(calculate_gains(amount_inv=2000000))
PART 2 - THIS IS WHAT I NEED HELP WITH:
Another functionality for the app is the ability to estimate the return on investment over a period of time. In order to implement this feature, you will have to update the investment calculator algorithm.
The base function to calculate the return on investment from Task 1 can be reutilized here to simplify our task. This feature will take into consideration a 12-month period by default.
To calculate the total amount earned over a period of time, you will have to loop through the n-months period, increase the amount for each period. The other rules from the previous task apply here as well.
For example: If you invest $3 million on the first month, and obtain a return of $93,000 dollars, then the amount to be invested in the second month is $3.093 million.
To summarize:
Note that to calculate the accumulated value over a 12-month period do not just multiply the gain of every month by 12 (or n). In this case, the gain of every month is added to the original value, updating the amount to be invested in the subsequent month.
The following base code is given for you in the file calculate_gains_over_time.py:
#The following base code is given for you.
def calculate_gains_over_time(amount_inv=0.0, period=12):
"""
Calculating the return gains of a given amount invested based on a period of application.
:param amount_inv: the money amount invested
:param period: application period
:return:
"""
# call the base `calculate_gains` function to estimate the gains for the first period
# calculate the first period before entering the loop
# loop through the specified period to calculate the gain of each month
# 1 to period-1 because the first period gains is already calculated above
# call the function to update the value based on the period inside the loop and the updated amount
new_amount = total_amount # update the `new_amount` variable
# return the final ammount
return new_amount
print(calculate_gains_over_time(amount_inv=4000000, period=12))
ANSWER:
CODE TEXT
#The following base code is given for you.
def calculate_gains_over_time(amount_inv=0.0, period=12):
"""
Calculating the return gains of a given amount invested based on a
period of application.
:param amount_inv: the money amount invested
:param period: application period
:return:
"""
# call the base `calculate_gains` function to estimate the gains
for the first period
# calculate the first period before entering the loop
gains, total_amount, gain_margin =
calculate_gains(amount_inv=amount_inv)
# defining new_amount value to total_amount_gains value recieved by
calling above function
new_amount = total_amount
# loop through the specified period to calculate the gain of each
month
# 1 to period-1 because the first period gains is already
calculated above
for i in range(period-1):
# call the function to update the value based on the period inside
the loop and the updated amount
gains, total_amount, gain_margin =
calculate_gains(amount_inv=new_amount)
new_amount = total_amount # update the `new_amount` variable
# return the final ammoun
return new_amount
print(calculate_gains_over_time(amount_inv=4000000, period=12))
CODE IMAGE
OUTPUT IMAGE
Get Answers For Free
Most questions answered within 1 hours.