# Parallel Computing For Finance

Technology is making inroads into every sector of the economy; the financial industry too is no stranger to technology. Financial industry has always been at the forefront when it comes to adopting innovation. Organizations globally are looking at technology as an enabler to reach their strategic goals. Thus, making the most efficient use of the available system infrastructure is vital. Parallel computing is one such idea which enables us to leverage the power of computing for our applications. This concept has been around for some time now, however, off-late with rising computing demand from big data, increasing complexity of financial models etc. has led Banks and Financial Institutions to explore parallel computing in a big way.

Most modern computers CPUs (Central Processing Units) are equipped with multicore features (eg: we frequently come across processor specifications which say that a certain processor is dual core/quad core etc.). The idea of ** parallel computing** involves efficiently using the computational power of your system to accomplish complex tasks in a shorter period of time. There are numerous applications in finance that can leverage the power of parallel computing for efficiently accomplishing a certain objective. Out of the many applications, one specific application from finance that come to my mind is

**, that happens to greatly benefit from usage of parallel computing technique. Monte Carlo simulations are extremely versatile and are adopted for implementing a host of financial applications including**

*Monte Carlo simulations**product*

*pricing, value at risk, interest rate modelling etc*.

This post comprises of two parts. In the first part we will understand the meaning of parallel computing. In the second part, we will implement an option pricing engine using the power of parallel processing.

**Serial Computing Vs Parallel Computing:**

Imagine that there is a task called as ** X** that you need to execute. Further, there are 4 sub-tasks namely

**under the main task**

*m, n, o, p***. So, for our system to execute the task X, it needs to implement each of the aforesaid sub tasks. Also, lets assume we have a processor that has 4 cores.**

*X***a) Serial computing:**

This type of processing implies that we execute one sub task at a time and only then can we begin with executing the next sub task. For instance, if the system is busy executing sub-task ** m, **it will not allow execution of any other sub-tasks

**unless the subtask at hand gets completed. Thus, in serial processing, the system will only execute one task at a time.**

*n, o, p***b) Parallel computing:**

This type of processing implies that we execute the sub tasks separately (i.e., in parallel) at the same time by leveraging the multicore available in the CPU. Thus, in parallel processing, the system will simultaneously begin to execute all the sub-tasks in one go. This results in the system not having to put other sub-tasks on hold while it executes a specific sub-task. Finally, we can collate the outputs of the four parallel paths i.e., the four sub-tasks and present it as one single system output.

In this post, we will be exploring how to apply the idea of parallel processing for a financial application.

**Parallel computing for Option pricing:**

Imagine we are implementing a computationally heavy activity like pricing an Option via monte carlo simulations, and we wish to simulate *1 million asset price paths* for pricing this product. If we decide to use the concept of serial processing, it is naturally expected to take a long time to execute. We can reduce the execution time by using the idea of parallel processing and extract the model output faster. Let’s understand how to implement this idea!

We are pricing a European Call Option using the approach of Monte Carlo simulation. We are applying the **Euler’s approximation **for pricing this product. Euler’s approximation will allow us to derive the asset price paths in one stroke. This is an acceptable approach for pricing plain vanilla European options.

Below are the steps for implementing this algorithm using Python:

- Import the required libraries to be used for this implementation

Python interpreter by default follows a GIL (i.e. Global Interpreter Lock) logic, so as to avoid conflicts between multiple threads. Under this, the interpreter executes only one statement at a time.

In this post, we will be using the *multiprocessing* library which will enable is to spawn multiple sub processes and speed up our parallel computation operation.

2) Option trade inputs. We are assuming a hypothetical option contract to be priced. Further, we define the number of iterations (i.e., the number of simulation paths) over which the option will be priced. We will simulate 1 million asset price paths as mentioned previously.

3) We define a function to hold the random number generator. We will draw the random numbers from a standard normal distribution. We are attempting to utilize the multiple CPU cores that are available in our processor. The number of processor cores to be put to use for parallel computing is done via *mp.cpu_count()* function. The *Pool class* will be used for generating the parallel computing logic.

Firstly, we create the object of class Pool. There are multiple functions available to use with this Pool class’s object. We will use the *pool.apply*** **function to collate the paths generated.

4) The simulated asset price paths are then used in the Euler’s approximation formula. We subsequently take the average payoff across all paths to get the option price

I did some basic scenario testing at my end by varying the number of iterations i.e., number of simulations. The Option price was converging as expected.

In this post we have explored just one of the applications of parallel computing. There are many other applications in Finance that will find the usage of parallel processing to be very efficient. Especially, with organizations looking to ride the big data wave through use of advanced analytics like machine learning; parallel computing is expected to be adopted more and more not just in the financial industry, but in other industries as well. Languages like Python backed by their rich set of libraries supports rapid prototyping of such models.

****