**Simulation of correlated random walks for a basket of stocks using Python**

**Background**

In many quantitative finance applications, we frequently generate random walks to build the path of a certain asset that follows a stochastic process. By far the most popular model for simulation of a stochastic process is the geometric Brownian motion (GBM) for simulating the path of a single equity stock. There could be instances that require generation of correlated random walks for building a set of asset price paths for a **basket of securities**. The idea of the basic GBM model can be extended to accommodate the requirement for simulation of paths for a basket of assets. Common applications of simulated correlated processes may include a *basket linked debenture* wherein the payoff of the product is a function of a bunch of underlying assets. The aforesaid basket linked debenture is a hybrid product [it’s a bond (to provide capital protection) + option whose payoff is a function of a basket of underlying]; a very popular product that financial institutions sell to their wealthy investors.

This article discusses a 4 asset case. We define correlation matrix, further, we will briefly discuss Cholesky decomposition along the way, as it plays an important role in generation of correlated random processes. We will implement the same via Python programming, so that we have a model for simulation of basket of assets.

**Overview of the math behind the asset simulation process**

We focus on the stock price random walk given as below:

S(t) = r*S*dt + σ*S*dz

Where, r: risk free rate; S: stock price; σ: volatility; dz: random term that can be discretized as φ*sqrt(dt) for modelling purposes.

The above process can be solved through Ito’s which takes us to a convenient formula for stock price simulation given as below. This is popularly also called as the *Euler-Maruyama method* for asset price simulation.

The above equation can be easily implemented in Python for a single stock. However, when we have a basket of stocks, the idea of *correlation* needs to be applied to the respective stochastic processes of the assets. This will ensure that we generate ** correlated random walks **which are necessary when we have a basket portfolio. We also leverage the idea of

**in order to build the simulation of a basket of stocks**

*Cholesky decomposition*

*.***Simulation of asset prices for a basket of securities**

Let’s assume four assets say A, B, C, D. We will use the idea of correlation matrix. This matrix helps us build a relationship between the respective assets. This is necessary because finally these four assets form a basket and their correlation needs to be modelled in the stochastic process.

The Cholesky decomposition is an effective way of solving for correlated processes. It is required that the matrix being decomposed be Hermitian and positive definite. This means that when the matrix M is decomposed as M = Q*Q(T) , Q is a lower triangular matrix with real and positive numbers on the diagonals, and Q(T) is the conjugate transpose of L.

Once we decompose the correlation matrix, we multiple Q with the vector of uncorrelated random numbers to get the correlated variables denoted by epsilons. We can then use these epsilons to generate the correlated random walks

We plug in required set of inputs including days to expiry, interest rate etc.

We use the correlated epsilons as below to simulate the stock price random walks

We can plot the simulated paths of the basket of 4 stocks

A quick check to see if we have got the Cholesky decomposition right. This is an important checkpoint because if the Cholesky workings are incorrect, they will adversely impact the basket of correlated random processes.

Since the above output matches the earlier computation, we can safely say that the Cholesky decomposition calculation is correct.

**Conclusion**

Correlated random processes are frequently used for pricing a variety of financial products. Using Python libraries it becomes a relatively easy exercise to build such correlated processes. There is a lot of literature available on Cholesky decomposition which is a central part in the exercise of generation of correlated random numbers. Interested readers may look up relevant resources to know more. There are multiple applications where correlated random numbers are used. On prominent example of usage of correlated processes is for pricing of index/basket linked products that financial institutions particularly NBFI’s offer to their clients.