Is Deep Learning useful for Predicting Futures Markets?

Any discussion of the application of deep neural networks to predicting financial markets needs to navigate a sociological mine-field. Quants, machine learning researchers and financial econometricians have competing perspectives which seem to have been forged from a number of factors including the juxtaposition of different academic disciplines and the theory versus the practice.

In our forthcoming Journal of Algorithmic Finance article, we show how to use deep learning to predict directional movements of CME futures prices at 5 minute intervals.  Deep neural networks, as primarily developed for image and speech recognition applications, and now heralded in applications such as AlphaGo and self-driving cars, require a large number of features to justify the use of multiple hidden perceptron layers.
screen-shot-2016-09-17-at-12-23-09-pm
[Source: Dixon, Matthew Francis, Klabjan, Diego and Bang, Jin Hoon, Classification-Based Financial Markets Prediction Using Deep Neural Networks (July 18, 2016). Forthcoming in the Journal of Algorithmic Finance]

Re-opening Pandora’s Box

The question that we set out to address is how can deep neural networks be applied to the prediction of futures markets?  The more fundamental question of economic value of machine learning is both complex and contentious with many prominent algorithmic finance researchers concluding that trading costs outweigh any methodological benefits. Yet it is well known in the capital markets industry that a dominant use case for machine learning is alpha generation.

There exists a spectrum of opinion best characterized by its poles. On the one end, we have computer scientists predicating the notion that we set a machine to process some input and leave it to find hidden patterns which yield trading profits. The proverbial hammer looking for a nail.  At the other end, we have financial prediction experts asserting that the question of utility of deep learning, considered in isolation, is somewhat limited; Which events to predict in conjunction with choice of input data is by far the most skillful aspect of successfully applying machine learning.The methodology is secondary.

Finance academics are on the fence. Much of their skepticism of machine learning derives from inadequate assessment of over-fitting by studies in the 1990s.  But since then, we’ve witnessed an exponential growth in the amount of data to train models, orders of magnitude improvement in micro-processor capability not to mention advances in techniques for avoiding and measuring over-fitting, such as k-fold cross validation, node black-out and bias variance trade-off analysis. Antiquated dynamic models of financial econometrics remain the standard. Surely it’s time to open Pandora’s box?

Finding alpha is essentially a question of time series analysis applied to very noisy datasets. While there are arguably similar types of non-financial applications where Recurrent Neural Networks (RNNs) with Long Short Term Memory (LTSM) have been successful,  the question of how to define the recurrence for financial market prediction is non-trivial. Our approach includes the memory in the features to avoid having to define recurrence. However it is an open question as to which is better.

We shall break off one piece of this puzzle, here, and discuss the applicability of deep learning in particular. Like most academic studies, we were limited by the amount of data we could access and this defined the scope of our studies. We begin with ‘longer’ time-frame predictions, at 5 minutes, and then advance to using order book pressure to prediction near-time movement.

Market Wide Prediction

One efficient approach to generating a sufficient number of features from historical prices is to simply lag prices and calculate rolling moving averages, varying the lag and window size for each feature.  This may results in a few hundred features but isn’t sufficient for deep neural networks.

By predicting multiple instruments with one model, we are able to scale the number of features to nearly ten thousand. Not only is this sufficient for deep neural networks but it provides the added benefit of capturing market wide effects, not necessarily apparent from fitting a model to a single instrument.

The graph below shows the distribution of classification accuracy for each 0f 43 CME listed front-month futures contracts over ten out-of-sample walk forward optimization windows. We have used a three state classifier to represent up, flat and down movements. The red line in each bar represents the average result over the backtesting horizon. In most cases, the classifier outperforms white noise (33%), but the variability is significant. The results also require market knowledge to interpret their significance. For example, a market with little liquidity may yield higher classification accuracy by virtue of smaller price dispersion.

classifcation

[Source: Dixon, Matthew Francis, Klabjan, Diego and Bang, Jin Hoon, Classification-Based Financial Markets Prediction Using Deep Neural Networks (July 18, 2016). Forthcoming in the Journal of Algorithmic Finance]

Machine Learning is just Matrix Linear Algebra

Using off the shelf tools such as Tensor flow and Theano is convenient but shifts the burden of configurability to the user. We prefer to maintain our own implementation, designed specifically for prediction across multiple instruments. Using the Intel Xeon Phi, we have designed and implemented a C++ version of a deep neural network which uses Intel MKL libraries to efficiently map matrix computations, the computational bottle-neck, to multi and many-core Intel Xeon architectures. Training a deep neural network with 7 layers over approximately 10 years of 43 CME futures prices at 5 minute intervals can take days on a single processor. Our implementation runs 11.4x faster on the Knights Corner generation of the Intel Xeon Phi co-processor.  Further details of this implementation are described in our 8th Workshop on High Performance Computational Finance paper.

Using Market-Microstructure is Key

The above study concluded that consistent high prediction accuracy from price history alone is elusive.  We turned to using the order book to extract current and lagged features and are able to generate a sufficient number of features for a single instrument to warrant using deep learning. Prediction time frames from book pressure and aggressor information is very short and low latency implementations are required. At 1-2 millisecond lead times, we are able to obtain substantially higher classification accuracy than the use of price history alone.  The naive approach to labeling, detailed in the paper,  does not lead to trading profits. However, market knowledge can be applied to construct more elaborate labeling approaches which do yield trading profits.

Summary

