33
loading...
This website collects cookies to deliver better user experience
!pip install coinbase
api_key = 'xpto123'
api_secret = 'xpto123'
from coinbase.wallet.client import Client
client = Client(api_key, api_secret)
import datetime
def price_bitcoin_in_day(date_search):
return float((client.get_spot_price(currency_pair='BTC-BRL',
date=date_search)).amount)
import pandas as pd
#days = number of days searcheddef
data_bitcoin_price_in_days(days):
# The first surveyed date is today (December 5, 2020) date_search = datetime.date.today()
#price is the price in reais found.
price = price_bitcoin_in_day(date_search)
#creating the list with the first values
data = [{'day': date_search, 'price': price}]
# informing the number of days to be searched
for i in range(1, days):
print(i)
# Previous day's date
date_search = date_search - datetime.timedelta(days=1)
#Researching the price...
price = price_bitcoin_in_day(date_search)
#Added the new values searched and their dates to the list
data = data + [{'day' : date_search, 'price' : price}]
#returned the complete list
return data
dados = data_bitcoin_price_in_days(4015)
df_dados = pd.DataFrame(dados)
“Prophet is a procedure for forecasting time series data based on an additive model in which non-linear trends are adjusted with annual, weekly, and daily seasonality, in addition to the effects of holidays. Works best with time series with strong seasonal effects and multiple seasons of historical data. The prophet is robust for missing data and changes in trend, and usually handles outliers well. ”
!pip install fbprophet
import Prophet
df_dados.rename(columns = {'day':'ds', 'price':'y'}, inplace = True)
m = Prophet(changepoint_prior_scale=0.15, daily_seasonality=True)
m.fit(df_dados)
future = m.make_future_dataframe(periods=365)
future.tail()
forecast = m.predict(future)
forecast[['ds', 'yhat', 'yhat_lower', 'yhat_upper']].tail()
from fbprophet.plot import plot_plotly, plot_components_plotly
plot_plotly(m, forecast)