p2 - Stock Market Prediction System A Wavelet Based

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Appl. Math. Inf. Sci. 12, No.

3, 579-585 (2018) 579


Applied Mathematics & Information Sciences
An International Journal

http://dx.doi.org/10.18576/amis/120312

Stock Market Prediction System: A Wavelet based


Approach
S. Saravanan and S. Mala∗
Department of Management Studies, University College of Engineering, Anna University, BIT Campus, Tiruchirappalli, Tamil Nadu,
India.

Received: 8 Sep. 2017, Revised: 13 Mar. 2018, Accepted: 23 Mar. 2018


Published online: 1 May 2018

Abstract: This work concentrates on computational approach for predicting the interval (number of trading days), a significant feature
of stock market analysis using Haar Wavelet. A distinct model is proposed for predicting the high value of returns. The prime objective
is to understand the trends using Haar wavelet and use this information to determine the interval for future direction. This model used
85 securities closing price and validated 4355 trading days. The results reported at 200 recent trading days with an average accuracy of
45.88% on 85 securities over a period of 15 years.

Keywords: Haar wavelet, National Stock Exchange (NSE),Stock Market Prediction, Wavelet Transform (WT).

1 Introduction can become more crucial for the recent stock market
changes and increases the need for financial care of
The objective of this work is to capture trends and stock-market. The stock market usually improve
similarities in order to help investors understand the economical well-being of people. The financial market
current trading scenario, aiming the test of system typically generates large amount of fluctuating
data, which might be analyzed for developing a better
hypothesis,‘whether trading intervals have any significant
impact on stock market data’. Studies suggest that, the decision support system. To make a cutting edge on stock
stock analysis is still evolving, and these exist an market, the hidden information in stock-market data is
considered, which is largely untapped and to be identified.
opportunity for developing new evaluation technique and
use of various data mining methods, which involves Financial data including numbers and charts must be
interval based analysis to make inference about the analyzed for effective trading decisions, further assessing
current market. Wavelet function is increasingly applied the feasibility of stock market data analysis using wavelet
and specifically predicting the stock data based on trading
to these stock data sets because it permit experts to focus
on time scale where the trading patterns would be intervals. This work introduces wavelets as a technique
important. Wavelets can be very much useful for for stock prediction, the development and characterization
distinguish trading patterns from other price movements. of a method to assess repetitive stock patterns for
detecting basic stock characteristics from NSE data set.
This work presents an interval based stock market
analysis using Haar wavelet in NSE data set which can
identify significant informative financial characteristics.
This method can be opted as an alternative to analyze
financial data which involves the effective use of stock This paper first survey on the related work, introduce
market data and assist investors to make better decisions wavelets and describe the main stock market
based on intervals. characteristics. We then detail the stock processing
Since lesser models are present to predict the state of required to detect basic characteristics in stock market
stock market based on trading intervals, the efficient data and describe the extracted features and elaborate on
diagnosis of current stock market and its relationship with the experiment. Finally, discuss the results with future
various financial trades will be available. These models work.
∗ Corresponding author e-mail: [email protected]
c 2018 NSP
Natural Sciences Publishing Cor.
580 S. Saravanan, S. Mala: Stock market prediction system: a wavelet based...

2 Theoretical Background provides a continuous assessment of relationships or


