# Recipe: Monte Carlo European Option Pricing for Intel® Xeon Phi® Processor

### Introduction

This is the second of a two document series. The first article, Monte Carlo European Option Pricing with RNG Interface for Intel® Xeon Phi™ Processor, covers the background of Monte Carlo methods, and details the random number generation interface with Intel® MKL. This article covers the Monte Carlo Methods using a simple quasi random number generator.

When the Monte Carlo method was first introduced, it was generally considered an inefficient algorithm because the results converge at the slow rate of the reciprocal of the square root of its problem size. In other words, to achieve 10 times improvement in accuracy, you have to process 100 times more samples. Since then, research has developed more efficient algorithms with faster converge rates and better variance control techniques. Moreover, the Monte Carlo method has become increasingly attractive, especially in quantitative finance, as computational power has improved at the rate of Moore’s law. As financial products have become increasingly complex, alternative methods have become intractable or simply do not exist. With the widely used parallel computing techniques, Monte Carlo has become the dominant method in the quantitative finance industry.

The first paper showing the use of Monte Carlo in quantitative finance was published in 1977. Since then, researchers have continually worked to improve Monte Carlo methods. Quasi-random numbers are used to achieve faster (1/N) converge rates, while antithetic sampling, control variate, and importance sampling have widely been used as variance reduction techniques so that Monte Carlo can converge faster with higher-quality results using limited samples. In our example, we show a variety of Monte Carlo methods using pre-generated quasi-random number sequence with all option data sharing the same random number sequence.

In this document, we will cover how to download, build, and run the code. Since the algorithm is the same as the one shown in the Monte Carlo with RNG interface document, we are not going to repeat the same technical detail here. However, we do include a section covering the computational consequence of sharing a large portion of memory among a large number of worker threads.

### Code Access

Monte Carlo European Option with Pre-Generated Random Numbers is maintained by Shuo Li and is available under the BSD 3-Clause Licensing Agreement. The code runs natively on Intel® Xeon Phi™ Processor in a single node environment.

To access the code and test workloads, go to the source location to download the MonteCarlor.tar file.

### Build and Run Directions

Here are the steps for rebuilding the program:

1. Install Intel® Composer XE 2016 SP 2 on your system.
2. Source the environment variable script file under
3. Untar the MonteCarlo.tar
4. Type make to build the binaries for Single and Double Precision
1. For Single Precision processing: mc_sp.knl
2. For Double Precision processing: mc_dp.knl
5. Make sure the host machine is powered by Intel® Xeon Phi™ Processors
```[sli@ortce-knl7 ~]\$ lscpu

Architecture:          x86_64

CPU op-mode(s):        32-bit, 64-bit

Byte Order:            Little Endian

CPU(s):                272

On-line CPU(s) list:   0-271

Core(s) per socket:    68

Socket(s):             1

NUMA node(s):          8

Vendor ID:             GenuineIntel

CPU family:            6

Model:                 87

Model name:            Intel(R) Xeon Phi(TM) CPU 7250 @ 1.40GHz

Stepping:              1

CPU MHz:               1400.273

BogoMIPS:              2793.61

Virtualization:        VT-x

L1d cache:             32K

L1i cache:             32K

L2 cache:              1024K

NUMA node0 CPU(s):     5,6,11,12,17,18,23-25,73-86,135-148,197-210,259-271

NUMA node1 CPU(s):     1,2,7,8,13,14,19,20,43-58,105-120,167-182,229-244

NUMA node2 CPU(s):     3,4,9,10,15,16,21,22,59-72,121-134,183-196,245-258

NUMA node3 CPU(s):     0,26-42,87-104,149-166,211-228For Double Precision processing: BlackScholesDP.kn```
6. Make sure the memory mode for Intel® Xeon Phi™ Processors is flat.

```	[root@heat2 ~]# syscfg /d biossettings "memory mode"
Memory Mode
===========
Current Value : Cache
---------------------
Possible Values
---------------
Cache : 00
Flat : 01
Hybrid : 02
Auto : 03```
7. Run mc_sp.knl under numactl;

Run mc_dp.knl in

```    ./mc_sp.knl 272 64k 256k 32k

[sli@ortce-knl8 clean]\$ ./mc_sp.knl 272 64k 256k 32k

Monte Carlo European Option Pricing in single Precision

Compiler Version  = 16

Release Update    = 3

Build Time       = May 27 2016 13:42:26

Path Length      = 262144

Number of Options= 17825792

Block Size       = 32768

Creating the reference result...

Initializing data...

Starting options pricing in vector and in parallel.

Validating the result...

L1_NORM          = 0.000003

AVERAGE RESERVE  = 373.299543

Max Error        = 0.000125

Max Error Index  = 9115049

==========================================

------------------------------------------

Total Cycles        = 31160576706

Total Time Elapsed  = 22.309222

Cyc/opt             = 1748.061273

Opt/sec             = 799032.436774

==========================================

[sli@ortce-knl8 clean]\$ ./mc_dp.knl 272 64k 256k 16k

Monte Carlo European Option Pricing in double Precision

Compiler Version  = 16

Release Update    = 3

Build Time       = May 27 2016 13:42:41

Path Length      = 262144

Number of Options= 17825792

Block Size       = 16384

Creating the reference result...

Initializing data...

Starting options pricing in vector and in parallel.

Validating the result...

L1_NORM          = 0.000003

AVERAGE RESERVE  = 374.828479

Max Error        = 0.000121

Max Error Index  = 7872518

==========================================

------------------------------------------

Total Cycles        = 54202703828

Total Time Elapsed  = 38.806089

Cyc/opt             = 3040.689790

Opt/sec             = 459355.541805

==========================================```
AttachmentSize
20 KB
For more complete information about compiler optimizations, see our Optimization Notice.