Theoretical Option Value Script

Discussion in 'Options' started by meanVelocity, Apr 24, 2014.

  1. Hi, I am looking for source code for a theoretical options value calculator/script in any platform language. I need a options theoretical value script for SierraChart to plot theoretical value, and can't find one... So, going to try to find one to convert! Anyone know of one?
     
  2. I did manage to find this... This look correct? As for volatility... Not sure what to do. Will synthetic Vix work? I don't need perfect accuracy... Just something that follows close to theoretical.

    Code:
    //S= Stock price
    
    //X=Strike price
    
    //T=Years to maturity
    
    //r= Risk-free rate
    
    //v=Volatility
    
    //The Black-Scholes Model is a formula for calculating the fair value of an option contract, where an option is a derivative whose value is based on some underlying asset.
     
    
    #ifndef Pi
    #define Pi 3.141592653589793238462643
    #endif
    
    // The Black and Scholes (1973) Stock option formula in C++
    double BlackScholes(char CallPutFlag, double S, double X, double T, double r, double v)
    {
    double d1, d2;
    
    
    d1=(log(S/X)+(r+v*v/2)*T)/(v*sqrt(T));
    d2=d1-v*sqrt(T);
    
    if(CallPutFlag == 'c')
    return S *CND(d1)-X * exp(-r*T)*CND(d2);
    else if(CallPutFlag == 'p')
    return X * exp(-r * T) * CND(-d2) - S * CND(-d1);
    }
    
    // The cumulative normal distribution function
    double CND( double X )
    {
    
    double L, K, w ;
    
    double const a1 = 0.31938153, a2 = -0.356563782, a3 = 1.781477937;
    double const a4 = -1.821255978, a5 = 1.330274429;
    
    L = fabs(X);
    K = 1.0 / (1.0 + 0.2316419 * L);
    w = 1.0 - 1.0 / sqrt(2 * Pi) * exp(-L *L / 2) * (a1 * K + a2 * K *K + a3 * pow(K,3) + a4 * pow(K,4) + a5 * pow(K,5));
    
    if (X < 0 ){
    w= 1.0 - w;
    }
    return w;
    } 
     
  3. 2rosy

    2rosy

  4. SIUYA

    SIUYA

  5. what.the

    what.the