structures, as well as other observations. The wavelet
Wavelets are applied in number of fields including analysis has the variety of algorithms. Depending on the
biomedical signals, medical images, aural signal and data-analysis different wavelet algorithm are applied. In
video-signal [1,2,3]. Despite the considerable research in PVI non-linear system, adaptive wavelet neural network
economics and finance, only limited researchers have is employed to inherit time-varying system characteristics
identified the application of wavelets in stock markets [4, [19].
5]. Wavelet analysis is a mathematical model very This work applies Haar-Wavelet (in close price for a
suitable for non-stationary data that transforms the time stock), which is very fast and works well for the financial
domain signal into a different domain for analysis and time series. Financial-time-series are non-stationary,
processing [6]. Haar wavelet are used in different cannot be described within a window by combination of
applications. This work makes use of haar wavelet since sin and cos terms. Financial time series cannot be cyclical
most of the financial time series data are non-stationary. in a predictable fashion. Financial-time- series lend
The economic applications of wavelets provide different themselves to Haar wavelet analysis since graphs of
insights into those application and report fruitful results. financial time series tend to jagged, without a lot of
Transformations are applied to signals which obtain smooth detail. The present work adopts CWT (for interval
further information which is not visible in the raw signal. analysis) & DWT (for noise removal) using Haar wavelet
Traditional method time-series analysis focuses on time as the mother-wavelet. By using CWT, from a very
domain which requires a very strong assumption that data complicated function the user can extract components
must be stationary and spectral analysis, which focuses on with a simpler structure. The user can study each small
frequency-domain makes sense when the market activity component instead of studying original function as the
is stable across the whole period [7]. whole. Main advantage of DWT is that it inherits the
A financial time series is a combination of same benefit of CWT but uses a limited number of
components that operate on different frequencies. Unlike translated and dilated versions of the original wavelet
traditional methods, wavelet Analysis, provide useful [20].
information to economics and finance that help to The stock market researchers have attempted to
overcome the limitations in traditional methods. U.S predict stock price using machine learning techniques and
stock price behavior are analyzed by various waveform statistical models. The problem of parameter selection
dictionaries to decompose the time series contained and over-fitting occurs in machine learning techniques
within three tick-by- tick foreign exchange rates [8,9]. [21,22]. The statistical models result in large error due to
The authors conclude that waveform dictionaries are most the assumption of time series data to be linear and
useful for analyzing data that are not stationary. Wavelets stationary. Use of continuous time transform, every
are used orthogonally to decompose the KOSPI and DJIA possible translation and scale-based decomposition
daily stock market indices into different respective models has been found to improve the accuracy of stock
time-scale components [10]. market prediction.
To quantify price spillovers among a wide range of
regional stock markets on different time horizons
wavelets are employed [11]. The relationship between 3 Empirical Tests
future output and a variety of financial indicators using
scale by scale based on wavelet multi resolution analysis 3.1 Sample Selection
[12]. Wavelets are used to study growth and volatility of
The data set for this work is collected from the historical
GDP series over different time horizons, where the focus
data on National Stock Exchange from the website of
is on changes in the growth rates as well as the levels of quandl
GDP[13].
https://www.quandl.com/data/XNSE-National-Stock-Exchange-of-India-Prices .
In the presence of wavelet analysis, the lead-lag
Quandl has the richest collection of publicly available
relationship between financial variables and real
stock market data on the Internet. Quandl is a platform for
economic activity and stock returns inflation on different economical, financial and other data, serving professional
time scales are studied [14,15]. Wavelet-based methods
investors. More than 2000 stock data from National Stock
are used to forecast foreign exchange rates [16]. To detect
Exchange of India is available in quandl. This work used
and separate periodic components in time series the DWT the daily closing price of more than 80 security index.
and Scalo gram are used in spectral analysis [17]. The
This data set involves an average of more than 3000
wavelets are applied to investigate the issue of market
trading days.
efficiency in the future markets for oil [18]. A
wavelet-based prediction procedure is introduced and
used to forecast market data for crude oil over different 3.2 Prediction Framework
forecasting horizons. The CWT avoids one particular
problem: in most of the literature from frequency domain, Prediction analysis is needed to provide the knowledge
cut-off frequency band is arbitrary for the analysis. CWT and guidance to investors in terms of when to buy, sell or

c 2018 NSP
Natural Sciences Publishing Cor.
Appl. Math. Inf. Sci. 12, No. 3, 579-585 (2018) / www.naturalspublishing.com/Journals.asp 581

