tests/cuda4.1sdk/tests/BlackScholes/BlackScholes_gold.cpp
static void BlackScholesBodyCPU(
    float& callResult,
    float& putResult,
    float Sf, //Stock price
    float Xf, //Option strike
    float Tf, //Option years
    float Rf, //Riskless rate
    float Vf  //Volatility rate
){
    double S = Sf, X = Xf, T = Tf, R = Rf, V = Vf;

    double sqrtT = sqrt(T);
    double    d1 = (log(S / X) + (R + 0.5 * V * V) * T) / (V * sqrtT);
    double    d2 = d1 - V * sqrtT;
    double CNDD1 = CND(d1);
    double CNDD2 = CND(d2);

    //Calculate Call and Put simultaneously
    double expRT = exp(- R * T);
    callResult   = (float)(S * CNDD1 - X * expRT * CNDD2);
    putResult    = (float)(X * expRT * (1.0 - CNDD2) - S * (1.0 - CNDD1));
}
///////////////////////////////////////////////////////////////////////////////
// Black-Scholes formula for both call and put
///////////////////////////////////////////////////////////////////////////////
Black-Scholes formula for both call and put
Black - Scholes formula for both call and put
static void BlackScholesBodyCPU(
    float& callResult,
    float& putResult,
    float Sf, 
    float Xf, 
    float Tf, 
    float Rf, 
    float Vf  
){
    double S = Sf, X = Xf, T = Tf, R = Rf, V = Vf;
    double sqrtT = sqrt(T);
    double    d1 = (log(S / X) + (R + 0.5 * V * V) * T) / (V * sqrtT);
    double    d2 = d1 - V * sqrtT;
    double CNDD1 = CND(d1);
    double CNDD2 = CND(d2);
    double expRT = exp(- R * T);
    callResult   = (float)(S * CNDD1 - X * expRT * CNDD2);
    putResult    = (float)(X * expRT * (1.0 - CNDD2) - S * (1.0 - CNDD1));
}
static void BlackScholesBodyCPU ( float & callResult , float & putResult , float Sf , float Xf , float Tf , float Rf , float Vf ) { double S = Sf , X = Xf , T = Tf , R = Rf , V = Vf ; double sqrtT = sqrt ( T ) ; double d1 = ( log ( S / X ) + ( R + 0.5 * V * V ) * T ) / ( V * sqrtT ) ; double d2 = d1 - V * sqrtT ; double CNDD1 = CND ( d1 ) ; double CNDD2 = CND ( d2 ) ; double expRT = exp ( - R * T ) ; callResult = ( float ) ( S * CNDD1 - X * expRT * CNDD2 ) ; putResult = ( float ) ( X * expRT * ( 1.0 - CNDD2 ) - S * ( 1.0 - CNDD1 ) ) ; }
Black-Scholes formula for both call and put
Black - Scholes formula for both call and put
//Stock price //Option strike //Option years //Riskless rate //Volatility rate //Calculate Call and Put simultaneously