AI applications in Quantitative Finance - MATLAB
Video length is 20:49

AI applications in Quantitative Finance

Overview

Many financial applications are looking to incorporate machine learning techniques including risk classification, economic analysis, credit scoring, time series forecasting, estimating default probabilities, data mining and document generation. However, implementing and comparing machine learning techniques to choose the best method can be challenging.  Furthermore, it can be costly and time-consuming process to develop and maintain AI models. MATLAB minimizes these challenges by providing you with built-in functions and tools.

In this webinar, we will introduce how to build AI models with MATLAB through various machine learning, and deep learning examples in MATLAB. We will demonstrate MATLAB features that simplify the procedures so that the financial institutions can reduce costs, increase efficiency, and provide better outcomes for customers.

Highlights

  • Use ChatGPT to generate financial documentation through the web application
  • Compare Monte Carlo Methods with Neutral Networks on barrier option pricing
  • Build Deep learning LSTM models for sequence/time series data

About the Presenter

Dr. Yuchen Dong is a Senior Application Engineer at MathWorks focusing on customers in the Financial Services industry. His focus areas are financial instruments, portfolio optimization, and risk management. Before joining the MathWorks, Yuchen worked as a derivative valuation analyst. He holds a Ph.D. in mathematical sciences at Worcester Polytechnic Institute.

Recorded: 29 Aug 2023

Hi, everyone. Thank you for joining this webinar. My name is Yuchen, application engineer in computational finance from MathWorks. In this webinar, we will focus on artificial intelligence applications in quant finance, discuss several financial examples using neural networks in MATLAB.

We usually receive questions from our users. For example, the analysts are not AI experts, they are quantitative experts. How can they apply deep learning to their financial applications? Sometimes data scientists use Python. The current models are built in MATLAB. How can the teams work on the integration together?

Let's see how MATLAB answers these questions. MATLAB has hundreds of examples of AI being used in domain specific applications in the production environment. MATLAB can also work with Python. We will show this demo today. We will cover two main topics in this webinar. Recently many financial companies are using AI techniques on asset management. In the first part, we will introduce how to create AI models in MATLAB.

We will focus on barrier option pricing in neural networks, time series prediction using long short term memory. Then we will introduce how to call models from AI user community. One used one is ChatGPT. The other is to call Python Git models for synthetic data generation. Here is our AI system design workflow, as you see on the screen. Success with AI requires more than training AI model, especially in AI driven systems that make decisions and take actions.

A solid AI workflow involves preparing the data, creating a model, designing the system on which the model will run, and deploying to hardware or enterprise system. When things are working as good as we like, iterate over and over until we match the requirements. We will focus on AI modeling part today.

There are different areas of AI applications, such as medical imaging, automated driving, robotics. MathWorks has many successful stories on supporting AI applications in different industries, including finance. Let's move forward to our first example. Use neural network on barrier option pricing. The barrier option is an option where the payoff depends on whether the underlying assets crossed a predetermined trigger value during the life of the option.

Barrier options are widely traded because they are less expensive than the corresponding vanilla options. It is also the key component of more complicated financial instruments, such as accumulator. One of the key applications of neural networks in MATLAB is to find the price of OTC deals, such as barrier options, shown in this example.

In classic way, barrier option is calculated in Monte Carlo simulations. Given the model and parameter values, we simulate thousands of paths to simulate the dynamics of underlying assets. Then we take the mean value of the discounted payoff. Recall that once the parameter inputs and the model changes a little bit, it requires a new set of simulations. It is very time consuming.

Here we introduce a new idea on using neural networks on option pricing. Given the historical data on parameter inputs and past option price, we build a neural networks model to bridge the relationship between them. The core benefits of using neural networks is to obtain the barrier option price with less computational time versus Monte Carlo simulation.

In this demo, it shows the workflow on how to use deep learning toolbox to train a neural network and compare predictions on barrier option price with a Heston model. Let's switch to MATLAB. Instead of using the basic Black-Scholes models, and here we use Heston model. It has to model. The volatility is no longer assumed to be constant. The volatility can also be changed by time.

In the first part we use the classic quasi Monte Carlo simulation to calculate the option price. Each option requires simulating 1,000 paths. It costs 0.46 seconds to simulate one path. If we want to price 30,000 barrier options it costs approximately four hours to compute. However, the AI techniques reduce the recurring time cost significantly.

The second part of this demo is to utilize the neural network framework on barrier option pricing. Once the neural network is designed, then we can visualize the networks in MATLAB Network Designer. We can easily drag the layer component from the layer library. We can also set up several predetermined networks for use. By clicking each layer, for example here, fully connected layer, you can figure out and change the properties of each layer.

You can set up the training options. These values are critical to our model performance. It is easy to use MATLAB Experiment Manager app to tune training options programmatically. Here is a video to show how to interactively build experiments to fine tune and compare deep learning networks using MATLAB Experiment Manager app with no extra coding.

You can also have the GPU option to accelerate the training speed. It is easy to uncomment these GPU settings here. You don't need to change any written code. Avoid waiting for the training. Here is the screenshot for the training progress. We can monitor root or mean square error at each epoch and iteration in the training progress.

It will cost several minutes to train your networks. However, once the network is trained, these 30,000 options can be calculated in only 0.7 seconds. The mean square error is around 10 to the negative 6. We can visualize the error distribution. The error of most options is around zero. We can also compare the predictions on test data versus the actual price as well.

In this demo, we directly build neural networks between option features and the option price. In addition to classic models and methodologies, like tree models analytic methods, the deep learning neural networks can be another way to find the market values with less computational time. Another benefit of this approach is being able to compute grids from trained and neural networks. The following link will navigate you to the code and the videos on Experiment Manager app.