hold the shares. This work attempts to design simple 3.3 Daily Returns From Closing Price
wavelet-based model for stock prediction in the future in
terms of interval based on trading days. Issues in data The input to processing chain is the closing price of stock
preprocessing technique, architectural design, wavelet market historical data for a particular security. In the first
selection and performance measures have been stage, the rate of returns from closing price are calculated
considered carefully. The methods were all implemented by the following formula depicted in (1). Returns from
off-line using MATLAB. The framework for stock Closing price quotes the ith return of an asset from the
prediction is illustrated in Fig. 1. The daily returns period T(i)to T(i+1) and normalizes it with time interval,
calculated from closing price are the significant input for which is 1 between successive price observations.
this processing chain. Firstly, the noise from returns are
removed by using Haar wavelet. The denoised-returns are
given as input to the next stage, where intervals for times(i + 1)
Return(i) = log (1)
positive stock market prediction is calculated using Haar (times(i + 1) − times(i))
wavelet. The results are further evaluated using confusion
matrix. The sample returns calculated using MATLAB for
NSE RCF security from March 1998 to June 2016 is
shown in Fig. 2.

Close Price NSE-RCF


150

Close Price
100

50

0
0 500 1000 1500 2000 2500 3000 3500 4000 4500 5000
Trading Days
Return NSE-RCF
0.4
Close Price returns

0.2

-0.2

-0.4
0 500 1000 1500 2000 2500 3000 3500 4000 4500 5000
Trading Days

Fig. 2: NSE RCF Closing Price and Returns

3.4 Noise Removal


Several stock market characteristics (peaks) are needed to
be preserved from the noise removal methods. The
steepness of stock market data edge needs to be retained
in order to differentiate between profit/loss characteristics
in stock. During diagnosis, return series are processed to
remove noise (also known as ‘market noise ’caused by
program trading) that tends to confuses or misrepresents
genuine trends. We have used wavelet transform based
noise removal and identified wavelet-based methods are
Fig. 1: Stock Market Prediction Framework suitable for visual inspection, Peak Signal to Noise Ratio
(PSNR) and Mean Square Error (MSE). The algorithm
used Haar Wavelet decomposition at level 1 on each
component for removing noise. The DWT using Haar as
mother wavelet has, Approximation Coefficients and
Detail Coefficients. The choice of mother wavelet

c 2018 NSP
Natural Sciences Publishing Cor.
582 S. Saravanan, S. Mala: Stock market prediction system: a wavelet based...

Table 1: PSNR, MSE for sample securities using Haar Wavelet.


SECURITY PSNR MSE
1 81.476 0.000463
2 77.504 0.001155
3 83.937 0.000263
4 79.928 0.000661
5 81.978 0.000412
6 80.221 0.000618
7 84.013 0.000258
8 81.185 0.000495
9 80.308 0.000606
Fig. 4: PSNR,MSE for 2 different securities with Intervals

becomes important in analyzing a given time series for


two reasons. Firstly, length of the discrete wavelet
function determines how well it would be able to isolate 3.5 Basic Stock Characteristic Detection
features to specific frequency intervals. Secondly, it is
being used to represent the hidden information contained
in time series.The Detail Coefficients indicate the short From the reconstructed returns, stock market prediction
bursts in the financial data which are more of impulsive intervals are detected. The corresponding
reactions to news and events [22].On the other hand,the positive/negative characteristics identified by the
Approximation Coefficients denote the average behavior detection algorithms are the basis for this work. Based on
of the indices during a long run and are considered for the proposed method results are evaluated for NSE RCF
determining the relationship of movement between stock data set. The profit/loss can be detected from the
indices. The reconstructed signals and the daily raw processed stock market returns. Intervals forming the
returns for security NSE RCF is shown in Fig. 3. The basis of all stock features are used for prediction.
PSNR for NSE RCF 79.447 and MSE for NSE RCF Robustness of the algorithm for detecting is a key to
0.00073847 are calculated after reconstruction, and this achieve good performance prediction. Profit detection is
shows that Haar wave function can be used for denoising particularly important because the entire stock market
daily stock market returns. Sample PSNR, MSE for some data are reliable. For the profit identification, we used
securities are listed in Table 1. Continuous wavelet transform Profit Detection
(CWTPD). The input to CWTPD are the denoised stock
market returns. CWTPD first computes the continuous 1D
wavelet coefficients at scale 10 using Haar as mother
0.25
NSE RCF Daily Returns
wavelet.
Let R be one of the return components and φ the
Daily Returns
0.2 Reconstructed Returns using haar@L1

