Professional Documents
Culture Documents
Project Report Format (Repaired)
Project Report Format (Repaired)
Project Report Format (Repaired)
Deep Learning
A Report Submitted to the
BACHELOR OF TECHNOLOGY
In
COMPUTER SCIENCE AND ENGINEERING
By
Bharat Shubham
Amritansh Soni
Anish Sahay
Rishabh Jha
Under the supervision of
Asst. Prof. Rasmi Ranjan Khansama
DECLARATION …………………………………………………………………………………………ii
ACKNOWLEDGEMENTS...............................................................................................................iii
ABSTRACT .....................................................................................................................................iv
CONTENTS ……………………………………………………………………………………………..v
INTRODUCTION.............................................................................................................................1
LITRATURE SURVEY……………………………………………………………………………5
RESULT ANALYSIS……………………………………………………………………………….8
REFERENCES………………………………………………………………………………………15
CHAPTER 1
INTRODUCTION
Investment has become an integral part of our daily lives, and many people have become
accustomed to using their personal assets to generate more profit. In general, conservative
investors place their excess cash in banks, funds, or the stock market, and expect to obtain
returns on interest and dividends. In contrast, active investors prefer to use their funds to buy/sell
stocks, funds, futures, options, and so on, expecting to get higher returns. As a whole, since stock
investment can produce high profitability (although there is a risk), it is one of the most popular
investment activities. Although stock investment can bring high returns for investors, the stock
market is affected by macroeconomic and international factors, stock market volatility, as well as
governmental policies that combine to make it very difficult to achieve an assured level of
accurate stock prediction.
The main idea behind stock prediction is to analyze the available information from the stock
market in order to effectively predict future trends (stock prices), which can increase profit. The
first approach is aimed at analyzing the general economic situation, current industrial trends, and
other long-term factors. On the other hand, technical analysis focuses on the short-term stock
price (also called momentum) in the stock market.
Understanding Candlestick Charts
Candlesticks show that emotion by visually representing the size of price moves with different
colors. Traders use the candlesticks to make trading decisions based on regularly occurring
patterns that help forecast the short-term direction of the price.
A candlestick chart is a style of financial chart used to describe price movements of a security,
derivative, or currency. Each "candlestick" typically shows one day, thus a one-month chart may
show the 20 trading days as 20 candlesticks. Candlestick charts can also be built using intervals
shorter or longer than one day. It is similar to a bar chart in that each candlestick represents all
four important pieces of information for that day: open and close in the thick body; high and low
in the “candle wick”. Being densely packed with information, it tends to represent trading
patterns over short periods of time, often a few days or a few trading sessions.
FIGURE: 01
Candlestick chart of EUR/USD currency pair on daily timeframe in Meta-Trader 5 trading platform.
Candlestick charts are most often used in technical analysis of equity and currency price patterns.
They are visually similar to box plots, though box plots show different information.
Candlestick Components
Just like a bar chart, a daily candlestick shows the market's open, high, low, and close price for
the day. The candlestick has a wide part, which is called the "real body." This real body
represents the price range between the open and close of that day's trading. When the real body is
filled in or black, it means the close was lower than the open. If the real body is empty, it
means the close was higher than the open.
FIGURE: 02
Traders can alter these colors in their trading platform. For example, a down candle is often
shaded red instead of black, and up candles are often shaded green instead of white.
Description
The area between the open and the close is called the real body, price excursions above and
below the real body are shadows (also called wicks). Wicks illustrate the highest and lowest
traded prices of an asset during the time interval represented. The body illustrates the opening
and closing trades. The price range is the distance between the top of the upper shadow and the
bottom of the lower shadow moved through during the time frame of the candlestick. The range
is calculated by subtracting the low price from the high price.
If the asset closed higher than it opened, the body is hollow or unfilled, with the opening price at
the bottom of the body and the closing price at the top. If the asset closed lower than it opened,
the body is solid or filled, with the opening price at the top and the closing price at the bottom.
Thus, the color of the candle represents the price movement relative to the prior period's close
and the "fill" (solid or hollow) of the candle represents the price direction of the period in
isolation (solid for a higher open and lower close; hollow for a lower open and a higher close). A
black (or red) candle represents a price action with a lower closing price than the prior candle's
close. A white (or green) candle represents a higher closing price than the prior candle's close. In
practice, any color can be assigned to rising or falling price candles. A candlestick need not have
either a body or a wick. Generally, the longer the body of the candle, the more intense the
trading.
Candlesticks can also show the current price as they're forming, whether the price moved up or
down over the time phrase and the price range of the asset covered in that time. Rather than
using the open, high, low, and close values for a given time interval, candlesticks can also be
constructed using the open, high, low, and close of a specified volume. In modern charting
software, volume can be incorporated into candlestick charts by increasing or decreasing
candlesticks width according to the relative volume for a given time period.
Usage
Candlestick charts are a visual aid for decision making in stock, foreign exchange, commodity,
and option trading. Looking at a candlestick, one can identify an asset’s opening and closing
prices, highs and lows, and overall range for a specific time frame. Candlestick charts serve as a
cornerstone of technical analysis. For example, when the bar is white and high relative to other
time periods, it means buyers are very bullish. The opposite is true for a black bar. A candlestick
pattern is a particular sequence of candlesticks on a candlestick chart, which is mainly used to
identify trends.
CHAPTER 2
LITERATURE SURVEY
I. Predicting Stock Price Trend Using Candlestick Chart Blending
Technique
The author “Yoshihisa Udagawa” deals with a technical analysis for stock price
predictions using candlestick charts. The stock prices are apt to show no directional
movements when there is no significant news, resulting in generating a series of noisy
candlesticks. We propose a blending algorithm that combines candlesticks sharing
certain price ranges into one candlestick to eliminate the noisy candlesticks. The
paper discusses statistical measures on candlesticks to produce appropriate blended
candlestick charts for the prediction. The experimental results on the Nikkei-225
stock average show that the blended candlesticks are successful in offering
information for short-term stock price predictions. The performance of the proposed
algorithm is measured showing that it can blend daily candlesticks of 25 years within
two seconds.
Mostly in order to solve a complex problem, we stack some additional layers in the Deep Neural
Networks which results in improved accuracy and performance. The intuition behind adding more layers
is that these layers progressively learn more complex features. For example, in case of recognizing
images, the first layer may learn to detect edges, the second layer may learn to identify textures and
similarly the third layer can learn to detect objects and so on. But it has been found that there is a
maximum threshold for depth with the traditional Convolutional neural network model.
Residual Block
This problem of training very deep networks has been alleviated with the introduction of ResNet
or residual networks and these Resnets are made up from Residual Blocks.
ResNet Architecture
ResNet network uses a 34-layer plain network architecture inspired by VGG-19 in which then
the shortcut connection is added. These shortcut connections then convert the architecture into
the residual network as shown in the figure below:
Collecting the daily historical stock data for multiple stocks using the python library
nsepy.
Converting the data into Candlestick charts.
Labelling the Candlestick charts as having an “Up” or “Down” movement based on
percentage movement (of close price) in a particular direction.
Training a Deep Learning Model on the data.
Getting the areas of interest (based on the values of activations)and visualizing them
using heat maps.
nsepy
pandas
numpy
matplotlib
fastai
NSEpy
NSEpy is a library to extract historical and realtime data from NSE’s website. This Library aims
to keep the API very simple.
Python is a great tool for data analysis along with the scipy stack and the main objective of
NSEpy is to provide analysis ready data-series for use with scipy stack. NSEpy can seamlessly
integrate with Technical Analysis library (Acronymed TA-Lib, includes 200 indicators like
MACD, RSI). This library would serve as a basic building block for automatic/semi-automatic
algorithm trading systems or backtesting systems for Indian markets.
Pandas
Pandas is a software library written for the Python programming language for data
manipulation and analysis. In particular, it offers data structures and operations for manipulating
numerical tables and time series. It is free software released under the three-clause BSD
license. The name is derived from the term "panel data", an econometrics term for data sets
that include observations over multiple time periods for the same individuals. Its name is a play
on the phrase "Python data analysis" itself.
NumPy
NumPy is a Python library used for working with arrays. It also has functions for working in
domain of linear algebra, Fourier transform, and matrices.
In Python we have lists that serve the purpose of arrays, but they are slow to process. NumPy
aims to provide an array object that is up to 50x faster than traditional Python lists. The array
object in NumPy is called ndarray, it provides a lot of supporting functions that make working
with ndarray very easy. Arrays are very frequently used in data science, where speed and
resources are very important.
Matplotlib
Matplotlib is a collection of functions that make matplotlib work like MATLAB. Each pyplot
function makes some change to a figure: e.g., creates a figure, creates a plotting area in a figure,
plots some lines in a plotting area, decorates the plot with labels, etc.
In matplotlib various states are preserved across function calls, so that it keeps track of things
like the current figure and plotting area, and the plotting functions are directed to the current axes
(please note that "axes" here and in most places in the documentation refers to the axes part of a
figure and not the strict mathematical term for more than one axis).
Fastai
Fastai is a deep learning library which provides practitioners with high-level components that
can quickly and easily provide state-of-the-art results in standard deep learning domains, and
provides researchers with low-level components that can be mixed and matched to build new
approaches. It aims to do both things without substantial compromises in ease of use, flexibility,
or performance. This is possible thanks to a carefully layered architecture, which expresses
common underlying patterns of many deep learning and data processing techniques in terms of
decoupled abstractions. These abstractions can be expressed concisely and clearly by leveraging
the dynamism of the underlying Python language and the flexibility of the PyTorch library.
Fastai includes:
A new type dispatch system for Python along with a semantic type hierarchy for tensors
A GPU-optimized computer vision library which can be extended in pure Python
An optimizer which refactors out the common functionality of modern optimizers into
two basic pieces, allowing optimization algorithms to be implemented in 4-5 lines of
code
A novel 2-way callback system that can access any part of the data, model, or optimizer
and change it at any point during training
A new data block API
In this section we are completing the following steps:
Obtaining the historic stock data (for the past two years) using the “obtain_data”
function.
Determine whether a particular chart should be classified into “Up” or “Down” based on
movement in the upcoming five days.
Create a Candlestick chart for a time period of 20 days.
Save the Candlestick chart to the respective folder (Up/Down).
Now, we are setting up the data such that we can use it train a deep learning model. We are
completing the following tasks:
We trained a deep learning model (having an accuracy of nearly 62 % on a validation set) above.
A more detailed overview of what we did is as follows:
Used transfer learning to train a pre-trained neural network on our charts using an
appropriate learning rate.
Increased the size of our images (for the earlier training cycles it was 224 by 224 and
then we increased it to 352 by 352)
Used transfer learning again to train the previous network on the new larger images using
an appropriate learning rate.
Future Work
We will be creating heat maps highlighting areas which were of interest to the neural net
using the activations.
We will improve the accuracy by implementing it with different models like GoogleNet,
AccordNet and Microsoft Cognitive toolkit.
[1] Mr M.M Goswami, Prof C.K Bhensdadia, Prof A.P Ganatra “ Candlestick Analysis based
short term prediction of stock price Fluctuations using SOM - CBR “ Faculty of Technology,
D.D University- Nadiad
[2] Filip Martinsson and Ivan Liljeqvist “ Short Term Stock Market Prediction Based on
Candlestick Pattern Analysis. “ Skokan for Datavetenskap och Kommunikation.
[3] Razik Batliwala, Muddassir Khan “ Stock Market Prediction using Candlestick chart”
IT,Padhmbhusham vasantdada patil pratisthan’s college of Engineering, Sion Mumbai.
[4] - Kietikul Jearanaitanakij, “ Predicticting short trend of stock by using CNN and candlestick
pattern”- Faculty of Engineering, King Mongkut’s Institute of technology, Ladkrahang.