Successful application of deep learning to predicting price movements in any market requires integration of market knowledge with machine learning expertise. Deep learning needs a large number of features and the quant researcher needs to be innovative in their construction.  Prediction from level I data almost certainly requires a market wide prediction approach. With level II data, the key discriminatory factor is how the microstructure memory is encoded.  Labeling approaches which yield profitable trading signals need to be carefully designed too. We’ve shown that deep learning leads to high accuracy in predicting extreme price movements over very short time-frames.

Using Apache Spark for CVA Pricing of Derivatives

Why Use Apache Spark for CVA?

Ease of use and flexibility
Easily express parallel computations across many machines using simple operators, without advanced knowledge of parallel architectures.

Fault tolerant
Avoid having to restart the simulations from scratch if any machines or processes fail while the computation is running.

Reproducibility of results
Generate and store all scenario data, even for large numbers of scenarios and instruments, so that risk estimates can be exactly reproduced and isolated from randomness. Access scenario data for what-if scenario analysis and diagnosis.

Background

Since the 2007 global financial crisis, financial institutions now more accurately measure the risks of over-the-counter (OTC) products. It is now standard practice to adjust derivative prices for the risk of the counterparty’s or one’s own default, by means of credit or debit valuation adjustments (CVA/DVA).

Calculating the CVA of a portfolio typically requires Monte-Carlo simulation with a large number of scenarios. Monte-Carlo simulation is computationally complex but embarrassingly parallel. The computation and storage requirement for what-if scenario analysis grows significantly when the portfolio is large and contains a wide array of financial instruments across multiple asset classes.

Emerging distributed computing platforms offer trade offs between performance, flexibility, modularity and maintainability of programming infrastructure. We demonstrate below how to deploy exposure calculations on Apache Spark for in-memory analytics on scenario data.
spark-stack

Apache Spark provides a suite of functionality for data mining, streaming, machine learning and graph construction.

 


Estimating CVA using Python on Apache Spark

We demonstrate how Apache Spark can be used to realize CVA calculations on a cluster supporting the Hadoop file system.  Apache Spark enables CVA calculations on a cluster of thousands of nodes using high level languages such as Scala and Python, thus making it an attractive platform for prototyping and live risk estimates.

Additionally, Apache Spark can hold all the price results of a large portfolio simulation in memory across thousands of nodes in support of calculating various statistics on demand.  The key benefit of using Apache Spark over other distributed implementations like MPI, OpenMP & CUDA etc. is that it allows the computations to scale to a large number of nodes in a reliable manner where failure of nodes is managed by the framework.

This benefit, along with the ease of implementation comes at the expense of some performance loss. However, we can minimize this performance loss by using the numpy/scipy package that has been built using BLAS and LAPACK routines.


Interest rate swap portfolio example

For demonstration purposes we consider a portfolio of vanilla interest rate swaps. Our implementation on Apache Spark is based on Python code that utilizes the QuantLib package to value a vanilla swap.

Consider a portfolio of NI vanilla swaps and let NT denote the number of time steps in the future where the price distribution of the portfolio is evaluated.  Further denote NS as the number of simulations used to price the portfolio at each time step in the future.  The total number of price calculations then is given by NI x NT x NS.

A high level description of the implementation now follows:<\p>

  • Create a distributed collection (RDD), randArrayRDD, of random numbers of size NS x NT.  For this we use the Apache Spark Python API:
    randArrayRDD = RandomRDDs.normalVectorRDD(sc, NS, NT,  numPartitions=NP, seed=1L)
  • Call a map function value_swap that  processes the RDD created in the first step. For this we use the Apache Spark Python API:
    randArrayRDD.map(lambda p:(value_swap(p, NI)))
  • The map function works on a row of RDD of random numbers in two stages:
    (i) Construct  NT yield curves, crvVec, one for each time interval using the single factor Hull-White short-rate model.
    (ii) Value NI swaps at NT time intervals in the future to construct a price matrix, spmat of size NI x NT for each simulation.
  • Collect  price matrices for all simulations to create a single price matrix, pmat, of size NS x NI x NT. For this we use the Apache Spark Python API:
    pmat=randArrayRDD.map(lambda p: (value_swap(p, NI))).collect()

priceDistribution

This price matrix, pmat, has price distribution information for all swaps in the portfolio, and can be used to calculate various statistics including PFE and EE.  CVA can be estimated using the Basel III formula for regulatory capital charge. Demonstration code is available from the authors.

 

 


About Us
Quiota LLC is a consulting company that develops strategies for adopting emerging technologies and software platforms to deliver high performance computing to financial applications that harness big data. We engage in:

  • Cost benefit study for adoption of emerging technology and software platforms.
  • Diligence of emerging financial technologies and software platforms for financial institutions.
  • Systems architecture and development of financial application prototypes based on distributed computing frameworks.
  • Performance benchmarking and diagnostics.
  • Data science and quantitative analytics.
  • Workshops and company hosted training.

Matthew Dixon

Matthew Dixon is the principal consultant at Quiota LLC. He began his career as a quantitative developer at Lehman Brothers. He is a Professor of Analytics at the University of San Francisco and has held appointments at Stanford University and UC Davis.  Matthew holds a Ph.D. in Applied Math from Imperial College and a M.Sc. in Parallel Computing from Reading University. He is a chartered financial risk manager.

 

zubairF

Mohammad Zubair is a professor of Computer Science at Old Dominion University. He has over twenty years of research experience both at the university as well as in Industry.  Zubair has extensive experience with a variety of parallel programming environments and specializes in designing cost-effective strategies for large scale financial computations.