-
Notifications
You must be signed in to change notification settings - Fork 0
/
Arima_bitcoin_price.py
42 lines (37 loc) · 1.17 KB
/
Arima_bitcoin_price.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# evaluate an ARIMA model using a walk-forward validation
from pandas import read_csv
from pandas import datetime
from matplotlib import pyplot
from statsmodels.tsa.arima.model import ARIMA
from sklearn.metrics import mean_squared_error
from math import sqrt
import pandas_datareader.data as pdr
#Load Bitcoin price from yahoo finance
end = datetime.today()
start = datetime(end.year-5,end.month,end.day)
BTC = pdr.DataReader('BTC-USD','yahoo',start,end)
#BTC.to_csv('BTC_USD.csv',index=False)
bt=BTC['Close'].resample('W').last()
# split into train and test sets
X = series.values
size = int(len(X) * 0.7)
train, test = X[0:size], X[size:len(X)]
history = [x for x in train]
predictions = list()
# walk-forward validation
for t in range(len(test)):
model = ARIMA(history, order=(5,1,0))
model_fit = model.fit()
output = model_fit.forecast()
yhat = output[0]
predictions.append(yhat)
obs = test[t]
history.append(obs)
print('predicted=%f, expected=%f' % (yhat, obs))
# evaluate forecasts
rmse = sqrt(mean_squared_error(test, predictions))
print('Test RMSE: %.3f' % rmse)
# plot forecasts against actual outcomes
pyplot.plot(test)
pyplot.plot(predictions, color='red')
pyplot.show()