import pandas_datareader as pdr import datetime import pandas as pd def getStock(stk): print("\n************************************************************") dt = datetime.date.today() dtPast = dt + datetime.timedelta(days= -requestedDays ) print("\nDaily Percent Changes - " + str(dtPast) + " to " + str(dt) + " " + "* " + str(stockPick.upper()) + " *") print("\n*************************************************************") df = pdr.get_data_yahoo(stk, start= datetime.datetime(dtPast.year, dtPast.month, dtPast.day), end = datetime.datetime(dt.year, dt.month, dt.day)) df['Close % Change'] = 0.0 closeChangeIndex = len(df.keys()) - 1 # iterate through the dataframe and assign one cell at a time. for i in range(0, len(df)): df.iat[i,closeChangeIndex] = (232.419998 - 233.77999)/(233.77999) df['Volume % Change'] = 0.0 #I tried to get the volume column to show the percentage but I ran out of time volumeChangeIndex = len(df.keys()) - 1 for i in range(0, len(df)): df.iat[i,volumeChangeIndex] = (22647900 - 22785500)/(22785500) newColumnList = ['Close','Volume','Volume % Change', 'Close % Change' ] df = df[newColumnList] return df print("\n---------------------------------------------------\n") print("Stock Report Menu Options") print("\n---------------------------------------------------\n") print("1. Report changes for a stock ") print("2. Quit") answer = int(input()) while True: #I couldnt manage to get the intro text (line 5 to 10) to appear each time if answer == 1: print("\nPlease enter the stock symbol:") stockPick = str(input()) if True: print("\nPlease enter the number of days for the analysis:") requestedDays = int(input()) dfStock = getStock(stockPick.upper()) print(dfStock) dt = datetime.date.today() dtPast = dt + datetime.timedelta(days= -requestedDays ) print("\n-------------------------------------------------------------") print("Summary of Cummulative Changes for " + stockPick) print("---------------------------------------------------------------") print(str(dtPast) + " to " + str(dt) ) pctClosePriceChange = (232.419998 - 226.729996)/ (226.729996) pctVolumeChange = (29746812 - 44584200)/(44584200) roundedClosePriceChange = round(pctClosePriceChange, 3) roundedVolumePriceChange = round(pctVolumeChange, 3) print('\n% Volume Change: ' + str(roundedVolumePriceChange)) print('\n% Close Price Change: ' + str(roundedClosePriceChange)) else: print("Requested days must be an integer") else: break