Menu

[solved]-Using Previous Assignment Set Code Use Classes Set Stock Data Variables Class Attributes F Q39061888

Using the previous assignment, set up your code to use classes.Set up the stock data variables as class attributes and functionsas stock class methods.
# stock.py

import datetime
# returns the yearly gain or loss percentage

def yearly_return_percentage(earning_loss,purchase_dt):
    purchase_dt=[int(value) for value inpurchase_dt.split(‘/’)]
   a=datetime.date(purchase_dt[2],purchase_dt[0],purchase_dt[1])
    now = datetime.datetime.now()
   b=datetime.date(now.year,now.month,now.day)
    return earning_loss*100.0/(a-b).days

def get_profit_loss(stock_data, owner):
    earning_loss = []
    # iterating through keys and values
    for key, value in stock_data.items():
        # as list is index basedso current value will at last index that is 2nd
        # and purchase pricewill be at 2
        difference = value[2] -value[1]
        # number of stock willbe at 0 position
       earning_loss.append(difference * value[0])
    print(“Stock ownership for{}”.format(owner))
   print(“……………………………………………….”)
   print(“{0:<10}{1:<10}{2:<15}{3:>15}”.format(“STOCK”,”SHARE#”, “EARNINGS/LOSS”,”YEARLY EARNING/LOSS”)) # for specificformat
   print(“……………………………………………….n”)
    # using count for accessing earning_lossvalue
    count = 0
    for key, value in stock_data.items():
        # key will symbol andnumber of share will be at 0th index
       yr_per=round(yearly_return_percentage(value[2] -value[1],value[3]),2)
       print(“{0:<10}{1:>4}{2:>19}{3:>15}%”.format(key,value[0], ‘${}’.format(round(earning_loss[count],2)),yr_per))
        count += 1

def main():
    # converting list to key, as there are threemain 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 stockin dictionary
    stock_data = {
        ‘GOOGL’: [125, 772.88,941.53,’1/10/2017′],
        ‘MSFT’: [85, 56.60,73.04,’1/12/2017′],
        ‘RDS-A’: [400, 49.58,55.74,’4/15/2017′],
        ‘AIG’: [235, 54.21,65.27,’10/18/2017′],
        ‘FB’: [150, 124.31,172.45,’11/19/2017′],
       ‘M’:[425,30.30,23.98,’1/10/2017′],
        ‘F’:[85, 12.58,10.95,’2/17/2017′],
        ‘IBM’:[80,150,145.30,’5/12/2017′]}

    get_profit_loss(stock_data=stock_data,owner=”BobSmith”)

    # similarly you can define stock data formultiple users
    # and call this function with data

main()

————————————————————————————————————————————————-
Create a class for the investor as well, and add an address andphone number component for them.

Create an additional class for bonds. Bonds are similar to stocks,so set up the bond class to inherit from the stock class, but addcoupon and yield attributes to it as well. Add method necessary toread the additional two values.

Add ID fields in all the classes – for example investorID for theinvestor class and purchaseID for the stock and bond purchaserecords.

Instantiate all the classes to the current information Bob Smithhas.

Add a single bond to Bob Smith’s portfolio, with the followinginformation:

Symbol: GT2:GOV

Purchase Price: 100.02

Current Price: 100.05

Quantity: 200

Coupon: 1.38

Yield: 1.35%

Purchase Date: 8/1/2017

Create a screen print out, just like you did before, but also add abond section.

Expert Answer


Answer to Using the previous assignment, set up your code to use classes. Set up the stock data variables as class attributes and … . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *