This code is a Streamlit application that performs the following...

April 19, 2024 at 07:41 AM

import streamlit as st import pandas as pd import yfinance as yf from datetime import datetime from datetime import timedelta import plotly.graph_objects as go from prophet import Prophet from prophet.plot import plot_plotly, plot_components_plotly import warnings import streamlit.components.v1 as components import time import plotly.figure_factory as ff import pytz from sklearn.metrics import mean_absolute_error # Suppress warnings warnings.filterwarnings('ignore') pd.options.display.float_format = '${:,.2f}'.format # Today's date today ='%Y-%m-%d') start_date = '2016-01-01' # Download Ethereum data tz = pytz.timezone('UTC') yf.pdr_override() eth_df ='ETH-USD', start_date, today) eth_df.reset_index(inplace=True) # Prepare dataframe for Prophet df = eth_df[["Date", "Open"]] df.rename(columns={"Date": "ds", "Open": "y"}, inplace=True) # Prophet model m = Prophet(seasonality_mode="multiplicative") future = m.make_future_dataframe(periods=365) forecast = m.predict(future) # Calculate MAE y_true = [3, -0.5, 2, 7] y_pred = [2.5, 0.0, 2, 8] mae_value = mean_absolute_error(y_true, y_pred) # Prophet plot fig = plot_plotly(m, forecast) # Add MAE annotation to the plot fig.add_annotation( x=forecast['ds'].iloc[-1], # x-coordinate of the annotation (last date in the forecast) y=forecast['yhat'].iloc[-1], # y-coordinate of the annotation (predicted value) text=f'MAE: {mae_value:.2f}', # Text to display (MAE value) showarrow=True, arrowhead=7, ax=0, ay=-40 ) # Streamlit sidebar menu rad ="Menu", ["History of Ethereum", "History of Ethereum with Candlesticks", "Ethereum Price Prediction", "Custom", "About Us"]) # Menu options if rad == "History of Ethereum": st.write("# History of Ethereum") st.write(go.Scatter(x=df["ds"], y=df["y"])) elif rad == "History of Ethereum with Candlesticks": st.write("# History of Ethereum with Candlesticks") fig2 = go.Figure(data=[go.Candlestick(x=eth_df['Date'], open=eth_df['Open'], high=eth_df['High'], low=eth_df['Low'], close=eth_df['Close'])]) st.plotly_chart(fig2) elif rad == "Ethereum Price Prediction": st.write("# Ethereum Price Prediction") st.write(fig) elif rad == "Custom": strdate = st.date_input("Enter Date") strdate = strdate.strftime('%Y-%m-%d') # Convert the input date to string format min_date = forecast['ds'].min().strftime('%Y-%m-%d') max_date = forecast['ds'].max().strftime('%Y-%m-%d') if min_date <= strdate <= max_date: prediction_date = forecast['ds'].dt.strftime('%Y-%m-%d') if strdate in prediction_date.values: index = prediction_date[prediction_date == strdate].index[0] st.write("## Ethereum Price on", forecast['ds'][index], "is", forecast['yhat'][index], "United States Dollar and", forecast['yhat'][index] * 76.1, "in Indian Rupee") else: st.write("No prediction available for the selected date.") else: st.write("Please select a date within the range of available predictions ({} to {}).".format(min_date, max_date)) else: st.success("Thank you for knowing about us") st.balloons() st.write("### We are Computer Science Undergraduates from Engineering College") # Footer footer = """ <style> a:link , a:visited { color: blue; background-color: transparent; text-decoration: underline; } a:hover, a:active { color: red; background-color: transparent; text-decoration: underline; } .footer { position: fixed; left: 0; bottom: 0; width: 100%; background-color: gray; color: white; text-align: center; } </style> <div class="footer"> <p>Developed with Streamlit by <br>SYV</p> </div> """ st.markdown(footer, unsafe_allow_html=True)

This code is a Streamlit application that performs the following tasks:

  1. Downloads historical Ethereum data using Yahoo Finance API.
  2. Prepares the data for Prophet time series forecasting model by selecting the "Date" and "Open" columns and renaming them.
  3. Fits a Prophet model to the data and generates a forecast for future time periods.
  4. Calculates the Mean Absolute Error (MAE) between two sets of values.
  5. Plots the Prophet forecast using Plotly.
  6. Adds an annotation to the plot displaying the MAE value.
  7. Creates a Streamlit sidebar menu with options for viewing the history of Ethereum, history with candlesticks, Ethereum price prediction, custom input, and an "About Us" section.
  8. Depending on the selected menu option, it displays different visualizations and information related to Ethereum data and price prediction.
  9. Includes a footer at the bottom of the Streamlit application with developer information.

Overall, this code creates an interactive web application using Streamlit that allows users to explore Ethereum historical data, view price predictions, and interact with the data through custom inputs.

Generate your own explanations
Download our vscode extension
Read other generated explanations

Built by @thebuilderjr
Sponsored by beam analytics
Read our terms and privacy policy
Forked from openai-quickstart-node