Untitled

Run Settings
LanguagePython
Language Version
Run Command
def forecast_price(stock_symbol): #list of all prices for the recent month's BAC = [29.9, 32.5, 31.48, 29.31, 29.95, 29.4, 28.28] T = [37.65, 39.16, 36, 35.1, 32.54, 32.47, 32.21] GE = [17.98, 16.02, 14.02, 13.12, 14.05, 14.1, 13.37] F = [12.66, 10.92, 10.29, 10.86, 11.26, 11.71, 11.1] TWTR = [24.51, 27.14, 32.24, 28.04, 30.3, 36.65, 44.98] C = [74.36, 79.2, 73.66, 67.71, 68.25, 67.28, 67.16] ORCL = [46.63, 51.63, 49.71, 45.01, 45.95, 47.35, 44.95] JPM = [107.95, 116.87, 113.43, 107.85, 108.78, 108.4, 105.08] PFE = [36.44, 36.83, 35.63, 35.05, 35.4, 36.25, 36.33] BABA = [183.65, 192.22, 181.99, 177.61, 179.5, 204.34, 186.36] AAPL=[172.26,167.78,175,166.68,169.1,190.24,187.18] MSFT = [85.95, 94.26, 92.85, 88.52, 95, 100.79, 100.01] INTC= [46.85,47.65,47.84,48.92,53.33,57.08,50.20] F=[12.66,10.92,10.29,10.86,11.26,11.71,11.10] EBAY=[38.06,46.40,42.27,39.36,37.83,38.34,36.67] AMZN=[1189.01,1390,1493.45,1371.99,1582.26,1641.54,1713.78] GOOGL= [1073.21,1181.59,1071.41,1012.63,1040.75,1135,1142.11] a=0 mae=0 # function selection if stock_symbol == 'BAC': stock_array_mini = BAC[:-1] stock_array_full= BAC a = 0.3 elif stock_symbol == 'T' : stock_array_mini = T[:-1] stock_array_full = T a = 0.45 elif stock_symbol == 'GE' : stock_array_mini = GE[:-1] stock_array_full = GE a=0.4 elif stock_symbol == 'TWTR': stock_array_mini = TWTR[:-1] stock_array_full = TWTR a=0.8 elif stock_symbol == 'C' : stock_array_mini = C[:-1] stock_array_full = C a=0.8 elif stock_symbol == 'ORCL' : stock_array_mini = ORCL[:-1] stock_array_full = ORCL a=0.5 elif stock_symbol == 'JPM' : stock_array_mini = JPM[:-1] stock_array_full = JPM a=0.6 elif stock_symbol == 'PFE' : stock_array_mini = PFE[:-1] stock_array_full = PFE a=0.25 elif stock_symbol == 'BABA' : stock_array_mini = BABA[:-1] stock_array_full = BABA a=0.85 elif stock_symbol == 'AAPL' : stock_array_mini = AAPL[:-1] stock_array_full = AAPL a=0.75 elif stock_symbol == 'MSFT': stock_array_mini = MSFT[:-1] stock_array_full = MSFT a=0.82 elif stock_symbol == 'INTC': stock_array_mini = INTC[:-1] stock_array_full = INTC a=0.5 elif stock_symbol == 'F': stock_array_mini = F[:-1] stock_array_full = F a=0.25 elif stock_symbol == 'EBAY': stock_array_mini = EBAY[:-1] stock_array_full = EBAY a=0.35 elif stock_symbol == 'AMZN': stock_array_mini = AMZN[:-1] stock_array_full = AMZN a=0.9 elif stock_symbol == 'GOOGL': stock_array_mini = GOOGL[:-1] stock_array_full = GOOGL a=0.86 print ('the price of this stock in the beginning of last month was ${}'.format(stock_array_full[-1])) #smoothing technique smoothing_2=stock_array_full[0] smoothing_3=a*stock_array_full[1]+(1-a)*smoothing_2 smoothing_4=a*stock_array_full[2]+(1-a)*smoothing_3 smoothing_5=a*stock_array_full[3]+(1-a)*smoothing_4 smoothing_6=a*stock_array_full[4]+(1-a)*smoothing_5 smoothing_7=a*stock_array_full[5]+(1-a)*smoothing_6 smoothing_8=a*stock_array_full[6]+(1-a)*smoothing_7 x=len(stock_array_full) x_1=x*stock_array_full[-1] x_2 = (x-1) * stock_array_full[-2] x_3 = (x-2) * stock_array_full[-3] x_4 = (x-3) * stock_array_full[-4] x_5 = (x-4) * stock_array_full[-5] x_6 = (x-5) * stock_array_full[-6] x_7 = (x-6) * stock_array_full[-7] #moving averages masum=(x_1+x_2+x_3+x_4+x_5+x_6+x_7) madivide=(x)+(x-1)+(x-2)+(x-3)+(x-4)+(x-5)+(x-6) ma =masum/madivide # print("moving average is",ma) first_mean =float(sum(stock_array_mini)/max(len(stock_array_mini),1)) #z_score_algo first_var =[(num-first_mean)**2 for num in stock_array_mini] for num in first_var: var_sum=sum(first_var) mean_std= (var_sum/len(stock_array_mini)) final_std=mean_std**.5 z=(stock_array_mini[-1]-first_mean)/final_std mean2=float(sum(stock_array_full))/max(len(stock_array_full),1) secondvar =[(num-mean2)**2 for num in stock_array_full] for num in secondvar: var_sum2=sum(secondvar) mean_std2= (var_sum2/len(stock_array_full)) finalstd2=mean_std2**.5 final = (z * finalstd2) + mean2 #print_conditional if z < 1 or z>-1: print ("The stock price around the beginning of next month will be ${} ".format(round(final,2))) if final>stock_array_full[-1]: print("buy the stock") else: print("sell the stock") elif z < 2.2 or z>2.2: ze = (final + smoothing_8) / 2 if ze>stock_array_full[-1]: print("buy the stock") else: print("sell the stock") print ("The stock price around the beginning of next month would be ${} ".format(round(ze,2))) else: mae = (smoothing_8+ma)/2 if mae>stock_array_full[-1]: print("buy the stock") else: print("sell the stock") print ("The stock price around the beginning of next month would be ${} ".format(round(mae,2))) break x = input("which stock's price next month would you like this program to predict BAC, T, GE, F, TWTR, C, ORCL, JPM, PFE, BABA, AAPL, MSFT, INTC, F, EBAY, AMZN, GOOGL in single quotes") print ("{}".format((forecast_price(x)))) x = input("which stock's price next month would you like this program to predict BAC, T, GE, F, TWTR, C, ORCL, JPM, PFE, BABA, AAPL, MSFT, INTC, F, EBAY, AMZN, GOOGL in single quotes") print ("Stock price around the start of August will be ${}".format((forecast_price(x))))
Editor Settings
Theme
Key bindings
Full width
Lines