Tez No İndirme Tez Künye Durumu
538638
Derin öğrenme yöntemleri ile zaman serisi tahmini / Time series classification with deep learning methods
Yazar:HAKAN GÜNDÜZ
Danışman: PROF. DR. ZEHRA ÇATALTEPE
Yer Bilgisi: İstanbul Teknik Üniversitesi / Fen Bilimleri Enstitüsü / Bilgisayar Mühendisliği Ana Bilim Dalı / Bilgisayar Mühendisliği Bilim Dalı
Konu:Bilgisayar Mühendisliği Bilimleri-Bilgisayar ve Kontrol = Computer Engineering and Computer Science and Control
Dizin:Ekonomik zaman serisi = Economic time series ; Makine öğrenmesi yöntemleri = Machine learning methods ; Yapay sinir ağları = Artificial neural networks ; Örüntü tanıma = Pattern recognition
Onaylandı
Doktora
Türkçe
2019
142 s.
Borsa piyasalarındaki yatırımcılar karlarını yükseltmek için piyasa davranışını en doğru şekilde tahmin etmeyi amaçlamaktadır. Hisse senedi fiyatının veya yönünün tahmini, borsa piyasalarının karmaşık, doğrusal olmayan ve dinamik doğaları nedeniyle zorlu bir iştir. Finans alanında kabul gören Rastgele Yürüyüş Teorisi, hisse senedi fiyatlarının rastgele tanımlandığını ve dolayısıyla tahmin edilemeyeceğini öne sürmektedir. Ancak yapay zeka alanındaki gelişmeler ve dijital veri miktarının hızla büyümesi, hisse senedi davranışlarının rastgele bir işlemden daha iyi performansla tahmininin önünü açmıştır. Finansal tahmin çalışmalarında yaygın olarak Yapay Sinir Ağları ve Destek Vektör Makineleri yöntemleri kullanılırken; İstatistiksel yöntemler, Rastgele Ormanlar, Doğrusal Ayrışım Analizi, Lojistik Regresyon ve Evrimsel Hesaplama tahminlemede kullanılan diğer yöntemlerdir. Bahsedilen bu yöntemlerde giriş verisi olarak ham verilerden hesaplanan el yapımı öznitelikler kullanılır. Ham verilerden el yapımı özniteliklerin oluşturulması iş gücü ve alan uzmanlığı gerektiren bir süreçtir. Genişleyen öznitelik uzayının boyutunu indirgemek için öznitelik seçim yöntemlerinden yararlanılırken; zaman serisi verisi gibi doğrusal olmayan ve gürültüye sahip verilerde uygun seçim yönteminin bulunması zorlu olmaktadır. Öznitelik oluşturma ve seçim sürecindeki işgücünü azaltmak için farklı bir yaklaşım olan Derin Öğrenme son yılların aktif araştırma konularından biridir. Derin Öğrenme (DÖ), veriden otomatik olarak öznitelikler çıkaran ve çıkarılan bu öznitelikleri doğrudan tahmin sürecinde kullanan bir sınıflandırma çatısı olarak düşünülebilir. DÖ yöntemleriyle ham verilerden veya daha basit özniteliklerden yararlı karmaşık öznitelik temsilleri elde edilir. Finansal piyasaların tahmininde çoğunlukla kullanılan DÖ modelleri Uzun Kısa Süreli Bellek (UKSB) ve Evrişimsel Sinir Ağlarıdır (ESA). Çalışmada ağırlıklı olarak bu iki DÖ modeli hisselerin saatlik yönünün tahmininde kullanılmıştır. Tez çalışmanın ilk aşamasında, Borsa İstanbul'daki üç farklı hissenin günlük hareketleri farklı teknik göstergeler kullanılarak tahmin edilmiştir. Deneyler, farklı öznitelik kümeleri (bireysel hisse, Dolar-Altın (DA), BIST100 tüm hisse öznitelikleri ve BIST100+DA) ile gerçekleştirilmiştir. Öznitelik uzayının boyutu 5860'ya kadar yükseldiğinden ilintili öznitelikler Kazanç Oranı ve Relief yöntemleriyle seçilmiştir. Elde edilen öznitelikler ile Gradyan Arttırıcı Makineler (GAM) ve Lojistik Regresyon (LR) sınıflandırıcıları eğitilmiş, performans değerlendirmesi ise Doğruluk ve Makro Ortalama F-Ölçütü metrikleriyle yapılmıştır. GAM sınıflandırıcısı-Kazanç Oranı seçimiyle GARAN hissesi için tüm öznitelik seçim-sınıflandırıcı kombinasyonlarından daha yüksek Doğruluk oranına (0,599) ulaşılmıştır. THYAO'nun hareketleri, Relief seçimi-GAM sınıflandırıcı çifti kullanılarak 0,558'lik Doğruluk oranıyla başarılı bir şekilde tahmin edilmiştir. ISCTR tahmininde, Kazanç Oranı seçimine sahip LR sınıflandırıcısı, 0,581'lik bir Doğruluk oranı elde etmiştir. Sınıflandırma sonuçları incelendiğinde, öznitelik seçiminin, seçim yapılmadan elde edilen sonuçlara göre sınıflandırma sonuçlarını iyileştirdiği görülmüştür. BIST100 hisse özniteliklerinin tahminlerde kullanılmasının, tüm hisseler için sınıflandırma performansını doğruluk oranı açısından arttırmıştır. Çalışmanın ikinci aşamasında BIST 100'de yer alan tüm hisselerin saatlik hareket yönleri derin öğrenme modelleriyle tahmin edilmiştir. İlk deneyler sadece fiyat öznitelikleriyle (teknik göstergeler ve zamansal öznitelikler) yapılırken; her saate ait öznitelik vektörleri geçmiş 80 saate ait öznitelik vektörlerini içerecek şekilde 2 boyutlu (2B) biçime dönüştürülmüştür. ESA mimarisi öznitelikler arasındaki yerel örüntüleri çıkarırken öznitelikler arasındaki uzamsal ilişkileri dikkate aldığından giriş verisindeki özniteliklerinin sırası öznitelikler arasındaki korelasyonlar dikkate alınarak yeniden düzenlenmiştir. ESA sınıflandırıcısına fiyat öznitelikleri korelasyona göre düzenlenmiş ve rastgele sıralı olarak verilmiş ve 2 farklı deney kurulumu yapılmıştır. Rastgele sıralanmış öznitelikler (ESA-Rast) ile 100 hisse için ortalama 0,545 MO F-Ölçütü oranı yakalanırken, sıralanmış özniteliklerle (ESA-Kor) bu oran yaklaşık %2 artarak 0,565'e çıkmıştır. Alınan sonuçlar öznitelik seçimli ve öznitelik seçimsiz LR sınıflandırıcısı ile karşılaştırılmıştır. Tüm BIST 100 hisselerinin ortak öznitelik alt kümesini bulmada Ki-kare öznitelik seçimi kullanılırken; ortak öznitelikler belirlendikten sonra her bir hisse için ayrı LR sınıflandırıcısı eğitilmiştir. ESA-Rast eğitilen LR sınıflandırıcılarıyla neredeyse aynı MO F-Ölçütü oranına (0,545) sahipken; ESA-Kor öznitelik seçimli ve seçimsiz LR'den daha yüksek performans göstermiştir. Her bir sınıflandırıcının göreceli MO F-Ölçütü skorlarının incelenmesinden sonra, ESA-Kor'un diğer üç sınıflandırıcıya göre daha yüksek göreceli MO F-Ölçütü değerleri elde ettiği görülmüştür. ESA-Kor, 100 hisse senedinin 54'ünde en iyi MO F-Ölçütü skorlarıyla lider sınıflandırıcı olmuştur. ESA mimarisiyle sonuçlar alındıktan sonra diğer bir derin öğrenme mimarisi olan UKSB ağıyla deneyler yapılmıştır. UKSB ağı bulunulan zaman adımı için tahmin yaparken geçmiş zaman adımlarındaki örneklerin etkisini de göz önünde bulundurur ve dizideki her zaman adımı için bir çıktı vektörü üretir. UKSB ile yapılan deneylerde ilk olarak dizideki son zaman adımının çıkış vektörü (öznitelik temsili) tüm dizinin temsili olarak alınmıştır. İkinci olarak son zaman adımının çıktı vektörünü kullanmak yerine, tüm adımların çıktı vektörleri kullanılmıştır. Böylece UKSB hangi zaman adımlarının önemli olduğunu dikkat mekanizmasıyla seçmiştir. 100 hisse için fiyat öznitelikleri ile yapılan UKSB sınıflandırmalarında son zaman adımından elde edilen öznitelik temsilleriyle (Fiyat-Son modeli) 0,560'lık ortalama MO F-Ölçütü oranına ulaşılırken; tüm zaman adımlarından elde edilen temsillerle (Fiyat-Tüm modeli) bu oran 0,576'ya kadar yükselmiştir. UKSB ağıyla ikinci deneyler haber verileri kullanılarak yapılmıştır. Haber veri kümesinde yer alan yaklaşık 457000 haber metni ilk aşamada ön işlemeye tabi tutulmuş ve her bir kelime için word2vec aracı ile kelime temsilleri oluşturulmuştur. Haber metinlerinde geçen kelimelerin temsil vektörlerinin ortalaması alınarak haber metinleri 300 boyutluk yoğun vektörlere dönüştürülmüştür. Kelime temsili vektörleriyle ifade edilen haber metinleri en son aşamada yayımlanma tarihlerine göre ilk önce saatlik zaman dilimlerine daha sonra 5'er dakikalık periyotlara ayrılmıştır. 5 dakikalık zaman diliminde yer alan haber vektörlerinin ortalaması alınarak her saat dilimi 12x300'lük matrislerle ifade edilmiştir. Elde edilen haber öznitelikleri ile fiyat verisinde olduğu gibi iki farklı UKSB ağı eğitilmiştir. İlk UKSB ağında son zaman adımından elde edilen temsillerle 0,530'luk ortalama MO F-Ölçütüne ulaşılırken, ikinci ağ mimarisinde tüm zaman adımlarından elde edilen temsiller kullanılarak 0,520'lik MO F-Ölçütü oranı bulunmuştur. Haber verilerinden elde edilen kelime temsilleri yapısı gereği haberlerdeki finansal duyguları doğrudan çıkaramamaktadır. Bu durumu gidermek için Loughran ve McDonald tarafından hazırlanan finansal duygu sözlüğünden ve ön-eğitilmiş Fasttext kelime temsillerinden yararlanılmıştır. Türkçe'ye çevrilen finansal duygu kelimelerinin ilk aşamada Fasttext temsili vektörleri bulunmuş ve vektörlere hiyerarşik kümeleme uygulanmıştır. Oluşan 314 kümenin her biri küme ortancası kelimelerle temsil edilmiştir. İkinci aşamada haber metinlerinde geçen kelimelerin Fasttext vektörlerinin ortalaması alınarak haber metinleri yoğun vektörlere dönüştürülmüştür. En son aşamada ise haber vektörleri duygu kümeleri cinsinden ifade edilmiştir. Bunun için haber vektörleriyle duygu kümelerinin ortanca kelimeleri arasındaki benzerliğe bakılmış ve her haber metni 314 boyutlu vektörlerle temsil edilmiştir. Haber öznitelikleriyle yapılan önceki deneyde olduğu gibi haber metinleri önce saatlik zaman dilimine daha sonra ise 5'er dakikalık periyotlara ayrılmıştır. Böylece her saat dilimi 12x314 boyutlu matrislerle ifade edilmiştir. Elde edilen özniteliklerle yine iki UKSB ağı eğitilirken en yüksek ortalama MO F-Ölçütü oranına (0,543) son zaman adımından elde edilen temsillerle ulaşılmıştır. İlk kullanılan haber özniteliklerine kıyasla duygu sözlüğü ve eğitilmiş hazır temsillerin kullanımı sınıflandırma sonucunu yaklaşık %1,5 oranında arttırmıştır. Fiyat ve haber verileriyle ayrı deneyler yapıldıktan sonra iki veri türü birleştirilmiştir. Öznitelik düzeyinde birleştirmede haber ve fiyat öznitelikleri doğrudan birleştirilerek UKSB ağına verilmiştir. Model düzeyinde birleştirmede ise haber ve fiyat öznitelikleri farklı UKSB ağlarına giriş olarak verilmiş ve bu ağların çıktıları iki farklı yöntemle birleştirilmiştir. Gerek öznitelik düzeyinde gerekse model düzeyinde birleştirmeyle alınan sonuçlar sadece fiyat özniteliğiyle elde edilen sonuçları geçememiştir. UKSB ağıyla (Fiyat-Tüm) alınan sonuçlar en son aşamada Ridge Regresyonu (RR) ve Destek Vektör Makineleri (DVM) modelleriyle karşılaştırılmıştır. Fiyat öznitelikleriyle eğitilen her iki modelin ortalama sınıflandırma başarısı 0,550 MO F-Ölçütü oranı civarındadır. Her iki modelin performansı da derin öğrenme sınıflandırıcılarının gerisinde kalmıştır. Derin öğrenme ve yapay öğrenme modelleriyle deneyler tamamlandıktan sonra bu modellerle piyasa benzetimi gerçeklenmiştir. Benzetime her hisse için 1000 TL'lik sermaye ile başlanmış ve benzetim sonunda hisse bazında elde edilen sermaye miktarları hesaplanmıştır. Benzetimde UKSB, DVM ve RR modelleriyle birlikte karşılaştırma amaçlı 3 stratejiden yararlanılmıştır. Benzetim sonunda hem kar edilen hisse sayısı hem de ortalama kar oranı bakımından UKSB lider olmuştur. UKSB ağıyla %2.7'lik ortalama kar oranına ulaşılırken, onu Bekle ve Satın Al stratejisi %0,7'lik kar oranıyla takip etmiştir. DVM ve RR modelleri ise yaklaşık %5 oranında ortalama zarara sahip olmuştur. Tez çalışması, derin öğrenme modellerinin borsa tahmin problemlerinde diğer yapay öğrenme modellerine güçlü bir alternatif olduğunu göstermiştir. Önerilen farklı derin öğrenme mimarilerinin performansı literatürde sıklıkla kullanılan DVM ve LR yapay öğrenme modellerine üstünlük sağlamıştır. Derin öğrenme mimarileriyle beraber heterojen veri kaynakları kullanıldığında ise tahmin performansında artış olmamıştır.
Investors in the stock market aim to predict market behavior accurately to raise their profits. The Random Walk Theory, which is accepted by the finance community, reveals the hypothesis that stock prices are randomly defined and therefore it's unpredictable. However, developments in the field of artificial intelligence and the growth of the amount of digital data provide the way for better prediction of stock behaviors. Current approaches in financial forecasting are divided into two main groups as technical analysis and fundamental analysis. In technical analysis, past price data and technical indicators are used to predict the future behavior of the financial time series. Although the Effective Market Hypothesis suggests that all information is reflected on the stock prices immediately, technical analysts believe that it is possible to predict the future price by analyzing the past price data. Fundamental analysis is based on several news sources such as financial reports, companies releases, political and economic developments. Analysts extract important features from these unstructured data sources then these features are used as predictive inputs for the machine learning algorithms. In addition to the approaches of financial analysis, machine learning methods have proven to be useful in predicting the stock markets. Artificial Neural Networks and Support Vector Machines are the most preferred methods used for this aim. Statistical methods, Random Forests, Linear Discriminant Analysis, Logistic Regression and Evolutionary Computation are other methods used in the financial prediction. In these methods, handcrafted features obtained from raw data are used as model inputs. Formation of handcrafted features is a process that requires heavy workload and domain expertise. Furthermore, as the size of the features increases, training time of the models is extended and outputs produced by these models become more difficult to understand. While using feature selection methods to reduce the size of the expanding feature space; it is difficult to find an appropriate selection method in non-linear and noisy stock market data. In recent studies, Deep Learning (DL) has been proposed to deal with this issue. DL can be considered as a classification framework that automatically extracts features from the data and uses them directly in the prediction process. DL also has ability to form complex feature representations from raw data or simpler features in each layer at different levels of abstraction. The state of the art results obtained with the DL models in the fields of image classification and natural language processing give rise to the use of DL models in the time series classification tasks. Most commonly used DL models in financial prediction are Long-Short Term Memory (LSTM) and Convolutional Neural Networks (CNN). In this study, these DL models are mainly used to predict the hourly direction of the stocks. In the first part of the thesis, the daily movements of three different stocks in Borsa İstanbul were predicted by using different technical indicators. Experiments were performed with the different sets of features (individual stock, Dollar-Gold (DA), BIST100 all stock and BIST100 + DA). As the size of the feature space rose to 5860, relevant features were selected by the Gain Ratio and Relief selection methods. Gradient Boosting Machines (GBM) and Logistic Regression (LR) classifiers were trained and the performance evaluation was performed with Accuracy and Macro-Averaged (MA) F-Measure metrics. With the GBM classifier-Gain Ratio selection, the GARAN stock had been reached to the highest accuracy rate (0.599) than all the feature selection-classifier combinations. THYAO's movements were successfully predicted with an accuracy of 0.558 using the Relief selection-GAM classifier pair. In the ISCTR prediction, the LR classifier with the Gain Ratio selection achieved an accuracy ratio of 0.581. When the classification results were examined, it was seen that the selection of the relevant features improved the classification results according to the results obtained without selection. The use of BIST100 stocks features in the prediction also increased the performance of the classification for all stocks in terms of accuracy. In the second part of the thesis, the hourly movements of all stocks in the BIST 100 were predicted with the deep learning models. First experiments were conducted only with the price features (technical indicators and temporal features) using CNN classifier. Feature vectors correspond to each hour were transformed into 2-D (2D) matrices containing the feature vectors of the past 80 hours. Because CNN took into account the spatial relationships between neighbor features when extracting local patterns, the order of the features in the input data was rearranged considering the feature correlations. With randomly sorted features (CNN-Rand (ESA-Rast)), an average of 0.545 MA F-Measure rate was obtained for 100 stocks, while sorted features (CNN-Corr (ESA-Kor)) resulted in 2% performance increase. The results were compared with the LR classifiers with and without feature selection. In the selection process, Chi-square was used to find a common subset of features for all BIST 100 stocks. After choosing common features, the LR classifier was trained for each stocks. While CNN-Rand had almost the same MA F-Measure ratio (0.545) as LR classifiers; CNN-Corr had shown higher performance than LR with and without feature selection. After examining the relative MA F-Measure scores of each classifier, it was found that CNN-Corr achieved higher relative MA F-Measure values than the other three classifiers. CNN-Corr became the leading classifier in 54 of 100 stocks with the best MA F-Measure scores. After obtaining results with the CNN architecture, experiments were done with another deep learning architecture, LSTM network. LSTM network takes into account the impact of the examples in the past time steps when predicting the current time step. For each time step in the sequence, the LSTM produces an output vector. In the experiments with LSTM, output vector (feature representation) of the last time step in the sequence is taken as a representation of the entire sequence. Secondly, instead of using the output vector of the last time step, output vectors of all steps are used. In this case, LSTM uses the attention mechanism to choose which time steps are important. As in CNN, input data of the LSTM networks was given in 2D matrices. In the experiments done with the price features for 100 stocks, with the representations obtained from the last time (LSTM-Last (Fiyat-Son) model) achieved an average MA F-Measure rate of 0.560. With the use of the attention mechanism (LSTM-All (Fiyat-Tüm) model), the classification performance increased to 0.576 MA F-Measure rate. Second experiments were conducted with LSTM network using news data. Approximately 457000 news articles in the news dataset were firstly pre-processed and word representations for each word were created via the Word2vec toolkit. In order to translate each news article into the representations, word vectors corresponding to occurred words were averaged. So, each news articles were converted into 300 dimensional dense vectors. News articles expressed by word representations were firstly divided into hourly intervals and then each interval was divided into 5-minute periods. The mean of the news vectors in a 5-minute time periods was taken in order to express in each hour with the matrices of 12x300 dimensions. After features were created with the word representations, two different LSTM networks were trained again. While the mean of MA F-Measure rate of 0.530 was reached with the representations obtained from the last time step in the first LSTM, the MA F-Measure rate of 0.520 was achieved using the representations from all time steps in the second network architecture. Due to the properties of word embeddings, word representations do not directly represent the financial sentiments in the news. To overcome this issue, financial sentiment dictionary prepared by Loughran and McDonald and pre-trained Fasttext word representations were used. In the first step, Fasttext representations of the financial sentiment words were extracted and hierarchical clustering is applied. Formed 314 clusters were represented by the cluster medians. In the second step, news articles were converted to dense vectors by taking the means of Fasttext representations. In the last stage, news vectors were expressed in terms of sentiment word vectors. For this purpose, the similarity between the news vectors and the medians of the sentiment clusters was examined. Thus, each news article was represented in 314-dimensional vectors. As in the previous experiment with news features, news articles were divided into hourly time intervals and then 5-minute periods. So, each hour was expressed in 12x314 dimensional matrices. While two different LSTM networks were trained again with the sentiment-based features, the highest mean MA F-Measure rate (0.543) was reached with the representations obtained from the last time step. Compared to the news features used in the previous experiments, the use of sentiment dictionary and pre-trained representations increased the classification performance about the rate of 1.5%. After separate experiments with price and news data, two heterogeneous data sources were combined. Two different methods were proposed for combining the price and news features: feature level and model level. At feature level combination, news and price feature vectors were directly concatenated and fed to LSTM networks. At model level combination, news and price features were given as input to the independent LSTM networks and the outputs of these networks were combined with two different methods. Both attribute level and model level combinations did not result any performance improvement according to the results obtained with only price features. The results of the LSTM networks were also compared with the other machine learning methods such as Ridge Regression (RR) and Support Vector Machines (SVM). In order to capture the temporal relationships between training samples, both models were used Cross Validation with Sliding Window method in the training process. The average classification success of both models with the price features was around 0.550 MA F-Measure, while this rate was 2.5% lower than the performance of LSTM-All model. After the experiments were completed with deep learning and machine learning models, market simulation was realized. For each stock, the simulation was started with capital of TL 1000 and the amount of capital obtained on the basis of stock was calculated at the end. For comparison, 3 different strategies were used together with LSTM, SVM and RR models. At the end of the simulation, LSTM-All was the leading model in terms of both the number of stocks in profit and the average rate of profits. While LSTM-All achieved an average profit rate of 2.7%, it was followed by a Buy and Hold strategy with the rate of 0.7%. SVM and RR models had an average loss of about 5%. This study showed that deep learning models were a strong alternative to other artificial learning models in stock market prediction tasks. The performance of the proposed different deep learning architectures was superior to frequently used artificial learning models such as SVM and LR. When heterogeneous data sources were used together with deep learning architectures, there was no increase in prediction performance.