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
.
#pragma omp for
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; }
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 |
|
|||
omp for: 3.7x | Intel(R) C++ Compiler 18.0 for Linux | -O3 -fp-model fast -xHost -ipo -qopenmp |
|
.sln
filePERF_NUM
Build.bat [perf_num]
perf_num
: collect performance numbers (will run example 5 times and take average time)Build.bat run [help|0|1|2|3|4]
Build.bat [perf_num]
perf_num
: collect performance numbers (will run example 5 times and take average time)Build.bat run
source <icc-install-dir>/bin/compilervars.sh {ia32|intel64}
make [icpc] [perf_num=1]
perf_num=1
: collect performance numbers (will run example 5 times and take average time)make run [option=help|0|1|2|3|4]
make gcc [perf_num=1]
perf_num=1
: collect performance numbers (will run example 5 times and take average time)make run