Question

I am working on a project using python: this is broken into two parts I have...

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:

  • Loop over a period of 12 months to calculate the total for each period
  • Return the accumulated estimated value for a period of 12 months

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))

Homework Answers

Answer #1

ANSWER:

  • I have provided the properly commented code in both text and image format so you can easily copy the code as well as check for correct indentation.
  • I have provided the output image of the code so you can easily cross-check for the correct output of the code.
  • Have a nice and healthy day!!

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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Please create a python module named homework.py and implement the functions outlined below. Below you will...
Please create a python module named homework.py and implement the functions outlined below. Below you will find an explanation for each function you need to implement. When you are done please upload the file homework.py to Grader Than. Please get started as soon as possible on this assignment. This assignment has many problems, it may take you longer than normal to complete this assignment. This assignment is supposed to test you on your understanding of reading and writing to a...
def clear(file_path: str): """ Clears the file at the specified file path. :param file_path: A path...
def clear(file_path: str): """ Clears the file at the specified file path. :param file_path: A path to a file :return: None """ def delete_last_line(file_path: str) -> str: """ Removes the last line in the file at the specified file path. Then it saves the new value with the last line removed to the file. Finally it returns the deleted last line. If the file has nothing in it an empty string ("") is returned. :param file_path: A path to file...
Hello i am working on a project for my programming course and i am a little...
Hello i am working on a project for my programming course and i am a little lost. The assignment is as follows: Part A Do all of problem 3.13 (Employee Class), including the main, as written. Part B Now, suppose a new company policy says that instead of the monthly salary we will now store the yearly salary. We will need to make this change inside Employee and support the new usage, without breaking existing code (such as the old...
Using Interest Factor Table Ali invested $300,000 in a small project for an interest rate of...
Using Interest Factor Table Ali invested $300,000 in a small project for an interest rate of 8%. Four years later, he invested another $600,000 in the same project but this time for an interest rate of 10%. What is the total amount of money he is going to receive after 12 years of his investment period? Compressor that has the following costs are under consideration for using in a new chemical plant. Using interest rate of 10% per year. Calculate...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):         self.name = name         self.pop = pop         self.area = area         self.continent = continent     def getName(self):         return self.name     def getPopulation(self):         return self.pop     def getArea(self):         return self.area     def getContinent(self):         return self.continent     def setPopulation(self, pop):         self.pop = pop     def setArea(self, area):         self.area = area     def setContinent(self, continent):         self.continent = continent     def __repr__(self):         return (f'{self.name} (pop:{self.pop}, size: {self.area}) in {self.continent} ') TASK 2 Python Program: File: catalogue.py from Country...
2). Question with methods use scanner (Using Java): You are going to invest the amount, then...
2). Question with methods use scanner (Using Java): You are going to invest the amount, then you going to compute that amount with annual interest rate. 1) Prompt the user to enter student id, student name, student major 2) Declare variables consistent with names that you are prompting and relate them to the scanner 3) Declare the amount invested in college, prompt the user to ask for amount and declare variable and scanner to input 4) Declare the annual interest...
Maths of finance This task assesses the following learning outcomes: Time value for money and the...
Maths of finance This task assesses the following learning outcomes: Time value for money and the rate of return Assess the simple interest and compound interest Net Present value in Capital Budgeting (Internal rate of return, Payback period) Annuities (PV, FV, Growth Annuities, types of Annuities) Perpetuities (PV, Growth Perpetuities) 3. How long will it take to your money to earn 2000€ at a rate of 12% simple interest rate? 4. If you want to invest only one part of...
Maths of finance This task assesses the following learning outcomes: Time value for money and the...
Maths of finance This task assesses the following learning outcomes: Time value for money and the rate of return Assess the simple interest and compound interest Net Present value in Capital Budgeting (Internal rate of return, Payback period) Annuities (PV, FV, Growth Annuities, types of Annuities) Perpetuities (PV, Growth Perpetuities) 2. The bank offers you some options, however, you can't withdraw it for 5 years: a. 8% simple interest b. 6% compounded semiannual c. 5.5% compounded monthly Which is the...
Please answer correct, I have used to many credits and lost them due to incorrect answers…....
Please answer correct, I have used to many credits and lost them due to incorrect answers…. Aaron Heath is seeking part-time employment while he attends school. He is considering purchasing technical equipment that will enable him to start a small training services company that will offer tutorial services over the Internet. Aaron expects demand for the service to grow rapidly in the first two years of operation as customers learn about the availability of the Internet assistance. Thereafter, he expects...
6.   If the general level of interest rates goes down and I am holding a bond with...
6.   If the general level of interest rates goes down and I am holding a bond with a fixed coupon rate, I would expect the value of my bond to a.stay the same b.double c.increase d.decrease e.not enough information to tell 7.  The Rule of 72’s a.Is about doubling the present value to get the future value. b.Says that 72 divided by the payment gives you the number of years to double. c.Says that the rate divided by 72 gives you the...