인공지능 기술이 발전하면서 이미지, 음성, 텍스트 등 다양한 분야에 적용되고 있으며, 데이터가 충분한 경우 기존 기법들에 비해 좋은 결과를 보인다. 주식시장은 경제, 정치와 같은 많은 변수에 의해 영향을 받기 때문에, 주식 가격의 움직임 예측은 어려운 과제로 알려져 있다. 다양한 기계학습 기법과 인공지능 기법을 이용하여 주가 패턴을 연구하여 주가의 등락을 예측하려는 시도가 있어왔다. 본 연구는 딥러닝 기법 중 컨볼루셔널 뉴럴 네트워크(CNN)를 기반으로 주가 패턴 예측률 향상을 위한 데이터 증강 방안을 제안한다. CNN은 컨볼루셔널 계층을 통해 이미지에서 특징을 추출하여 뉴럴 네트워크를 이용하여 이미지를 분류한다. 따라서, 본 연구는 주식 데이터를 캔들스틱 차트 이미지로 만들어 CNN을 통해 패턴을 예측하고 분류하고자 한다. 딥러닝은 다량의 데이터가 필요하기에, 주식 차트 이미지에 다양한 데이터 증강(Data Augmentation) 방안을 적용하여 분류 정확도를 향상 시키는 방법을 제안한다. 데이터 증강 방안으로는 차트를 랜덤하게 변경하는 방안과 차트에 가우시안 노이즈를 적용하여 추가 데이터를 생성하였으며, 추가 생성된 데이터를 활용하여 학습하고 테스트 집합에 대한 분류 정확도를 비교하였다. 랜덤하게 차트를 변경하여 데이터를 증강시킨 경우의 분류 정확도는 79.92%였고, 가우시안 노이즈를 적용하여 생성된 데이터를 가지고 학습한 경우의 분류 정확도는 80.98%이었다. 주가의 다음날 상승/하락으로 분류하는 경우에는 60분 단위 캔들 차트가 82.60%의 정확도를 기록하였다.
인공지능 기술이 발전하면서 이미지, 음성, 텍스트 등 다양한 분야에 적용되고 있으며, 데이터가 충분한 경우 기존 기법들에 비해 좋은 결과를 보인다. 주식시장은 경제, 정치와 같은 많은 변수에 의해 영향을 받기 때문에, 주식 가격의 움직임 예측은 어려운 과제로 알려져 있다. 다양한 기계학습 기법과 인공지능 기법을 이용하여 주가 패턴을 연구하여 주가의 등락을 예측하려는 시도가 있어왔다. 본 연구는 딥러닝 기법 중 컨볼루셔널 뉴럴 네트워크(CNN)를 기반으로 주가 패턴 예측률 향상을 위한 데이터 증강 방안을 제안한다. CNN은 컨볼루셔널 계층을 통해 이미지에서 특징을 추출하여 뉴럴 네트워크를 이용하여 이미지를 분류한다. 따라서, 본 연구는 주식 데이터를 캔들스틱 차트 이미지로 만들어 CNN을 통해 패턴을 예측하고 분류하고자 한다. 딥러닝은 다량의 데이터가 필요하기에, 주식 차트 이미지에 다양한 데이터 증강(Data Augmentation) 방안을 적용하여 분류 정확도를 향상 시키는 방법을 제안한다. 데이터 증강 방안으로는 차트를 랜덤하게 변경하는 방안과 차트에 가우시안 노이즈를 적용하여 추가 데이터를 생성하였으며, 추가 생성된 데이터를 활용하여 학습하고 테스트 집합에 대한 분류 정확도를 비교하였다. 랜덤하게 차트를 변경하여 데이터를 증강시킨 경우의 분류 정확도는 79.92%였고, 가우시안 노이즈를 적용하여 생성된 데이터를 가지고 학습한 경우의 분류 정확도는 80.98%이었다. 주가의 다음날 상승/하락으로 분류하는 경우에는 60분 단위 캔들 차트가 82.60%의 정확도를 기록하였다.
As Artificial Intelligence (AI) technology develops, it is applied to various fields such as image, voice, and text. AI has shown fine results in certain areas. Researchers have tried to predict the stock market by utilizing artificial intelligence as well. Predicting the stock market is known as on...
As Artificial Intelligence (AI) technology develops, it is applied to various fields such as image, voice, and text. AI has shown fine results in certain areas. Researchers have tried to predict the stock market by utilizing artificial intelligence as well. Predicting the stock market is known as one of the difficult problems since the stock market is affected by various factors such as economy and politics. In the field of AI, there are attempts to predict the ups and downs of stock price by studying stock price patterns using various machine learning techniques. This study suggest a way of predicting stock price patterns based on the Convolutional Neural Network(CNN) among machine learning techniques. CNN uses neural networks to classify images by extracting features from images through convolutional layers. Therefore, this study tries to classify candlestick images made by stock data in order to predict patterns. This study has two objectives. The first one referred as Case 1 is to predict the patterns with the images made by the same-day stock price data. The second one referred as Case 2 is to predict the next day stock price patterns with the images produced by the daily stock price data. In Case 1, data augmentation methods - random modification and Gaussian noise - are applied to generate more training data, and the generated images are put into the model to fit. Given that deep learning requires a large amount of data, this study suggests a method of data augmentation for candlestick images. Also, this study compares the accuracies of the images with Gaussian noise and different classification problems. All data in this study is collected through OpenAPI provided by DaiShin Securities. Case 1 has five different labels depending on patterns. The patterns are up with up closing, up with down closing, down with up closing, down with down closing, and staying. The images in Case 1 are created by removing the last candle(-1candle), the last two candles(-2candles), and the last three candles(-3candles) from 60 minutes, 30 minutes, 10 minutes, and 5 minutes candle charts. 60 minutes candle chart means one candle in the image has 60 minutes of information containing an open price, high price, low price, close price. Case 2 has two labels that are up and down. This study for Case 2 has generated for 60 minutes, 30 minutes, 10 minutes, and 5minutes candle charts without removing any candle. Considering the stock data, moving the candles in the images is suggested, instead of existing data augmentation techniques. How much the candles are moved is defined as the modified value. The average difference of closing prices between candles was 0.0029. Therefore, in this study, 0.003, 0.002, 0.001, 0.00025 are used for the modified value. The number of images was doubled after data augmentation. When it comes to Gaussian Noise, the mean value was 0, and the value of variance was 0.01. For both Case 1 and Case 2, the model is based on VGG-Net16 that has 16 layers. As a result, 10 minutes -1candle showed the best accuracy among 60 minutes, 30 minutes, 10 minutes, 5minutes candle charts. Thus, 10 minutes images were utilized for the rest of the experiment in Case 1. The three candles removed from the images were selected for data augmentation and application of Gaussian noise. 10 minutes -3candle resulted in 79.72% accuracy. The accuracy of the images with 0.00025 modified value and 100% changed candles was 79.92%. Applying Gaussian noise helped the accuracy to be 80.98%. According to the outcomes of Case 2, 60minutes candle charts could predict patterns of tomorrow by 82.60%. To sum up, this study is expected to contribute to further studies on the prediction of stock price patterns using images. This research provides a possible method for data augmentation of stock data.
As Artificial Intelligence (AI) technology develops, it is applied to various fields such as image, voice, and text. AI has shown fine results in certain areas. Researchers have tried to predict the stock market by utilizing artificial intelligence as well. Predicting the stock market is known as one of the difficult problems since the stock market is affected by various factors such as economy and politics. In the field of AI, there are attempts to predict the ups and downs of stock price by studying stock price patterns using various machine learning techniques. This study suggest a way of predicting stock price patterns based on the Convolutional Neural Network(CNN) among machine learning techniques. CNN uses neural networks to classify images by extracting features from images through convolutional layers. Therefore, this study tries to classify candlestick images made by stock data in order to predict patterns. This study has two objectives. The first one referred as Case 1 is to predict the patterns with the images made by the same-day stock price data. The second one referred as Case 2 is to predict the next day stock price patterns with the images produced by the daily stock price data. In Case 1, data augmentation methods - random modification and Gaussian noise - are applied to generate more training data, and the generated images are put into the model to fit. Given that deep learning requires a large amount of data, this study suggests a method of data augmentation for candlestick images. Also, this study compares the accuracies of the images with Gaussian noise and different classification problems. All data in this study is collected through OpenAPI provided by DaiShin Securities. Case 1 has five different labels depending on patterns. The patterns are up with up closing, up with down closing, down with up closing, down with down closing, and staying. The images in Case 1 are created by removing the last candle(-1candle), the last two candles(-2candles), and the last three candles(-3candles) from 60 minutes, 30 minutes, 10 minutes, and 5 minutes candle charts. 60 minutes candle chart means one candle in the image has 60 minutes of information containing an open price, high price, low price, close price. Case 2 has two labels that are up and down. This study for Case 2 has generated for 60 minutes, 30 minutes, 10 minutes, and 5minutes candle charts without removing any candle. Considering the stock data, moving the candles in the images is suggested, instead of existing data augmentation techniques. How much the candles are moved is defined as the modified value. The average difference of closing prices between candles was 0.0029. Therefore, in this study, 0.003, 0.002, 0.001, 0.00025 are used for the modified value. The number of images was doubled after data augmentation. When it comes to Gaussian Noise, the mean value was 0, and the value of variance was 0.01. For both Case 1 and Case 2, the model is based on VGG-Net16 that has 16 layers. As a result, 10 minutes -1candle showed the best accuracy among 60 minutes, 30 minutes, 10 minutes, 5minutes candle charts. Thus, 10 minutes images were utilized for the rest of the experiment in Case 1. The three candles removed from the images were selected for data augmentation and application of Gaussian noise. 10 minutes -3candle resulted in 79.72% accuracy. The accuracy of the images with 0.00025 modified value and 100% changed candles was 79.92%. Applying Gaussian noise helped the accuracy to be 80.98%. According to the outcomes of Case 2, 60minutes candle charts could predict patterns of tomorrow by 82.60%. To sum up, this study is expected to contribute to further studies on the prediction of stock price patterns using images. This research provides a possible method for data augmentation of stock data.
* AI 자동 식별 결과로 적합하지 않은 문장이 있을 수 있으니, 이용에 유의하시기 바랍니다.
문제 정의
본 논문은 딥러닝을 활용하여 주가 패턴을 예측하는 문제에서 데이터 증강(Data Augmentation)을 통해 학습 데이터를 추가로 생성하여, 모형의 정확도를 높이는 방안을 제시한다.
따라서, 본 연구에서는 이미지 기반의 다양한 데이터 증강 방안을 고려하여 주가 패턴 정확도를 향상시키는 방안을 파악한다.
본 연구를 통해서, 주가 데이터를 이용한 캔들스틱 이미지를 다양한 방법으로 증강하여 적용하는 방안을 제시하였다.
본 연구는 두 가지 목적을 이루기 위해 진행되었다.
제안 방법
데이터는 대신증권 API를 이용하여 분 단위 데이터를 추출하였고, 전처리를 거쳐 노이즈 제거, 라벨링 및 캔들차트 생성은 Plot.ly 라이브러리를 이용하였다.
하루의 주가 움직임을 캔들 차트로 그렸으며, 5분, 10분, 30분, 60분 단위로 다양하게 차트를 생성하였다.
분류 문제는 하루의 주가 패턴을 분류하는 문제와 내일의 주가가 상승할 지 하락할 지 분류하는 두 가지 문제로 구성하였다.
첫 번째 문제는 하루의 주가 패턴을 분류한 후에 과거 데이터를 가지고 학습하고, 캔들 차트에서 마지막 캔들(-1candle), 마지막에서 두번째 캔들(-2candle), 마지막에서 세번째(-3candle)을 제거한 테스트 데이터에 대해서 주가 패턴을 분류하는 방식으로 구성되어 있다.
두번째 분류 문제는 하루의 주가 캔들 차트를 가지고 내일의 주가 상승 여부를 분류하는 문제로 구성하였다.
CNN 기법을 통해서 모형을 학습하였으며, 데이터 증강방안으로는 주가 캔들 차트를 무작위로 변경하여 추가 데이터를 생성하는 방안과 가우시안 노이즈(Gausian Noise)(Hussain et al, 2018)을 적용하여 추가 데이터를 생성하는 방안을 활용하였다.
데이터 증강을 활용하지 않은 경우에 분류범주에 따라 높은 정확도를 보이는 경우는 데이터의 양이 많은 경우임을 알 수 있었으며, 데이터 증강기법을 이용해서 데이터를 늘리고 학습하여 정확도를 비교하였다.
전처리를 통해서 주식 데이터의 노이즈를 제거한 후 이미지를 생성하였다.
데이터 증강 방안을 적용하여 학습데이터를 추가로 생성한 후에 딥러닝 모델에 학습시켰다.
그 후 테스트 데이터로 생성된 모델의 정확도를 확인하였다.
그 후 라벨링된 이미지를 딥러닝 모델에 학습시키고 테스트 데이터로 정확도를 확인하였다.
패턴은 당일 주가가 상승하였는지 하락하였는지에 따라 상승(Up), 하락(Down)을 구분하고, 맨 마지막 캔들이 전 캔들보다 상승하면서 마감하였는지 하락하면서 마감하였는지에 따라 상승마감, 하락마감을 구분하였다.
패턴은 5개로 구분하였으며 당일 상승 하고 상승마감 혹은 하락마감한 패턴 두 개와 당일 하락 하고 상승 마감 혹은 하락마감한 패턴 두 개 그리고 횡보이다.
캔들스틱 차트(Candlestick Charts) 이미지를 만들기 위해서 ‘plotly’ 패키지를 사용하여 jpg 형태로 저장하였다.
주가 데이터는 종목코드, 일자, 시간, 시가, 고가, 저가, 종가를 5분, 10분, 30분, 60분 단위로 수집하여 캔들스틱 차트 생성에 사용하였다.
본 연구에서는 주가의 움직임을 나타내는 캔들스틱 차트에서 특정 캔들을 무작위로 움직여서 추가 이미지 데이터를 생성하는 방법을 활용하였으며, 절차는 다음과 같다.
3) 수정될 캔들의 수(100%, 50%, 10%)와 캔들의 움직임 정도(0.003 0.002, 0.001, 0.00025)에 따라 주가 이미지 데이터를 추가로 생성하였다.
데이터는 85:15의 비율로 학습 데이터 셋(training data set)과 테스트 데이터(test data set)로 나누었다.
기존 이미지에 평균 0, 분산 0.01만큼의 가우시안 노이즈 레이어를 추가하여, 추가 학습 이미지를 생성하였다.
따라서, 전체 데이터에서 시간을 기준으로 최신의 15% 데이터를 테스트 데이터로 고정하였다.
본 연구에서는 대신증권 API를 이용하여 KOSDAQ 상위 150개 종목에 대해 종목코드, 일자, 시간, 시가, 고가, 저가, 종가를 5분, 10분, 30분, 60분 단위로 데이터를 수집하였다.
성과의 교차검증을 위해 나머지 데이터에서 학습 데이터 셋과 검증 데이터(valid data)를 5가지 방식으로 나누었다.
따라서, 데이터 증강 및 가우시안 노이즈를 적용할 이미지는 10분 단위로 생성된 캔들스틱 차트와 마지막 세개의 캔들을 제거한 -3캔들을 사용하였다.
무작위로 수정되는 캔들의 수는 100%, 50%, 10%로 나누어 적용하였다.
두 수정값을 활용하여 이미지 데이터 증강방안에 적용하였다.
원본 데이터와 증강된 데이터를 활용하여 모형을 학습하였고, 성과를 측정하였다.
데이터 증강을 위해 캔들의 상하 움직임 값을 뜻하는 수정값을 다양하게 하여 증강 이미지 데이터를 생성하였다.
가우시안 노이즈는 10분 단위로 그린 캔들스틱 차트에서 마지막 세개의 캔들을 제거한 (-3캔 들) 원본 이미지와 수정값 0.003으로 50%의 캔들을 수정한 증강 이미지에 적용해보았다.
실제로 -1candle이 높은 정확도를 보여주나, -3candle이 예측에 있어 더 큰 의미가 있다고 판단하여, Case 1의 연구에는 10분 -3candle을 이용하였다.
60분, 30분, 10분, 5분 단위로 캔들스틱 차트 이미지를 생성하였으며, 마지막 캔들(-1candle), 마지막 두 개의 캔들(-2candles), 마지막 세 개의 캔들(-3candles)을 제거한 이미지를 각각 생성 하여 분류정확도를 측정하였다.
60분, 30분, 10분, 5분 단위로 캔들스틱 차트 이미지를 생성하여 CNN 모형을 학습하였다.
그리고 VGGNet-16이 우수한 성과를 보이는 모형이지만, 본 연구에서는 하나의 모형만 사용하였다.
대상 데이터
데이터 수집 기간은 2016년 8월 1일부터 주식시장 종료 시간이 15시에서 15시 30분으로 변경되었기에, 2016년 8월 1일부터 2019년 3월 8일까지 수집했다.
데이터 전처리를 통해서 노이즈 제거 후 104개 종목에 대한 데이터를 실험에 활용하였다.
이론/모형
본 연구는 CNN 모형에서도 이미지 분류의 성과가 검증된 아키텍쳐인 VGGNet-16([Figure 6 참조])을 이용하였다.
본 연구에서는 딥러닝 모형으로 Convolutional Neural Network (CNN)을 사용하였다.
성능/효과
데이터 증강은 여러 수정값 중 0.00025를 모든 캔들(100%)에 적용하였을 때, 0.7992로 가장 높은 정확도를 보였다.
60분 단위 캔들스틱 차트 이미지가 가장 높은 0.8260의 정확도를 보였으며, 30분 단위, 10분 단위, 5분 단위 이미지를 활용한 경우의 분류 정확도가 지속적으로 낮아졌다.
그 결과 10분 -3캔들의 원본 이미지에 가우시안 노이즈를 적용한 경우의 분류 정확도는 0.8087이 나왔으며, 원본 이미지와 함께 데이터 증강(수정값 0.003, 50% 적용) 이미지에도 가우시안 노이즈를 적용한 경우의 분류 정확도는 0.8098이 나왔다([Table 8]참조).
1) 캔들스틱 차트에서 맨 왼쪽에 위치하는 첫번째 캔들을 제외하고 나머지 캔들중에서 수정할 캔들을 100%, 50%, 10% 중에서 무작위로 선택한다.
후속연구
본 연구의 한계점은 코스닥 데이터만 활용하였고, 2016년 8월 1일부터 2019년 3월 8일까지의 데이터만을 사용하였다는 점이다.
본 연구에서 제안한 방안 이외에 다양한 방안을 적용하여 증강이미지를 생성할 수 있으며, 시계열 데이터를 이미지로 생성함에 있어서 데이터 수가 부족한 문제를 해결하는 좋은 방안이 될 수 있을 것이다.
추후 다양한 모형을 적용하여 주가 패턴 예측을 위한 캔들스틱 이미지에 적합한 딥러닝 모형을 찾아 검증해 볼 필요가 있다.
참고문헌 (21)
Amilon, H., "GARCH estimation and discrete stock prices: an application to low-priced Australian stocks", Economics Letters, Vol.81, No.2, pp.215-222, 2003.
Ding, X., Zhang, Y., Liu, T., and Duan, J., "Using Structured Events to Predict Stock Price Movement: An Empirical Investigation", Proceedings of the 2014 Conference on Empirical Methods in Natural Language Processing (EMNLP), pp.1415-1425, 2014.
Guo, S. J., Hung, C. C., and Hsu, F. C., "Deep Candlestick Predictor: A Framework toward Forecasting the Price Movement from Candlestick Charts", 2018 9th International Symposium on Parallel Architectures, Algorithms and Programming (PAAP), pp.219-226, 2018.
Hoseinzade, E. and Haratizadeh, S., "CNNpred: CNN-based stock market prediction using a diverse set of variables", Expert Systems with Applications, Vol.129, No.-, pp.273-285, 2019.
Hussain, Z., Gimenez, F., Yi, D., Rubin, D., "Differential Data Augmentation Techniques for Medical Imaging Classification Tasks", Proceedings of 2018 AMIA Annual Symposium, pp.979-984, 2018.
Jeantheau, T., "A link between complete models with stochastic volatility and ARCH models", Finance and Stochastics, Vol. 8, No.1, pp.111-131, 2004.
Ko, D. G., Song, S. H., Kang, K.M., and Han, S. W., "Convolutional Neural Networks for Character-level Classification", IEIE Transactions on Smart Processing & Computing, Vol.6, No.1, pp.53-59, 2017.
LeCun, Y., Bottou, L., and Haffner, P., "Gradient-based learning applied to document recognition", Proceedings of the IEEE, Vol.86, pp.2278-2324, 1998.
Oh, C., and Shen, O. R. L., "Investigating Predictive Power of Stock Micro Blog Sentiment in Forecasting Future Stock Price Directional Movement", Proceedings of ICIS 2011, Shanghai, China.
Schumaker, R. P., and Chen, H., "Textual Analysis of Stock Market Prediction Using Breaking Financial News: The AZFinText System", ACM Transactions on Information Systems, Vol.27, No.2, Article No. 12, 2009.
※ AI-Helper는 부적절한 답변을 할 수 있습니다.