Python for Finance: Analyze Big Financial Data

(Elle) #1

Monte Carlo Simulation


Monte Carlo simulation is one of the most important algorithms in finance and numerical


science in general. Its importance stems from the fact that it is quite powerful when it


comes to option pricing or risk management problems. In comparison to other numerical


methods, the Monte Carlo method can easily cope with high-dimensional problems where


the complexity and computational demand, respectively, generally increase in linear


fashion.


The downside of the Monte Carlo method is that it is per se computationally demanding


and often needs huge amounts of memory even for quite simple problems. Therefore, it is


necessary to implement Monte Carlo algorithms efficiently. The example that follows


illustrates different implementation strategies in Python and offers three different


implementation approaches for a Monte Carlo-based valuation of a European option.


[ 15 ]

The three approaches are:


[ 16 ]

Pure Python


This example sticks with the standard library — i.e., those libraries and packages that


come with a standard Python installation — and uses only built-in Python


capabilities to implement the Monte Carlo valuation.


Vectorized NumPy


This implementation uses the capabilities of NumPy to make the implementation more


compact and much faster.


Fully vectorized NumPy


The final example combines a different mathematical formulation with the


vectorization capabilities of NumPy to get an even more compact version of the same


algorithm.


The examples are again based on the model economy of Black-Scholes-Merton (1973),


where the risky underlying (e.g., a stock price or index level) follows, under risk


neutrality, a geometric Brownian motion with a stochastic differential equation (SDE), as


in Equation 3-5.


Equation 3-5. Black-Scholes-Merton (1973) stochastic differential equation


The parameters are defined as in Equation 3-1 and Z is a Brownian motion. A


discretization scheme for the SDE in Equation 3-5 is given by the difference equation in


Equation 3-6.


Equation 3-6. Euler discretization of SDE

Free download pdf