This repository uses recurrent neural networks to predict the price of any stock, currency or cryptocurrency ( any market that yahoo_fin library supports ) using keras library.
to use this repository, install required packages
- Python 3.6
- keras==2.2.4
- sklearn==0.20.2
- numpy==1.16.2
- pandas==0.23.4
- matplotlib==2.2.3
- yahoo_fin
using the following command:
pip3 install -r requirements.txt
Dataset is downloaded automatically using yahoo_fin package and stored in data
folder. click here for more information about different tickers.
from keras.layers import GRU, LSTM, CuDNNLSTM
from price_prediction import PricePrediction
ticker = "BTC-USD"
# init class, choose as much parameters as you want, check its docstring
p = PricePrediction("BTC-USD", epochs=1000, cell=LSTM, n_layers=3, units=256, loss="mae", optimizer="adam")
# train the model if not trained yet
p.train()
# predict the next price for BTC
print(f"The next predicted price for {ticker} is {p.predict()}$")
# decision to make ( sell/buy )
buy_sell = p.predict(classify=True)
print(f"you should {'sell' if buy_sell == 0 else 'buy'}.")
# print some metrics
print("Mean Absolute Error:", p.get_MAE())
print("Mean Squared Error:", p.get_MSE())
print(f"Accuracy: {p.get_accuracy()*100:.3f}%")
# plot actual prices vs predicted prices
p.plot_test_set()
The next predicted price for BTC-USD is 8011.0634765625$
you should buy.
Mean Absolute Error: 145.36850360261292
Mean Squared Error: 40611.868264624296
Accuracy: 63.655%
Training logs are stored in logs
folder that can be opened using tensorboard, as well as model weights in results
folder.
- Fine tune model parameters (
n_layers
, RNNcell
, number ofunits
, etc.) - Tune training parameters (
batch_size
,optimizer
, etc. ) - Try out different markets such as NFLX (Netflix), AAPL (Apple) by setting the
ticker
parameter