[solved]-Assignment Provide Practice Creating Functions Determining Use Using Previous Assignment Q39027158
This assignment will provide you with practice creatingfunctions and determining how and when to use them.
Using the previous assignment, move the code you use tocalculate the loss/gain into a function.
# stock.pydef get_profit_loss(stock_data, owner): earning_loss = [] # iterating through keys and values for key, value in stock_data.items(): # as list is index based so current value will at last index that is 2nd # and purchase price will be at 2 difference = value[2] – value[1] # number of stock will be at 0 position earning_loss.append(difference * value[0]) print(“Stock ownership for {}”.format(owner)) print(“…………………………….”) print(“{0:<10}{1:<10}{2:<10}”.format(“STOCK”, “SHARE#”, “EARNINGS/LOSS”)) # for specific format print(“…………………………….n”) # using count for accessing earning_loss value count = 0 for key, value in stock_data.items(): # key will symbol and number of share will be at 0th index print(“{0:<10}{1:<10}${2:<10}”.format(key, value[0], (round(earning_loss[count], 2)))) count += 1def main(): # converting list to key, as there are three main property of shares # so putting all the values in list like [no_of_shares, purchase_price, current_price] # for each of keys, keys are the symbol of stock in dictionary stock_data = { ‘GOOGL’: [125, 772.88, 941.53], ‘MSFT’: [85, 56.60, 73.04], ‘RDS-A’: [400, 49.58, 55.74], ‘AIG’: [235, 54.21, 65.27], ‘FB’: [150, 124.31, 172.45] } get_profit_loss(stock_data=stock_data, owner=”BobSmith”) # similarly you can define stock data for multiple users # and call this function with datamain()
# OUTPUT
Furthermore, add an additional data item – the purchase date.Make sure that each of the existing entries has the purchase dateof 8/1/2015. Then add the following three records as well.
Add a second function to your code that calculates thepercentage yield/loss for each of the stocks, and a third that willcalculate the yearly earnings/loss rate (the formulas arebelow).
Move all your functions to a separate module.
STOCK SYMBOL
NO SHARES
PURCHASE PRICE
CURRENT VALUE
PURCHASE DATE
M
425
30.30
23.98
1/10/2017
F
85
12.58
10.95
2/17/2017
IBM
80
150.37
145.30
5/12/2017
Then create a report, similar to the one below, calculating howmuch the investor has earned or lost, as well as the average yearlyreturn.
Calculate the earnings/loss by using the following formula:
(current value – purchase price) x number of shares
Calculate yearly earnings/loss rate using the followingformula*:
((((current value – purchase price)/purchase price)/(currentdate – purchase date)))*100
*for anyone with a finance background, while this may not be thebest way to calculate the average yearly yield, it will serve thepurpose for this exercise
Stock ownership for Bob Smith
—————————————————-
STOCK SHARE# EARNINGS/LOSS YEARLY EARNING/LOSS
——————————————————————————————————
GOOGL 125$21026.25 10.88%
MSFT 85 $1397.4 14.48%
RDS-A 400 $2464 6.20%
AIG 235 $3599.1 10.17%
FB 150 $7221 19.31%
M 425-$2686 -37.32%
F 85 -$135.55 -28.49%
IBM 80 -$405.60 -15.01%
Expert Answer
Answer to This assignment will provide you with practice creating functions and determining how and when to use them. Using the pr… . . .
OR