0.15
mother wavelet. The wavelet coefficient Csp (R), at scale s
0.1
and position p, is defined as in (2).
Daily Returns

0.05

1 (t − p)
Z
R(t) p φ
-0.05
Csp (R) = dt. (2)
-0.1
(s) s
-0.15

-0.2
0 500 1000 1500 2000
Day
2500 3000 3500 4000
By application of specific threshold th pd on the
coefficients Csp = C10
p (R), CWT-PD creates a vector T
with elements Ti as in (3).
Fig. 3: NSE RCF: Raw Signal and Reconstructed Signal

1, ∀i : Ci (R) > th pd
Ti = (3)
0, otherwise.
The PSNR and MSE for 85 different securities are
analyzed before the detection of basic stock price This step divides returns into profit and non-profit
characteristics (profit/loss) analysis.The results obtained segments. Profit segments greater than the threshold are
for these securities shows the current trading intervals considered. CWT PD checks the return direction of each
playing the significant role in stock market prediction. 39 segment. The direction is derived from the sign of
out of 85 securities show the impact of current 200 corresponding element in T. The Fig. 5 illustrates raw
trading days. Fig. 4 list the highest values of returns (R) and Profit segments with application specific
PSNR(encircled) for 2 different sample securities. threshold 0.05.

c 2018 NSP
Natural Sciences Publishing Cor.
Appl. Math. Inf. Sci. 12, No. 3, 579-585 (2018) / www.naturalspublishing.com/Journals.asp 583

Table 2: Various security features with average intervals. Table 3: Confusion matrix(Actual Vs Calculated Results).
Security PSNR MSE Data Interval AvgPeakDist Actual Results TRUE FALSE TOTAL
1 81.476 0.000463 1-1400 42 Positive 1066(TP) 1134 (FP) 2200
2 77.504 0.001155 1-400 32 Negative 1071(TN) 1085(FN) 2156
3 83.937 0.000263 1-400 55 2137 2219
4 79.928 0.000661 1-200 23 Total (TP+FP+TN+FN) 4356
5 81.978 0.000412 1-200 49 Correct Predictions (TP+FN) 2151
6 80.221 0.000618 1-1600 26 Accuracy ((TP+FN)/Total) 49.38
7 84.013 0.000258 1-200 183
8 81.185 0.000495 1-1200 48
9 80.308 0.000606 1-2400 31 Table 4: Evaluation Results.
1 NumberOfObservations: 4356
2 ControlClasses: 2
3 CorrectRate: Accuracy 0.4938
4 ErrorRate: 0.5062
5 Sensitivity: 0.48455
6 Specificity: 0.50325
7 PositivePredictiveValue: 0.49883
8 NegativePredictiveValue: 0.48896

1 shows average peak distance for security NSE RCF is


44. This implies that an user may expect profit after 44
trading days for the security NSE RCF.

Peak Marker Vector for NSE RCF Returns (th=0.05) (Average Peak Distance =44)

Returns
0.1 Recons Haar Returns
peak Marker-vector

0.05

0
NSE RCF Returns

Fig. 5: Continuous Wavelet Transform - Profit Detection


(CWT PD) a) Raw Returns (NSE RCF) b) Transformed wavelet
with threshold.05 c) Marker vectors for profits -0.05

-0.1

3.6 Interval Analysis


-0.15

Various security features along with its data intervals and


50 100 150 200 250 300 350 400
average peak distance are listed in Table 2. To evaluate Trading Days

the CWT-PD algorithm, we performed an experiment


