A story about predicting exchange rates with Deep Learning

Overview

Assuming that the current date is $ T $, we use Deep Learning to predict the simple moving average of daily prices from $ T + 1 $ to $ T + 30 $. image.png We conducted a simulation trade in which profits are confirmed if the price exceeds (below) the predicted moving average from the price when holding (or shorting) a long position. Also, if you hold it for 30 days, you will be forced to close it. I will do my best to make entries if there is a balance for each date and time. image.png

DL framework used

chainer ver1.3~1.5 Just in ver1.5, the compatibility has changed significantly, and it was difficult to deal with it. It seems that it is ver2.0.2 as of August 2017.

Usage data

Mizuho Historical Data https://www.mizuhobank.co.jp/rate/market/historical.html Below, we used the date and time data of 23 currencies. All are against Japanese yen. The top 8 currencies in bold are the currencies that have verified the trading simulation. (From 2002/4/1 to 2016/1/29, only currencies that have daily data without fail for a day) image.png At the time of learning, all are normalized by 0-1.

Input data

Daily data for the currencies of the above 23 countries and the past 30 days. The reason for choosing this input data is that we speculate that exchange rate fluctuations in each currency may be correlated with fundamental and technical factors.

Teacher data

The teacher data is a 30-day simple moving average 30 days after one currency. This time, we predicted each of the eight currencies (currencies in bold in the above data) that are often used by Japanese Forex companies. By the way, I tried some one-point forecasts (such as forecasting daily data for the next day) instead of moving averages, but I did not get good results. After all, it is said to be a random walk, so it may be difficult unless you predict the trend for a certain period of time.

Learning model

A simple feedforward NN with 3 middle layers. (Input layer is 690, intermediate layer 1 is 512, 2 is 256, 3 is 128, output layer is 1) image.png It is delicate to say that it is deep learning, but in wikipedia it seems that it can be said from the middle layer 3 layers, so I am allowed to name it for the time being. I used ReLU as the activation function and Adam as the optimization function. Hyperparameters should have been Chainer's default. I also used dropouts, but I remember not getting very good results. The activation function of the output layer is $ tanh $, and the error function is the square error.

Learning results

We learned and verified with 2000 days of training data and 1325 days of test data. Below are the results of the pound sterling vs. the Japanese yen, which gave particularly good results. All results tended to be more divergent in the second half of the test period. It doesn't seem to be simply rock-paper-scissors (the rate of the previous day is used as a predicted value). I think this is partly due to the changing market trends, so it may be better to divide the learning period and verification period into smaller parts, or to use a time-series-specific model such as LSTM. .. image.png The overall learning result is as follows. The error is expressed as variance. image.png The Swiss franc has a big gap because the part of the 2015 surge has just overlapped with the test period. Since it is impossible to predict price movements that are not related to the input data used for learning, if there are large price movements due to fundamental factors, it is difficult to simply use past time series data, and from the latest information such as twitter and news. I think that it is necessary to detect the part that is likely to affect the price movement as soon as possible.

Trading simulation results

I easily made a back test on my own and did it. The verification period is 1325 days from 2010/7/7 to 2015/12/11, which is the test data period. The initial amount is 10 million, the transaction unit is 1000 currency units, and the spread is also taken into consideration. However, since the data uses only the above daily data, it fluctuates finely in actual trading, and it is not known whether the contract will be decided, so the reproducibility as a back test is low. image.png image.png image.png After all, good results were obtained with GBP, which had the highest learning accuracy. On the contrary, CHF has poor learning results, so trading results are also bad.

As a caveat, since we are learning to reduce the error of the test period to the lower limit, this learning result is optimized in the test period, and it does not work even if we test using the same learning result in another period. (Curve fitting) There is a possibility. For example, the way the market moves changes depending on the period, as the divergence becomes larger in the latter half of the test period. Therefore, it is better to set a verification period outside the test period and perform the actual simulation, but this time we have not done so.

Summary

I think it is difficult to predict the exchange rate exactly by deep learning. However, depending on the usage data and ingenuity of trading methods, it seems that trading using deep learning may produce results even from time series data alone. Of course, there is a risk that the market trend will fluctuate, so it seems that it will not be profitable in the long run. Since there are a lot of issues, I would like to study and verify by reading other verification results and papers. If you are confident that you will make a profit by repeating improvements and verifications, I would like to try actual operation.

↓ Tutorial to create a forex (FX) trading system using deep learning http://qiita.com/jiji_platform/items/268377c542706e6f44b1

Recommended Posts

A story about predicting exchange rates with Deep Learning
A story about machine learning with Kyasuket
A story about a 40-year-old engineer manager passing "Deep Learning for ENGINEER"
A story about automating online mahjong (Mahjong Soul) with OpenCV and machine learning
The story of doing deep learning with TPU
A story about simple machine learning using TensorFlow
A story about implementing a login screen with django
A story about data analysis by machine learning
A story about making 3D space recognition with Python
A story about using Resona's software token with 1Password
A story about making Hanon-like sheet music with Python
A story about trying a (Golang +) Python monorepo with Bazel
A story about how theano was moved with TSUBAME 2.0
Try deep learning with TensorFlow
About learning with google colab
Deep Kernel Learning with Pyro
Try Deep Learning with FPGA
Generate Pokemon with Deep Learning
Try to build a deep learning / neural network with scratch
A story about competing with a friend in Othello AI Preparation
(Now) Build a GPU Deep Learning environment with GeForce GTX 960
A story about installing matplotlib using pip with an error
A story about an amateur making a breakout with python (kivy) ②
A story about how to deal with the CORS problem
A story about an amateur making a breakout with python (kivy) ①
A story about making a tanka by chance with Sudachi Py
A story about clustering time series data of foreign exchange
I tried to divide with a deep learning language model
A story about a python beginner stuck with No module named'http.server'
Machine learning A story about people who are not familiar with GBDT using GBDT in Python
A story about developing a machine learning model while managing experiments and models with Azure Machine Learning + MLflow
Try Deep Learning with FPGA-Select Cucumbers
Cat breed identification with deep learning
A story stuck with the installation of the machine learning library JAX
A refreshing story about Python's Slice
Make ASCII art with deep learning
A story about predicting prefectures from the names of cities, wards, towns and villages with Jubatus
A story about adding a REST API to a daemon made with Python
Try deep learning with TensorFlow Part 2
A sloppy story about Python's Slice
About Deep Learning (DNN) Project Management
I searched for a similar card of Hearthstone with Deep Learning
Solve three-dimensional PDEs with deep learning.
A story about developing a soft type with Firestore + Python + OpenAPI + Typescript
Check squat forms with deep learning
Categorize news articles with deep learning
A story about a student who does not know the machine learning machine learned machine learning (deep learning) for half a year
A story about using Python's reduce
Forecasting Snack Sales with Deep Learning
Make people smile with Deep Learning
Under investigation about PYNQ-Let's do deep learning with FPGA using Python-
A story of a deep learning beginner trying to classify guitars on CNN
PPLM: A simple deep learning technique to generate sentences with specified attributes
I tried the common story of predicting the Nikkei 225 using deep learning (backtest)
A story about remodeling Lubuntu into a Chromebook
Classify anime faces with deep learning with Chainer
Try Bitcoin Price Forecasting with Deep Learning
Try with Chainer Deep Q Learning --Launch
Try deep learning of genomics with Kipoi
Sentiment analysis of tweets with deep learning
A story about Python pop and append