Using Artificial Neural Networks To Forecast Financial Time Series

Pages 102
Views 7

Please download to get full document.

View again

of 102
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Description
Using Artificial Neural Networks To Forecast Financial Time Series Rune Aamodt Master of Science in Computer Science Submission date: June 2010 Supervisor: Arvid Holme, IDI Norwegian University of Science
Transcript
Using Artificial Neural Networks To Forecast Financial Time Series Rune Aamodt Master of Science in Computer Science Submission date: June 2010 Supervisor: Arvid Holme, IDI Norwegian University of Science and Technology Department of Computer and Information Science Problem Description The student will investigate how artificial neural networks can be trained to forecast developments of financial time series. He will first need to establish whether any similar research has been conducted previously, and if so to review the various approaches to the problem suggested therein. Following this prestudy, the student should decide on an approach and make the necessary implementations to train and test the neural networks. The attainable forecasting performance should be evaluated emprically. Simulations will be done using historical intraday trade data which has been procured for a selection of stocks from the Oslo Stock Exchange. Assignment given: 15. January 2010 Supervisor: Arvid Holme, IDI Abstract This thesis investigates the application of artificial neural networks (ANNs) for forecasting financial time series (e.g. stock prices). The theory of technical analysis dictates that there are repeating patterns that occur in the historic prices of stocks, and that identifying these patterns can be of help in forecasting future price developments. A system was therefore developed which contains several agents, each producing recommendations on the stock price based on some aspect of technical analysis theory. It was then tested if ANNs, using these recommendations as inputs, could be trained to forecast stock price fluctuations with some degree of precision and reliability. The predictions of the ANNs were evaluated by calculating the Pearson correlation between the predicted and actual price changes, and the hit rate (how often the predicted and the actual change had the same sign). Although somewhat mixed overall, the empirical results seem to indicate that at least some of the ANNs were able to learn enough useful features to have significant predictive power. Tests were performed with ANNs forecasting over different time frames, including intraday. The predictive performance was seen to decline on the shorter time scales. Contents 1 Introduction Motivation Krang Report Structure Financial Markets Financial Securities Background The Evolution of Financial Markets Algorithmic Trading Financial Time Series Candlestick Time Series The Efficient Market Hypothesis Trading Nomenclature The Bull And The Bear Long Or Short Technical Analysis Swing Points Trendlines Moving Averages Simple Moving Average Exponential Moving Average i CONTENTS ii Analysing The Moving Average Trend Reversal Patterns Head And Shoulders Pattern Double Top Pattern Double Bottom Pattern The Relative Strength Index Analysing The RSI Elliot Wave Theory Fibonacci Retracements Volume Artificial Neural Networks Biological Nervous Systems Neurons Adaptation Artificial Neural Networks Artificial Neurons Layer Architecture Training The ANN ANNs Applied To Financial Analysis Forex Forecasting With ANNs (Huang et. al.) Larsen: Automatic Stock Trading Based On Technical Analysis Using ANNs For Pattern Recognition In Financial Time Series The Krang System Introduction System Overview The Agents The ANN Training Parameters The Simulation Loop The Agents CONTENTS iii The SPSupportAgent The TrendLineAgent The MATrendAgent The MASupportAgent The RSILevelAgent The RSIDivergenceAgent The FibonacciAgent The VolumeAgent The DoubleTopAgent and DoubleBottomAgent Using Krang The Graphical Interface Configuration Simulation Data Simulations Simulation Data Test Plan Network Design Phase Empirical Test Phase Performance Evaluation Simulated Trading Statistical Analysis Results The 30-Minute Prediction ANN Network Architecture Empirical Results The 2-Hour Prediction ANN Network Architecture Empirical Results The 2-Day Prediction ANN Network Architecture Empirical Results The 1-Week Prediction ANN CONTENTS iv Network Architecture Empirical Results Discussion The 1-Week ANN The 2-Day ANN The 2-Hour ANN The 30-Minute ANN Overall Performance Conclusion Krang: Does It Work? Adverse Market Conditions Long Term Vs. Short Term The Problem Of ANN Design Reversal Patterns Index 93 Bibliography 95 CONTENTS v List of Figures 2.1 A trading pit in the Chicago Mercantile Exchange (CME) An example of a modern traders work desk Time series (line chart) for Google stock over the year 2009 (source: Yahoo! Finance[31]) Candlestick chart for Google stock over the first few months of 2009 (source: Yahoo! Finance[31]) The bull statue on Wall Street symbolizes a positive market sentiment Using swing points to identify support and resistance levels (source: StockCharts.com[20]) Example of a support trendline (source: StockCharts.com[20]) Comparison of several simple moving averages on the S&P 500 index curve (source: Yahoo! Finance[31]) Comparison of simple and exponential moving averages on the S&P 500 index curve (source: Yahoo! Finance[31]) Using a moving average for trend classification (source: StockCharts.com[20]) Using a moving average to find support and resistance levels (source: StockCharts.com[20]) Example of the head and shoulder reversal pattern (source: StockCharts.com[20]) Example of the double top reversal pattern (source: StockCharts.com[20]) Example of the double bottom reversal pattern (source: StockCharts.com[20]) 25 vii LIST OF FIGURES viii 3.10 Simple RSI analysis (source: StockCharts.com[20]) Divergence in the RSI and price chart (source: StockCharts.com[20]) The fractal structure of Elliot wave cycles [15, p.162] Fibonnaci retracement support levels Candlestick chart with volume and percentage volume oscillator (source: StockCharts.com[20]) The basic structure of neurons The symmetric sigmoid activation function (with k = 1) Example of an artificial neural network with layers Example of simple univariate ANN Process flow description for Krang simulations The three main windows in the Krang application The simulation data window, displaying a daily candlestick series (above) and the signals generated by a VolumeAgent (below) An example simulation configuration An example ANN configuration Scatter plots for two data series and the corresponding Pearson correlations Example of predictions from a 2-hour ANN Price chart of the JIN stock, Price chart of the DNBNOR stock, Price chart of the FRO stock, List of Tables 6.1 Overview of the 10 stocks which are used in the simulations Sampled predictions from the example ANN Results for the 30-minute ANN with NHY stock data Results for the 30-minute ANN with DNBNOR stock data Results for the 2-hour ANN with DNBNOR stock data Results for the 2-hour ANN with STB stock data Results for the 2-day ANN with DNBNOR stock data Results for the 2-day ANN with FRO stock data Results for the 1-week ANN with DNBNOR stock data Results for the 1-week ANN with JIN stock data ix Chapter 1 Introduction This chapter summarizes the basic motivation of this thesis and gives a brief overview of the contents in this report. 1.1 Motivation The main purpose of the work presented in this report is to investigate if and how artificial neural networks (ANNs) can be used to forecast financial time series (i.e. the price curve of financial securities). As we will see in chapter 4, several researchers have already performed similar investigations, however there are some novel features of the approach used in this thesis that separates it from the bulk of the existing research. Probably the most important of these differences is that the empirical tests in this thesis were performed with intraday trade data, whereas the previous research has generally been carried out with only daily data (i.e. one data value for each day). So while the existing research has been restricted to mid-term and long-term forecasting, this thesis is unique in that it also investigates the viability of applying ANNs to short-term intraday forecasting. Another major difference between this thesis and most other research is that the forecasting models tested here utilize heuristic methods inspired 1 CHAPTER 1. INTRODUCTION 2 by the discipline of technical chart analysis (chapter 3) in an effort to help the ANNs extrapolate relevant features of the data. The vast majority of the existing research is not based on any such method; simply applying the ANNs to raw price data seems to be the norm. This is discussed at greater length in chapter Krang The Krang system is an application that was developed to carry out the empirical studies in this thesis. Its functionality, which includes the creation, training and evaluation of forecasting ANNs with intraday stock price data, is described with great detail in chapter Report Structure This report can be seen as having three major parts: Chapters 2-4 summarize what was found during the prestudy phase of the thesis work. Chapters 5-6 describe the functionality of the Krang system, and exactly how it was used to generate the empirical results of this thesis. Chapters 7-9 list these results, along with some commentary/discussion leading up to the final conclusion. As for the contents of the prestudy, chapter 2 provides some background perspective on financial markets in general. Chapter 3 introduces some of the concepts of technical analysis, with emphasis on the parts that are relevant for the Krang system. Chapter 4 provides a brief introduction to what artificial neural networks are, and reviews some of the existing research where ANNs have been used to forecast financial markets. Chapter 2 Financial Markets Since this report assumes no prior knowledge of finance on the part of the reader, it seems appropriate to provide an overview of some of the basic theory. This chapter explains what financial markets are and how they work. Some key financial concepts are also explained which are relevant to the rest of this report. 2.1 Financial Securities A financial security, or financial asset, is basically a marketable contract that represents a claim on some present or future value. Broadly speaking, there are three types of securities:[28] Equity (i.e. stocks) denote part ownership of a business. Each share of stock typically grants the owner voting rights when stockholders vote on company decision. It also entitles the holder to any cash dividends the company might decide pay to its stockholders from their profits. Debt securities grant the holder rights to some future cash payments from the issuer of the contract. One example is government bonds, which are issued by governments when they need to borrow money. 3 CHAPTER 2. FINANCIAL MARKETS 4 Derivatives are contracts whose present value is tied to the future value of some other underlying asset. A common example of such a contract is the stock option. This contract pays a sum of money on a given date based on how much the price of a stock is above or below a given level on that date. 2.2 Background Now that we have a basic understanding of what financial securities are, we can consider the context in which they are bought and sold. In particular, some perspective may be gained from considering how these financial markets are organized and how they came to be that way. We will also explain the practice of algorithmic trading, where computers programs themselves become autonomous market participants The Evolution of Financial Markets The earliest known trading of financial securities dates back to several thousand years B.C. when Sumerians would organize auctions for primitive commodity futures contracts made out of clay (a futures contract is a type of derivative that would allow the issuing farmer to secure a price for the future sale of his crops ahead of harvest). [11][26] In the western world, financial markets have undergone a tremendous evolution over the past few centuries. The worlds first official stock exchange was opened in Amsterdam in 1602[24], and by the middle of the 19th century there were a large number of exchanges operating all over the western world. The existence of stock exchanges were vital to the industrial growth of the world during the 18th and 19th centuries, as they provided companies with a pool of capital to which they could sell their own shares in order to fund business expansion.[27] Until the 1960s, stock exchanges (and financial markets in general) were organized as physical locations where brokers would meet and exchange buy/sell orders in an open outcry auction. But with the advent of digital CHAPTER 2. FINANCIAL MARKETS 5 communication technology, trading quickly became more and more computer driven, which allowed traders in remote locations to send their orders electronically to the exchange. Traditional auction trading still takes place in various locations, as can be seen in fig This is a photo from a trading pit in Chicago where traders still trade commodity futures contracts in person. In todays world, however, the vast majority of financial trading is purely electronical. The work environment of a modern day trader is more likely to look something like fig One of the largest stock exchanges in the world, the NASDAQ, is managed completely electronically.[2, p.5] The same is true for the Norwegian stock exchange, the Oslo Stock Exchange (OSE), which closed down its physical stock trading pits in 1999 when it switched to an all-electronic system.[14] Financial markets exist for all the previously mentioned types of financial securities: stocks, bonds and derivatives. In addition to these, there is also the FX in which currencies are traded. The FX are generally the most liquid financial markets in the world, totaling more than 4 trillion USD in trading volume on an average day.[7] CHAPTER 2. FINANCIAL MARKETS 6 Figure 2.1: A trading pit in the Chicago Mercantile Exchange (CME) CHAPTER 2. FINANCIAL MARKETS 7 Figure 2.2: An example of a modern traders work desk CHAPTER 2. FINANCIAL MARKETS Algorithmic Trading As the financial markets became increasingly tech driven, several investors and institutions realized that there was a potential for automatic computerized trading systems which could trade securities without human input, so called algorithmic trading systems. The earliest such systems would only try to scalp small profits by looking for arbitrage opportunities (an arbitrage opportunity occurs when something can be bought and sold at a profit instantaneouly). Consider for example three FX markets: USD/GBP, GBP/EUR and USD/EUR. Situations could occur where these currency pairs were being traded with a small disrepancy so that buying a dollar in pounds, selling the dollar in euros and buying back pounds with the resulting euros would result in a small (yet immediate) profit. Such opportunities soon became scarce as more and more algorithmic systems started competing to find them, driving tech savvy investors to look for more creative approaches to algorithmic trading. As computer technology became more and more pervasive, the algorithmic trading systems also became more sophisticated. By the late 1980s complex automated trading systems were already a common occurence in the US markets, especially for rich institutions and hedge funds. When the worlds stock markets fell by record amounts on October 19, 1987 ( Black Monday ), many blamed automated trading systems for exacerbating the decline as they supposedly started blindly selling stocks.[25] Whether these allegations are true remains speculation to this day, however the mere fact that they were concieved does indicate that such systems were already common at that time. The Black Monday incident is not the only event with which algorithmic trading has been painted a villain. So called high frequency trading (HFT) systems, which are a special class of algorithmic trading systems, have recently been accused of manipulating markets and having unfair advantages over common investors. Some sources estimate that HFT systems presently account for over 70% of stock trading volume in the U.S.[3] These systems can make hundreds of thousands of quick trades every day, scalping small CHAPTER 2. FINANCIAL MARKETS 9 profits of short term movements in the prices of securities. From a research perspective, the main problem with these systems is that although they are clearly being used pervasively by certain institutions, the specific details of how they are implemented and their actual profitability when deployed in practice has never been published for the scientific community at large. As we shall see in chapter 4, some (public) research has been conducted in applying various machine learning techniques into financial trading, but the literature is scarce and the approaches that are tested are often somewhat simplistic (compared to what you might expect an investment firm to develop proprietarily). 2.3 Financial Time Series In general, a time series refers to a series of data points which are measured at successive points in time spaced at uniform time intervals. This concept is heavily used in scientific fields like statistics and signal processing, but also in the context of financial analysis.[29] The price that a particular security is traded at can be viewed as a time series, where the value at a given point in time is the price of the last observed trade at that time. In essence, the time series is then just a simple price curve for the security. An example is given in fig. 2.3 where the time series for Google stock is plotted spanning the year In this particular plot, the sampling interval is once per day, and so each value in the plot is the last traded price (or closing price) of that day Candlestick Time Series One drawback of the time series as it was just defined is that it may give an incomplete picture of the volatility in the price of the underlying security. This is because each point on the curve only displays a single price value, and says nothing about whether the price fluctuated in that interval or not. To get a more complete sense of the price movements for the security in each time interval, we might instead choose to use the so-called candlestick series. CHAPTER 2. FINANCIAL MARKETS 10 Figure 2.3: Time series (line chart) for Google stock over the year 2009 (source: Yahoo! Finance[31]) An example of a candlestick series is given in fig Here we see that instead of just singular values, each point in the series is represented by a colored bar and line. Each of these items is what we call a candlestick, or just candle for short. The graphical features of a candlestick can be interpreted as follows: ˆ The thick rectangular bar stretches from the price of the first trade in the candle (the open) to the price of the last trade (the close). ˆ The thin spine of the candle stretches from the highest price of any trade in the candle (the high) to the lowest price (the low). ˆ A green colored candle means that the closing price was higher than the open (i.e. the stock price went up in the time period represented by the candle). A red colored candle means the opposite (i.e. the price went down). ˆ If no trades occured during the time period of the candle, it is simply displayed as a flat line at the same level as the close of the previous candle. CHAPTER 2. FINANCIAL MARKETS 11 Figure 2.4: Candlestick chart for Google stock over the first few months of 2009 (source: Yahoo! Finance[31]) 2.4 The Efficient Market Hypothesis The efficient market hypothesis (EMH) is a theory which states that all information about a security is already taken into account by its market price. The main consequence of this is that it should be impossible to outsmart the overall market. The theory is based on the assumption that all relevant information is publicly available and easily accessible to all investors, and that investors act rationally. If these assumptions hold, competition among investors should spontaneously and immediat
Advertisements
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks
SAVE OUR EARTH

We need your sign to support Project to invent "SMART AND CONTROLLABLE REFLECTIVE BALLOONS" to cover the Sun and Save Our Earth.

More details...

Sign Now!

We are very appreciated for your Prompt Action!

x