considering NSE RCF stock market data with more than
4000 trading days. Using a fixed sequence to simplify Fig. 6: NSE RCF Interval Analysis (AvgPeakDist 44)
labeling of individual profit, the sequence was comprised
of 0‘for non-profit segments and 1‘for profits. The
predictions are listed in Table 3. Comparing profits with
the annotated ground truth, we calculated true positives
(TP), true negative (TN), false positives (FP) and false 3.7 Results And Discussion
negatives (FN), to calculate the accuracy.
We have taken totally 4356 trading days of NSE RCF This work proposed a framework for stock prediction
for interval based analysis. By using the proposed method, using trading day intervals with 49.38% accuracy in the
2151 observations are predicted correctly. real data set. The objective of this work is to capture the
Table 4 suggests that trading day intervals can be used trends and similarities in the movements and activities of
to predict the future direction of stock market analysis. Fig. the Indian Stock Market NSE in order to help the

c 2018 NSP
Natural Sciences Publishing Cor.
584 S. Saravanan, S. Mala: Stock market prediction system: a wavelet based...

investors understand, the current trading scenario. Aiming [5] S. Skander, On the Use of the Wavelet Decomposition for
the test of hypothesis,‘whether trading intervals have any Time Series Prediction, Neurocomputing, Vol. 48(1-4),pp
significant impact on stock market data’. Considering the 267-277 (2002).
hypothesis that these would be an impact of trading [6] Y. Motohiro, Measure Business Cycle: A Wavelet Analysis of
intervals with respect to returns for desirable investments Economic Time Series, Economics Letter, vol. 100, pp. 208-
and profitability. The developed algorithm for detecting 212 (2008).
[7] Tian-Xiao He, Wavelet Analysis and Applications in
profit using trading intervals in stock market data has
Economics and Finance, Research & Reviews, Journal of
been proved achieving the accuracy of 49.38% for
Statistics and Mathematical Sciences, Vol. 1, no. 1, pp 22-37
NSE RCF data set. The experimental evaluation shows (2015).
sensitivity 48.45% and specificity 50.32% for NSE RCF [8] Ramsey,J. B., Usikov, D. and Zaslavsky, G. M, An Analysis
data set. The Interval analysis shows the number of of U. S. Stock Price Behavior Using Wavelets, Fractals, vol.
trading days for various securities have significant impact 3,no. 2, pp 377-389 (1995).
on stock market data. [9] Ramsey, J. B., and Semmler, W, Interest Rate Spreads
and Output: A Time Scale Decomposition Analysis Using
Wavelets, Computational Statistics and Data Analysis, Vol.
4 Conclusion 76, no. 2, pp 282-290 (2014).
[10] Lee, H. S, International Transmission of Stock Market
Application of Haar wavelet on stock market data was Movements: A Wavelet Analysis, Applied Economics
effectively implemented. The result indicates the Letters, Vol. 11, no. 3, pp. 197-201 (2004).
important relationship between stock market prediction [11] James. B. Ramsey, Wavelets in Economics and Finance:
and trading intervals which was one of the main Past and Future, Studies in Nonlinear Dynamics &
Econometrics, Vol. 6, no. 3, pp. 1-29 (2002).
objectives of this work. With increased frequency of stock
[12] Fernandez, V, The International CAPM and a Wavelet-
market data set we expect further testing on effectiveness Based Decomposition of Value at Risk, Studies in Nonlinear
of proposed work. We would like to extend our work Dynamics & Econometrics, Vol.9, no. 4, pp. 1-37 (2005).
further for on-line stock analysis. Trading intervals have [13] Maslova, I., Onder, H. and Sanghi, A, Growth and Volatility
provided new insight into stock market problem. The Analysis Using Wavelets, Policy Research Working Paper
most important idea of this work is the feasibility of stock 6578, The World Bank, (2014).
market prediction by trading intervals using wavelet. We [14] Kim, S. and In, F. H, The Relationship Between Stock
have used only a selected number of stock market data for Returns and Inflation: New Evidence from Wavelet Analysis,
the experimental scenario which can be considered Journal of Empirical Finance, Vol. 12, no. 3, pp. 435-444
further to on-line stock. (2005).
[15] Kim and In, F. H, The Relationship Between Financial
Variables and Real Economic Activity: Evidence From
Acknowledgement Spectral and Wavelet Analyses, Studies in Nonlinear
Dynamics & Econometrics, Vol. 7, no. 4, pp. 1-18 (2003).
[16] Wong, H., Ip, W., Xie, Z. and Lui, X, Modelling and
The authors are grateful to the anonymous referee for a
Forecasting by Wavelets, and the Application to Exchange
careful checking of the details and for helpful comments
Rates, Journal of Applied Statistics, Vol. 30, no. 5, pp. 537-
that improved this paper. 553 (2003).
[17] Arino, M. A., Morettin, P. A. and Vidakovic, B, Wavelet
Scalograms and Their Applications in Economic Time Series,
References Brazilian Journal of Probability and Statistics, Vol. 18, pp.37-
51 (2004).
[1] Seung-Min Park, Tae-Ju Lee and Kwee-Bo Sim, Heuristic [18] Yousefi, S., Weinreich, I. and Reinarz, D, Wavelet-Based
Feature Extraction Method for BCI with Harmony Search and Prediction of Oil Prices, Chaos, Solitons & Fractals, Vol. 25,
DiscreteWavelet Transform, International Journal of Control, no. 2, pp. 265-275 (2005).
Automation, and Systems, vol. 14, no. 6, pp. 1582-1587 [19] Lai, W. , Wavelet Theory and Its Applications in Economics
(2016). and Finance, PhD Thesis., University of Leicester, (2015).
[2] T. Sivalakshmi and G. Sreenivasulu, Comparative Analysis of [20] Hung-Yi Chen and Jin-Wei Liang, Adaptive Wavelet Neural
Different Wavelets for EEG Signal Denoising, International Network Controller for Active Suppression Control of a
Journal of Innovative Research in Science,Engineering and Diaphragm-Type Pneumatic Vibration Isolator, International
Technology, Vol. 6, No. 1,pp. 594-599 (2017). Journal of Control, Automation, and Systems, Vol. 15, no. 3,
[3] S. Mala and K. Latha, Electrooculography de-noising: pp. 1456-1465 (2017).
wavelet based approach to reduce noise, International Journal [21] Masset p, Analysis of Financial Time-Series Using Fourier
of Advanced Engineering Technology, Vol. 7,No. 2,pp. 482- and Wavelet Methods, University of Fribourg (Switzerland)-
487 (2016). Faculty of Economics and Social Science, (2008).
[4] Ramsey,J. B., and Anderson, H. M., U.S. and Canadian [22] Jothimani, D., Shankar, R and Yadav, S.S, Discrete Wavelet
industrial production indices as coupled oscillators, Journal Transform-Based Prediction of Stock Index: A Study on
of Economic Dynamics and Control, Vol. 26, pp. 33-67 National Stock Exchange Fifty Index, Journal of Financial
(2002). Management and Analysis, Vol. 28, no. 2, pp. 35-49 (2015).

c 2018 NSP
Natural Sciences Publishing Cor.
Appl. Math. Inf. Sci. 12, No. 3, 579-585 (2018) / www.naturalspublishing.com/Journals.asp 585

S. Saravanan is S. Mala pursuing


Head, Dept. of Management her Ph.D in Anna University,
Studies, Bharathidasan Chennai and awarded
Institute of Technology,Anna NIXI Fellowship for
University, Tiruchirappalli. Young Internet Professionals
He received his Ph.D. from National Internet
in Business Administration eXchange of India (NIXI) in
from Anna University, India. 2011. Her research interests
His area of specialization include Data Mining, Feature
is Finance and operations. He Selection, and Stock analysis.
has published research articles in reputed international
journals of finance and management. He has published 3
books.

c 2018 NSP
Natural Sciences Publishing Cor.

You might also like