In the previous demo, we used a forward neural networks. In MATLAB we also predefine various sets of layers. For sequential data there is a special type of recurrent neural network, which is called long short term memory network. It is capable of learning long term dependency. Next, let's move to the financial time series analysis.

LSTM works better if we are dealing with huge amounts of data with non-linear pattern. LSTM can learn complex relationships between variables and adapt to changing dynamics. The classic statistical method, such as ARIMA, are generally better suited for capturing linear patterns in the data. There could be also other methods such as transformers, however, LSTM is still widely used.

Another key difference is about memory and long term dependency. From the structure of LSTM, it has a built in memory mechanism that allows it to remember information from past timesteps, making it effective for modeling long term dependency in time series data. ARIMA model is difficult to capture long term dependency. The figure here is a magnified LSTM unit called memory cell. Each memory cell contains three gates controlling how much information should be kept in memory, forgotten, and passed on as cell output.

This demo is to show how to apply LSTM networks to predict the time series. In this demo, we got the daily nominal bond US dollar index using MATLAB Data V Toolbox. We will predict the trend on this index. The prediction can also be used in further trading strategy analysis. Let's first work on data preprocessing. We can retrieve data from online thread data sources.

From this plot, we can see that there are several missing values in the sequence. The data cleaning is crucial to ensuring accurate analysis, building high quality models, and ultimately leads to more reliable insights and decision making. Here we will remove these missing values. You can also fill values with different rules like nearest values, mean values, depending on the sequence.

We can use the data cleaning live task to make the phrase faster and more informative so that you can focus on your analysis and problem solving. We can click Task here and claim the missing data. We select the data input and the cleaning method.

For simplicity, we will remove all these missing values. There could be also other methods of filling the missing values, such as linear interpolation. Remove missing. For the live task, we detect there are 162 missing entries. Remove them and generate a vector of acclaimed data.

Additionally, we split the data set into training and testing. In the Deep Network Designer, we use the LSTM layer here. There are also several predefined layers, like convolution layers, layers for the sequential data, or activation layers. We do the same procedure as the previous demo, set up the training options and then train the networks.

Compare the performance on the training data and the test data. We can see from the figure the time series fit well for both training and test data. The error for the test data is around 0.41. In the first part of our webinar, we have shown how to build AI models in MATLAB, applied in asset management or time series analysis.

The second part of today's webinar is to call models from the AI user community. MathWorks is seeing a lot of interest in using large language models, like ChatGPT, with MATLAB. One example of something we've been building is the AI chat playground, which gives you a familiar chat interface with some integration with a MATLAB Editor where you can add it and run the code. This is a web app you can go into interactive with AI chat bot. All you need is a MathWorks account to be able to log in and use it.

You can type the message here. For example, we want to build a simple linear regression model. Use AI a chat bot to generate MATLAB code first. You can run the code to see if it is correct. We will be making this publicly for folks to experiment with soon, and we will be happy if you could try it and provide feedback.

In the financial application, we sometimes will have imbalanced data set with increased difficulties on data analysis. One of the statistics solution is resampling, like Smote. Another possible way is to generate synthetic data using neural networks, specifically generative adversarial networks. Let's first see how MATLAB works with Python. We can use Python interface to call Python from MATLAB to access any AI frameworks and networks.

On the other hand, we can use MATLAB engine in Python to reuse the domain specific processing. In this demo, we apply the multi time series simulation GaN to simulate the future indices values. GaN consists of two main components, generator network and the discriminator network. Ideally, the generator reaches a point where it generates samples that are indistinguishable from real data, according to the discriminator.

Using Python with MATLAB allows users to combine the benefits of both. The code for this is not posted. If you are interested in this, please contact me. I will list my email at the end. In this live script, we first import historical data for indices in different markets, including equity market, real estate market, emerging market. Our goal is to simulate the future values given the historical data.

In MATLAB, we have parsing function, which use the mean and covariance information with geometric Brownian motion assumptions on indices. Instead of using SDG simulations, we use the neural networks to simulate the future values. GaN doesn't require distribution assumptions. In this algorithm, we call Python API from MATLAB. The MTSS GaN is built in Python. From GitHub, the generated data are passed into MATLAB and can be easily visualized in MATLAB.

Let's take US equity market data as an example. In this plot, the first part are the original historical data, and the second part is one path of generated data. Once the model is trained, you could generate more paths in seconds. The simulated paths can be used in different areas, such as backtesting your portfolio. Here we use it to manage market risk.

We set up the confidence level, 95%, and then 99%. Use normal assumption to estimate the value at risk from MATLAB Risk Management Toolbox. As plots show, before the year of 2019, value at risk is estimated by given data, and in the year of 2019, the value at risk is calculated by our generated data. The workflow can also be used if you would like to apply other available building algorithms from open communities.

In this webinar, we focus on how to utilize MATLAB Deep Learning Toolbox in finance. We demonstrate how to easily create AI models in finance using deep learning neural networks architecture for both derivative valuation and time series analysis. We can visualize the network architecture from Network Designer. It is also easy to tune the training options or neural network models in Experiment Manager app.

In a second part we showed how to call models from the AI user community easily, AI chat playground, and used GaN to generate sensitive financial time series data. If you are interested in other financial examples in AI, you can explore other neural networks, architectures, and examples through our documentation. Recall this is MATLAB design workflow. For each step, MATLAB has different tools to support.

Today we focus on AI modeling part. If you would like to explore more, please contact us. We can share more information based on your request. We have Onramp training courses on AI. No download or installation needed. Just browsers. You will learn from these self-paced online courses with step by step instructions in couple of hours. Thank you for your attention and thank you for joining this webinar. Please feel free to contact us. Here is my contact information. Thanks.

Related Products

View more related videos