Stock FAQs

dtw image pattern stock price time series cnn lstm python example github

by Bettye Franecki Published 2 years ago Updated 1 year ago

How to predict the future behavior of Petrobras stock prices using LSTM?

Python deep learning model with Keras Long Short-Term Memory (LSTM) to predict the future behavior of Petrobras stock prices. The purpose of this project was to get started forecasting time series with LSTM models.

How does it predict stock prices?

It combines features learned from different representations of the same data, namely, stock time series and stock chart images, to predict stock prices. Stock prediction is one of the most challenging and long standing problems in the field of time series data.

Why is stock pattern recognition not based on variation data?

This is because even the stock market is volatile, stock pattern recognition is based on the shapes of patterns. The recognition model only considers the shape of the pattern, therefore no matter the shapes from variation data or real data, they areallcanbeusedfortraining.

How many features are prepared for the DJIA time series?

In the CNNpred paper, 82 such features are prepared for the DJIA time series:

How many parts are there in the tutorial?

This tutorial is divided into 7 parts; they are:

What is the input data in a market index?

The input data has a date column and a name column to identify the ticker symbol for the market index . We can leave the date column as time index and remove the name column. The rest are all numerical.

Does the model above stop you from making prediction for k steps ahead?

While the model above is for next-step prediction, it does not stop you from making prediction for k steps ahead if you replace the target label to a different calculation. This may be an exercise for you.

Can you predict the direction of a time series?

Also some other technical indicators such as the moving average of different window size are useful too. If we put all these align together, we will have a table of data, which each time instance has multiple features, and the goal is still to predict the direction of one time series.

Can CNN be used for sequence prediction?

We have seen the examples on using CNN for sequence prediction. If we consider Dow Jones Industrial Average (DJIA) as an example, we may build a CNN with 1D convolution for prediction. This makes sense because a 1D convolution on a time series is roughly computing its moving average or using digital signal processing terms, applying a filter to the time series. It should provide some clues about the trend.

Does it work?

As in all prediction projects in the financial market, it is always unrealistic to expect a high accuracy. The training parameter in the code above can produce slightly more than 50% accuracy in the testing set. While the number of epochs and batch size are deliberately set smaller to save time, there should not be much room for improvement.

What does followed pictures show?

Followed pictures shows some generated images of trainning data.

Which dataset is the best for neural networks?

Download one of the neural network models provided in this page. The ones trained in the MSCoco dataset are the best ones, since they were also trained on objects.

Why use 2D images?

The reason for using 2D images is that images about the stock pricelike candlestick chart are more often used for stock investors and easier to understand. Compared with feeding with 1D vector, this approach almost does not need any preprocessing, and the model can feed with raw pixels.

Can 150 images cover all patterns?

It is obvious that those 150 images cannot cover all HAS patterns in the real-world, which leads to the overfittingproblem. AlthoughgeneratedvariationdatacannotcoverallrealHASpatterns and has some data that not included in real data, it has the ability to increase the covered area of training data.

1. Overview

In this project I use Keras Long Short-Term Memory (LSTM) Model to Predict Petrobras Stock Prices. LSTMs are very powerful in sequence prediction problems because they're able to store past information. This is important here because the previous price of a stock is crucial in predicting its future price.

2. Quick Start

Checkout a static version of the notebook with Jupyter NBViewer from the comfort of your web browser.

3. What is LSTM and how it works

Long Short-Term Memory (LSTM) networks are a type of recurrent neural network capable of learning order dependence in sequence prediction problems. LSTMs have feedback connections, which enables it to process entire sequences of data (e.g. time series).

4. Dataset

For this project I used the Yahoo Finance for the historical daily prices of Petrobras stocks.

5. Approach

PART 1: Data Handling -> Importing Data with Pandas, Cleaning Data, Data description.

Introduction

Forecasting stock prices plays an important role in setting a trading strategy or determining the appropriate timing for buying or selling a stock. In this project, we use a model, called feature fusion long short-term memory-convolutional neural network (LSTM-CNN) model.

Related Work

Stock prediction is one of the most challenging and long standing problems in the field of time series data. H.Q.Thang @hust used Gaussian Process Regression and Autoregressive Moving Average Model to predict Vietnam Stock Index Trend. N.V.Son @vbd used ARIMA and LSTM to predict some stock symbols like APPL (Apple), AMZN (Amazon).

Expected Results

Understand CNN, LSTM model and its application to time series forecasting problems.

Reference

1. H.Q.Thang. Vietnam Stock Index Trend Prediction using Gaussian Process Regression and Autoregressive Moving Average Model . Research and Development on Information and Communication Technology, HUST, 2018.

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 1 2 3 4 5 6 7 8 9