Spaces:
Sleeping
Sleeping
| import yfinance as yf | |
| import datetime as datetime | |
| from datetime import date, timedelta | |
| import streamlit as st | |
| import plotly.graph_objects as go | |
| import joblib | |
| # from autots import AutoTS | |
| st.title('BTC AutoTS Price Prediction 📢') | |
| st.write('This is a bitcoin price prediction time series analysis using pretrained AutoTS model that took 10 minutes.') | |
| st.image('https://theounce.ca/wp-content/uploads/2021/02/Corinne-Doan-wallstreetbets-WSB-cannabis-2.jpg') | |
| # DATA IMPORT | |
| today = date.today() | |
| d1 = today.strftime("%Y-%m-%d") | |
| end_date = d1 | |
| d2 = date.today() - timedelta(days=1460) | |
| d2 = d2.strftime("%Y-%m-%d") | |
| start_date = d2 | |
| data = yf.download('BTC-USD', | |
| start=start_date, | |
| end=end_date, | |
| progress=False) | |
| data["Date"] = data.index | |
| data = data[["Date", "Open", "High", "Low", "Close", "Adj Close", "Volume"]] | |
| data.reset_index(drop=True, inplace=True) | |
| st.write("### Data of THE Last 4 Years") | |
| st.write(data) | |
| st.write("### BTC Price Chart") | |
| figure = go.Figure(data=[go.Candlestick(x=data["Date"], | |
| open=data["Open"], | |
| high=data["High"], | |
| low=data["Low"], | |
| close=data["Close"])]) | |
| figure.update_layout(xaxis_rangeslider_visible=False) | |
| figure.update_layout(xaxis_title='Date', yaxis_title='Close Price') | |
| st.plotly_chart(figure) | |
| st.write("### AutoTS Prediction") | |
| #model = AutoTS(forecast_length=30, frequency='infer', ensemble='simple').fit(data, date_col='Date', value_col='Close', id_col=None) | |
| #joblib.dump(model, 'autots_model.pkl') | |
| model = joblib.load('autots_model.pkl') | |
| prediction = model.predict() | |
| forecast = prediction.forecast | |
| fig = go.Figure() | |
| fig.add_trace(go.Scatter(x=data['Date'], y=data['Close'], mode='lines', name='Original')) | |
| fig.add_trace(go.Scatter(x=forecast.index, y=forecast['Close'], mode='lines', name='Forecast',line=dict(color='yellow'))) | |
| fig.update_layout(xaxis_title='Date', yaxis_title='Close Price') | |
| # Display the plot in Streamlit | |
| st.plotly_chart(fig) | |
| st.write("### Predicted Prices by Day") | |
| st.write(forecast) | |
| st.write('#### Looks like a fall is ahead of us! 😱') | |