Generating prediction of the stock for a next business day

Predicting stock prices is a difficult task because it takes into account different technical indicators which are different mathematical calculations performed on stock parameters like volume, price, etc. We can use these indicators to identify different patterns that a stock follows but it is very difficult for a normal human being to understand these indicators and make a decision out of these.

Stocker is an open-source python library that can forecast the stock closing price of the next business day. You don’t have to understand or go through different technical indicators or news related to stocks, just need to pass the ticker of the stock and it will forecast the stock price for the next day. It also shows you the error rate.

Stocker uses LSTM in the backend to predict the prices and yahoo finance to fetch the data related to stocks.

In this article, we will use stocker to forecast stock prices and also learn about different functionalities of stocker.

Installing required libraries

We will start by installing stocker which will install all its dependencies. Like any other python library, we will install stocker using pip.

pip install stocker

Importing required libraries

We only need to import stocker and use its functionalities.

from stocker.predict import tomorrow

Forecasting stock prices

Now we will start predicting stock prices using stocker. We will also explore the importance of stock parameters on which the prediction is dependent.

1. Error Rate

In this, we will find out the error rate for the prediction.

stock = 'INFY.NS'
error1 = tomorrow(stock, years=1)[1]
error2 = tomorrow(stock, years=2)[1]
error3 = tomorrow(stock, years=3)[1]
print('Error by using 1 year of data:',error1,'%')
print('Error by using 2 years of data:',error2,'%')
print('Error by using 3 years of data:',error3,'%')
Error in Year Data Source
error1 = tomorrow(stock, steps=1)[1]
error2 = tomorrow(stock, steps=10)[1]
error3 = tomorrow(stock, steps=20)[1]
print('Error by using 1 previous day of data:',error1,'%')
print('Error by using 10 previous days of data:',error2,'%')
print('Error by using 20 previous days of data:',error3,'%')
Error in Daily Data

Importance of parameter

Here we will find out the importance of the stock parameters in finding out the stock prices.

from stocker.get_data import correlation
correlation(stock, interest=True, indicators=True)
Feature Importance

 Prediction

import stocker 
stocker.predict.tomorrow('INFY.NS')

Here we can clearly analyze the stock prediction for the next day along with the error rate. But you should always keep in mind that stock markets are highly volatile and investment should not be made without proper research and analysis.

In this article, we saw how easily we can predict stock prices without creating any LSTM, Deep Learning model because Stocker already has that in the backend and calls the LSTM model whenever we use the predict function. It is currently supported for only next business day prediction but can be tuned for generating predictions more than that.

Go ahead, try this with different stocks.

For more tutorials based on Python and Machine Learning visit us at Geekycodes.

Leave a Reply