Pattern Recognition in Stock Data Kathryn Dover Harvey Mudd College
Total Page:16
File Type:pdf, Size:1020Kb
Claremont Colleges Scholarship @ Claremont HMC Senior Theses HMC Student Scholarship 2017 Pattern Recognition in Stock Data Kathryn Dover Harvey Mudd College Recommended Citation Dover, Kathryn, "Pattern Recognition in Stock Data" (2017). HMC Senior Theses. 105. https://scholarship.claremont.edu/hmc_theses/105 This Open Access Senior Thesis is brought to you for free and open access by the HMC Student Scholarship at Scholarship @ Claremont. It has been accepted for inclusion in HMC Senior Theses by an authorized administrator of Scholarship @ Claremont. For more information, please contact [email protected]. Pattern Recognition in Stock Data Kathryn Dover Weiqing Gu, Advisor Dagan Karp, Reader Department of Mathematics May, 2017 Copyright © 2017 Kathryn Dover. The author grants Harvey Mudd College and the Claremont Colleges Library the nonexclusive right to make this work available for noncommercial, educational purposes, provided that this copyright statement appears on the reproduced materials and notice is given that the copying is by permission of the author. To disseminate otherwise or to republish requires written permission from the author. Abstract Finding patterns in high dimensional data can be difficult because it cannot be easily visualized. Many different machine learning methods are able to fit this high dimensional data in order to predict and classify future data but there is typically a large expense on having the machine learn the fit for a certain part of the dataset. This thesis proposes a geometric way of defining different patterns in data that is invariant under size and rotation so it is not so dependent on the input data. Using a Gaussian Process, the pattern is found within stock market data and predictions are made from it. Contents Abstract iii Acknowledgments xi 1 Introduction 1 2 Background 3 2.1 Methods for Pattern Recognition in Stock Data . 3 2.2 Stock Patterns . 7 2.3 Proposed Change in Approach . 10 3 Approach: Geometric Definition of Patterns 11 3.1 The Standard W . 11 3.2 The Standard M . 12 3.3 The Standard Head and Shoulder . 13 4 Approach: Geometric Definition of Fuzzy Shapes 15 4.1 The Fuzzy W . 15 4.2 The Fuzzy M . 16 4.3 The Fuzzy Head and Shoulder . 17 5 Results: New Approach on Handling the Shapes 19 5.1 Change of Basis . 19 5.2 Flipping a Shape . 20 5.3 Symmetric Representation . 21 5.4 Fuzzy Symmetry . 21 5.5 Categorizing Shapes Using Slopes and Lengths . 22 5.6 Rough Predictions . 23 vi Contents 6 Implementation: Creating an Algorithm to Find Patterns 27 6.1 Gaussian Process . 27 6.2 Finding Local Extrema . 29 6.3 Creating Vectors Using End Points . 29 6.4 Storing Information for the Prediction . 29 6.5 Running the Algorithm on the Data . 29 7 Results: Running the Algorithm on Real Data 33 7.1 Results . 33 7.2 Predictions . 36 7.3 Potential Issues . 40 8 Conclusion 45 8.1 Future Work . 45 8.2 Closing Thoughts . 48 Bibliography 49 List of Figures 2.1 Linear hyperplane separating data points (Burges (1998)) . 4 2.2 A visualization of the -tube created by the loss function (Murphy (2012)) . 5 2.3 A simple feed-forward neural nework (Mihail (2016)) . 6 2.4 An example of a double-bottom pattern in stock volume data (Forex (2016)) . 8 2.5 An example of a double-top pattern in stock volume data (Forex (2016)) . 9 2.6 An example of a head and shoulder pattern in stock volume data (StockCharts (2016)) . 10 3.1 A visualization of how to construct a basis for a standard W shape using the maximum and minimum points . 12 3.2 A visualization of how to construct a basis for a standard M shape using the maximum and minimum points . 13 3.3 A visualization of how to construct a basis for a standard head and shoulder shape using maximum and minimum points . 14 5.1 Flipping a W shape into an M shape . 20 5.2 A standard W ........................... 21 5.3 Identifying a shape in the data and saving the following segment’s length and slope . 24 6.1 Various Gaussian Fits . 28 6.2 The original data (upper left), the fit of the data when the variance is 0.001 (upper right), the algorithm identifying the local extrema (lower left) and the W found by the algorithm (lower right) . 31 viii List of Figures 7.1 The original data (upper left), the fit of the data when the variance is 0.001 (upper right), the algorithm identifying the local extrema (lower left), the W found by the algorithm (lower right) . 34 7.2 The original data (upper left), the fit of the data when the variance is 4 (upper right), the algorithm identifying the local extrema (lower left), the W found by the algorithm (lower right) 35 7.3 A fit with variance = 0.001 where multiple Ws were found . 36 7.4 A fit with variance = 0.001 where multiple Ms were found . 36 7.5 A fit with variance = 0.001 where multiple head and shoulder shapes were found . 37 7.6 Both of these trials were given a variance of 4 but the GP defined two different fits with different local extrema which gave very different W patterns . 42 8.1 A scatterplot and parametric curve representation of the time, price and volume for Apple stock data . 47 8.2 The mean and standard deviation for each distribution found at every 10 points . 47 List of Tables 7.1 The expected lengths and slopes for each of the shapes as calculated by the algorithm . 37 7.2 The slopes and lengths calculated for the W shapes and how they compare to the expected values in Table 7.1 . 38 7.3 The slopes and lengths calculated for the M shapes and how they compare to the expected values in Table 7.1 . 39 7.4 The slopes and lengths calculated for the head and shoulders shapes and how they compare to the expected values in Table 7.1 . 39 7.5 The expected directional vectors calculated for each shape . 40 7.6 The directional vectors calculated for each W shape and how they compare to the expected values in Table 7.5. The mean of the differences is 0.502 with a standard deviation of 0.575 41 7.7 The directional vectors calculated for each M shape and how they compare to the expected values in Table 7.5. The mean of the differences is 0.393 with a standard deviation of 0.460 41 7.8 The directional vectors calculated for each head and shoulders shape and how they compare to the expected values in Table 7.5. The mean of the differences is 0.39 with a standard deviation of 0.370 . 42 Acknowledgments I would like to thank my advisor, Weiqing Gu, for helping me through this project and teaching me how to take a geometric perspective and put it into mathematical terms. I would also like to thank my second reader, Dagan Karp, for taking the time to offer advice and thoughts on this project. Finally, I’d like to thank my family and friends for all of their support throughout my time at Harvey Mudd. Chapter 1 Introduction When data is visually represented, an expert in the field can often identify and have knowledge about certain patterns in the data. The goal of this research is being able to apply specific expert knowledge in a field and have a computer program learn to identify these patterns within the data. This is a form of supervised learning and is different than other methods because the pattern definitions will be defined by geometry that is based on how the pattern looks to the expert. Therefore, the algorithm will be learning shapes rather than numbers. For a proof of concept, I will be looking at stock prices and finding certain patterns that have been identified and understood by experts in this field. In Chapter 2, I discuss the previous methods used to perform pattern recognition in stock data and the different stock patterns I will be trying to recognize. In Chapter 3, I will define the stock patterns in a geometric way and in Chapters 4 and 5, I will discuss how to apply these definitions in different ways and use them to find patterns in stock market data. Chapter 6 describes how the algorithm was implemented using a Gaussian Process. The results of this algorithm are in Chapter 7 and I discuss what my algorithm was able to find in different stock market data. Chapter 8 concludes with a reflection of my work and possible future work for my thesis. Chapter 2 Background Pattern recognition is the study within machine learning that is dedicated to finding different numerical methods to find patterns within a dataset. The ability to find patterns within data can also be used to classify data into different categories or predict behaviors on future datasets (Bishop (2006)). Because patterns can exist in many forms of data, pattern recognition has been used in to diagonose disorders with MRIs (Schiffmann and van der Knaap (2009)), classifying fingerprints (Kawagoe and Tojo (1984)) and facial recognition (Lawrence et al. (1997)). This section is a discussion on some of the current methods in pattern recognition, how it relates to understanding stock market data, and where the work in this paper builds upon the current field. 2.1 Methods for Pattern Recognition in Stock Data This section gives an overview of a few common methods used for pattern recognition in stock data and the mathematics behind them.