Deep Learning in Finance

In recent years, we have seen many spectacular successes achieved by means of deep learning techniques. Deep neural networks were successfully applied to tasks in which traditional machine learning algorithms could not succeed – large-scale image classification, autonomous driving, and superhuman performance when playing traditional games such as Go or classic video games. Almost yearly, we can observe the introduction of a new type of network that achieves state-of-the-art (SOTA) results and breaks some kind of performance record. 

With the constant improvement in commercially available Graphics Processing Units (GPU), the emergence of freely available processing power involving CPUs/GPUs (Google Colab, Kaggle, and so on) and the rapid development of different frameworks, deep learning continues to gain more and more attention among researchers and practitioners who want to apply the techniques to their business cases.

In this chapter, we are going to show two possible use cases of deep learning in the financial domain – predicting credit card default and forecasting time series. In the first one, we present how to approach a classification task on tabular data using deep learning. Then, we focus on introducing a few possible neural network architectures for time series forecasting. Deep learning proved to deliver great results with sequential data such as speech, audio, and video. That is why it naturally fits into working with sequential data such as time series—both univariate and multivariate. Financial time series are known to be erratic and complex, hence the reason why it is such a challenge to model them. Deep learning approaches are especially apt for the task, as they make no assumptions about the distribution of the underlying data and can be quite robust to noise. 

We train the neural networks using PyTorch, which is a deep learning framework developed by Facebook. There are a few reasons why we selected this framework over others (such as TensorFlow). The first one is that PyTorch is very pythonic, so it is relatively easy to quickly understand the entire workflow without the need to go very deep into framework-specific knowledge and syntax. PyTorch lies somewhere in between Keras and TensorFlow in terms of coding complexity – there is definitely more flexibility than in Keras, but we are also not required to work on such a low level of programming as in pure TensorFlow. Furthermore, PyTorch is compatible with many Python libraries, such as numpy and pdb (for debugging). Some of the general characteristics of PyTorch include data parallelism, support for dynamic computational graphs  and Open Neural Network Exchange (ONNX). Lastly, the community around PyTorch is very active and there are many wrappers around PyTorch, which provide a lot of functionalities out of the box, such as the popular fastai.

Please bear in mind that all the examples of using deep learning for time series forecasting presented in this chapter are oversimplified – using vanilla neural network architectures is not enough to accurately predict the stock prices. The goal of this chapter is to show how such techniques can be used to predict future observations of time series.

In this chapter, we present the following recipes:

  • Deep learning for tabular data
  • Multilayer perceptrons for time series forecasting
  • Convolutional neural networks for time series forecasting
  • Recurrent neural networks for time series forecasting

At the very beginning of each notebook (available on the book's GitHub repository), we run a few cells that import and set up plotting with matplotlib. We will not mention this later on, as this would be repetitive, so at any time, assume that matplotlib is imported.

In the first cell, we first set up the backend of matplotlib to inline:

%matplotlib inline
%config InlineBackend.figure_format = 'retina'

By doing so, each plotted figure will appear below the cell that generated it and the plot will also be visible in the Notebook should it be exported to another format (such as PDF or HTML). The second line is used for MacBooks and displays the plot in higher resolution for Retina displays.

The second cell appears as follows:

import matplotlib.pyplot as plt
import warnings

plt.style.use('seaborn')
plt.rcParams['figure.figsize'] = [16, 9]
plt.rcParams['figure.dpi'] = 300
warnings.simplefilter(action='ignore', category=FutureWarning)

In this cell, we import matplotlib and warnings, set up the style of the plots to 'seaborn' (this is a personal preference), as well as default plot settings, such as figure size and resolution. We also disable (ignore) some warnings. In some chapters, we might modify these settings for better readability of the figures (especially in black and white).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.110.131