Create your own mock stock portfolio, complete with a P/L statement in Python. The goal of this final project is to be able to pretend to buy and sell stock with real stock data; while recording your

import pandas as pd import datetime #Open persistance data try:

pl = pd.read_csv('my_pl.csv',index_col=False) except Exception as e:

print(str(e)) pl = pd.DataFrame({'BALANCE':[1000000.0], 'DATE':[datetime.datetime.now()], 'TICKER':['GOOG'], 'PRICE':[55.0], 'SHARES':[100.0], 'COST':[5500.0]}) #Should already be sorted, but lets make sure pl = pl.sort_values(by='DATE') #User input function while True:

try:

TICKER = input('Please enter a ticker') PRICE = int(input('Remind me, what price was this?')) COST = float(input('Please enter how much to buy in USD')) break except:

pass SHARES = COST / PRICE OLD_BALANCE = float(pl.tail(1)['BALANCE']) NEW_BALANCE = OLD_BALANCE - COST new_row = pd.DataFrame({'BALANCE':[NEW_BALANCE], 'DATE':[datetime.datetime.now()], 'TICKER':[TICKER], 'PRICE':[PRICE], 'SHARES':[SHARES], 'COST':[COST]}) pl = pd.concat([pl,new_row]) pl.to_csv('my_pl.csv',index=False)