def index(): # Get Ethereum gas data gas_data = get_gas_data() print( f"Last Block: {gas_data['last_block']} | Safe Gas Price: {gas_data['safe_gas']} | Propose Gas Price: {gas_data['propose_gas']}" ) # Get Ethereum price data eth_data = get_eth_price() print(f"Ethereum Price: {eth_data['eth_usd']} | Time: {eth_data['time']}") # Get stock market price data for Vanguard Total Stock Market ETF (VTI) stock_data = get_stock_data("vti") print(f"{stock_data['ticker']}: {stock_data['price']}") # Get bond market price data for Vanguard Total Bond Market ETF (BND) bond_data = get_stock_data("bnd") print(f"{bond_data['ticker']}: {bond_data['price']}") # Render the index page template return render_template("index.html", meta=meta, gas=gas_data, eth_data=eth_data, stock_data=stock_data, bond_data=bond_data)
import functions as DLmodels n_steps_in, n_steps_out = 7, 1 interval = '1wk' samples_test = 1 all_MAPE = [] ML_Techniques = ['LSTM', 'BidirectionalLSTM', 'convLSTM1D', 'convLSTM2D'] for stock in cs.stocks_codigo[int(sys.argv[1]):int(sys.argv[1]) + len(cs.stocks_codigo)]: print(stock) (flag, symbol) = (True, stock) if flag: dataframe = DLmodels.get_stock_data(symbol, interval) dataframe = dataframe[[ 'Open', 'High', 'Low', 'Close', 'Volume', 'HighLoad', 'Change', 'Adj Close' ]] dataframe = DLmodels.clean_dataset(dataframe) scaler = StandardScaler() dataset = scaler.fit_transform(dataframe.ffill().values) scaler_filename = 'scalers/' + stock + '-' + interval + '.save' scaler = pickle.load(open(scaler_filename, 'rb')) dataset = scaler.fit_transform(dataframe.iloc[:, :].ffill().values) n_features = dataset.shape[1]
n_steps_in, n_steps_out = 50, 3 epochs = 1000 verbose=0 save = True update = True samples_test = 15 interval='1d' main_df, cor = DLmodels.get_correlation_stock_matrix(cs.stocks_codigo) datagrouped = DLmodels.data_grouped_foreign_stock(cs.foreign_stocks, interval) for stock in cs.stocks_codigo[int(sys.argv[1]):int(sys.argv[1]) + len(cs.stocks_codigo)]: print(stock) dataframe = DLmodels.get_stock_data(stock, interval) if len(dataframe) < 200: continue dataframe['Moving_av']= dataframe['Adj Close'].rolling(window=20,min_periods=0).mean() i=1 upper_volatility=[dataframe.iloc[0]['Moving_av']] lower_volatility=[dataframe.iloc[0]['Moving_av']] while i<len(dataframe): upper_volatility.append(dataframe.iloc[i-1]['Moving_av']+3/100*dataframe.iloc[i-1]['Moving_av']) lower_volatility.append(dataframe.iloc[i-1]['Moving_av']-3/100*dataframe.iloc[i-1]['Moving_av']) i+=1 dataframe['Upper_volatility']=upper_volatility dataframe['Lower_volatility']=lower_volatility
# App layout ################################################################################ # Sidebar st.sidebar.markdown( "Look up ticker symbols [here](https://finance.yahoo.com/lookup)") ticker_symbol = st.sidebar.text_input('Stock ticker symbol', value='AAPL') start_date = st.sidebar.date_input("Start day", datetime.date(2010, 8, 14)) end_date = st.sidebar.date_input("End day", datetime.date(2020, 8, 14)) # Main Window st.title("Stock Price Chart") # Function calls to get data and make image df_ticker = functions.get_stock_data(ticker_symbol, start_date, end_date) stock_prices = functions.prepare_data(df_ticker['Close']) fig = functions.make_picture(stock_prices, img=img, x_width_image=x_width_image, horizon_height=horizon_height) st.pyplot(fig=fig, bbox_inches='tight') time.sleep( 1) # workaound, see https://github.com/streamlit/streamlit/issues/1294 plt.close(fig) gc.collect() st.markdown( "Suggestions [welcome](https://github.com/dhaitz/stock-art). Image source: [mamunurpics](https://www.pexels.com/@mamunurpics). Inspired by [stoxart](https://www.stoxart.com)." )
samples_test = 15 interval = '1d' all_MAPE = [] ML_Techniques = ['LSTM', 'BidirectionalLSTM', 'convLSTM1D', 'convLSTM2D'] data_trend_pt_br = pd.read_csv('./logs/trends_pt-BR.csv') data_trend_en_us = pd.read_csv('./logs/trends_en-US.csv') geo_us = 'en_us' geo_br = 'pt-BR' for stock in cs.stocks_codigo[int(sys.argv[1]):int(sys.argv[1]) + len(cs.stocks_codigo)]: print(stock) df_target = DLmodels.get_stock_data(stock, interval) df_target['Moving_av'] = df_target['Adj Close'].rolling( window=20, min_periods=0).mean() i = 1 upper_volatility = [df_target.iloc[0]['Moving_av']] lower_volatility = [df_target.iloc[0]['Moving_av']] while i < len(df_target): upper_volatility.append(df_target.iloc[i - 1]['Moving_av'] + 3 / 100 * df_target.iloc[i - 1]['Moving_av']) lower_volatility.append(df_target.iloc[i - 1]['Moving_av'] - 3 / 100 * df_target.iloc[i - 1]['Moving_av']) i += 1 df_target['Upper_volatility'] = upper_volatility