我必须使用我面临困难的函数进行计算
计算公式:
收益/损失:(value-price)*share
年收入/损失百分比= ((value-price)/price)/(current date- purchase date))*100
stocks = [
{ 'symbol': 'GOOGLE', 'share': 125, "price": 772.88, 'value': 941.53,'Purchase Date':"8-1-2015" },
{ 'symbol': 'MSFT', 'share': 85, "price": 56.60, 'value': 73.04 ,'Date':"8-1-2015"},
{ 'symbol': 'RDS-A', 'share': 400, "price": 49.58, 'value': 55.74 ,'Purchase Date':"8-1-2015"},
{ 'symbol': 'AIG', 'share': 235, "price": 54.21, 'value': 65.27 ,'Date':"8-1-2015"},
{ 'symbol': 'FB', 'share': 150, "price": 124.31, 'value':172.45,'Purchase Date':"8-1-2015" },
{ 'symbol': 'M', 'share': 425, "price": 30.30, 'value': 23.98 ,'Purchase Date':"1-10-2017"},
{ 'symbol': 'F', 'share': 85, "price": 150.37, 'value': 145.30,'Date':"2-17-2017" },
{ 'symbol': 'IBM', 'share': 80, "price": 150.37, 'value': 145.30,'Purchase Date':"5-12-2017"}
]
print('Stock ownership for Bob Smith')
print('-----------------------------------------')
print('Stock Share # Earn/Lose Date')
print('----------------------------------------')
for stock in stocks:
earn = stock['share'] * stock['value'] - stock['share'] * stock['price']
print(f'{stock["symbol"]}\t\t{stock["share"]}\t\t{round(earn, 2)}\t\t{stock["Date"]}')
我假设数据中的
Date
表示Purchase Date
相关问题 更多 >
编程相关推荐