Black-Scholes Sample

The Black-Scholes Equation estimates the price of a European option over time. The formula itself can be used in a number of ways, the most basic of which is to use the projected value to smartly hedge the option on its underlying asset. The simulation in this sample is auto-vectorized with the Intel® C++ compiler and parallelized with OpenMP* Worksharing construct #pragma omp for .

System Requirements:

Code Change Highlights:

#pragma omp for
linear version: (black_scholes.cpp, black_scholes_serial())
    for(int option = 0; option<OPT_N; ++option) {
        float T = OptionYears[option];
        float X = OptionStrike[option];
        float S = StockPrice[option];
        float sqrtT = sqrtf(T);
        float d1 = (logf(S / X) + (c_riskfree + c_half * c_volatility * c_volatility) * T) /
                   (c_volatility * sqrtT);
        float d2 = d1 - c_volatility * sqrtT;
#ifdef _WIN32
        float CNDD1 = CND(d1);
        float CNDD2 = CND(d2);
#else			
        float CNDD1 = c_half + c_half*erff(SQRT1_2*d1);
        float CNDD2 = c_half + c_half*erff(SQRT1_2*d2);
#endif
        float expRT = expf(-c_riskfree * T);

        CallResult[option] = S * CNDD1 - X * expRT * CNDD2;
        PutResult[option] = CallResult[option]  +  expRT - S;
    }
#pragma omp for version: (black_scholes.cpp, black_scholes_openmp())
#pragma omp parallel for
    for(int option = 0; option<OPT_N; ++option) {
        float T = OptionYears[option];
        float X = OptionStrike[option];
        float S = StockPrice[option];
        float sqrtT = sqrtf(T);
        float d1 = (logf(S / X) + (c_riskfree + c_half * c_volatility * c_volatility) * T) /
                   (c_volatility * sqrtT);
        float d2 = d1 - c_volatility * sqrtT;
#ifdef _WIN32
        float CNDD1 = CND(d1);
        float CNDD2 = CND(d2);
#else			
        float CNDD1 = c_half + c_half*erff(SQRT1_2*d1);
        float CNDD2 = c_half + c_half*erff(SQRT1_2*d2);
#endif
        float expRT = expf(-c_riskfree * T);

        CallResult[option] = S * CNDD1 - X * expRT * CNDD2;
        PutResult[option] = CallResult[option]  +  expRT - S;
    }

Performance Data:

Note: Modified Speedup shows performance speedup with respect to serial implementation.

Modified speedup Compiler (Intel® 64) Compiler options System specifications
omp for: 2.2x Intel(R) C++ Compiler 18.0 for Windows /O3 /Oi /fp:fast /QxHost /Qipo /Qopenmp
Microsoft Windows 10* (x64)
6th generation Intel® Core™ i5-6300U CPU @ 2.50GHz
8GB memory
omp for: 3.7x Intel(R) C++ Compiler 18.0 for Linux -O3 -fp-model fast -xHost -ipo -qopenmp
RHEL 7 (x64)
4rd Generation Intel Core™ i7-4790 CPU @ 3.60GHz
32GB memory

Build Instructions:

For Visual Studio users:
For Windows Command Line users:
For Linux*/OS X* users: