This repo contains an implementation of pricing financial derivatives using Monte Calo simulation with vectorization calculation. Generally speaking, computer program spend most of the time in loop process. Especially, Monte Carlo simulation(MCS) in finance is mainly composed of for-loop
or while-loop
.
The main purpose of this repo is to introduce the method for increasing performance of MCS using vectorization calculation. The program is performed by Python.
As I mentioned in Introduction
, loop
is the main reason for increasing cpu time. It means that the more the number of loop
and nested-loop
, the more programs spend more time. In most programs with numerical methods, one of role of loop
is to handle vector or matrix type data. To improve the performance of vector and matrix operation, several libraries has been developed such as Eigen-C++, Boost-C++, and Numpy-Python.
- CPU : Intel(R) Core(TM) i5-6400 @ 2.7GHZ
- RAM : DDR3L 16GB PC3-12800
- Python 2.7, numpy 1.10.4
- Test case : European vanilla call option
Stock | Strike | Maturity | Riskless interest rate |
Volatility | Number of simulations |
|
---|---|---|---|---|---|---|
Parameters | 100.0 | 100.0 | 1.0 | 0.03 | 0.3 | 105, 106, 107 |
- In this repo, I compare the cpu time(seconds) of three version for MCS using Numpy-Python. The parameters can be modified freely.
version 0
: Call random number function every timeversion 1
: Call random number function at a time such as(# of simulations × # of time steps)
version 2
: Vectorized path generation and call random number function at a time such as(# of simulations × # of time steps)
cpu time(sec) | 105simuls | 106simuls | 107simuls |
---|---|---|---|
version 0 | 0.1176 | 1.2223 | 11.6426 |
version 1 | 0.1354 | 1.3635 | 13.1086 |
version 2 | 0.0059 | 0.0726 | 0.7396 |
** Exact value of European call option: 13.28331
- If you're interested in my works, please email me.