Kalanand's December 2011 Log

   November 2011   
December 2011
SuMoTuWeThFrSa
    123
45678910
11121314151617
18192021222324
25262728293031
   January 2012   

December 8th

CERN MINUIT document

Weimin Wu pointed out this MINUIT ducument titled CERN Program Library Long Writeup D506 which was last modified in 2000. Amazing !

December 12th

Branch tag of RecoJet/JetAnalyzer for CMSDAS2012 jet exercises

Recipe from Sal Rappoccio:

Do
cvs up -r B4_2_X (bla)
then check in
cvs ci -m"Updates blablabla" bla
then tag.
cvs tag V00-05-06-12 (bla)

December 20th

Fermilab FTL via plain html

Much better than the Java-enabled one. Works in essentially every modern browser. Here is the access link

https://fermilab.kronoshosting.com/wfc09/applications/wtk/html/ess/logon.jsp

December 22nd

Black-Scholes equation

The option price, V (S, t), which is a function of time and the stock price, satisfies the following partial differential equation

∂V/∂t   +   ½σ2S2 . ∂2V/∂S2   +   rS . ∂V/∂S   −   rV = 0

where r = risk-free interest rate
          σ = standard deviation of the stock's returns (= volatility)

The solution for call and put option prices are

C(S, t)   =   N(d1) . S − N(d2) . X . e−r(T−t)
P(S, t)   =   −N(−d1) . S + N(−d2) . X . e−r(T−t)


where N(x)   =   (1/√(2π)) ∫x e−x2/2 dx   =   ∫x N'(x) dx
                     =   the standard normal cumulative distribution function
          X = strike price
          T−t = time to expiration
          d1 = (1/σ √(T−t)) [ ln(S/X) + (r + σ2/2) (T−t) ]
          d2 = (1/σ √(T−t)) [ ln(S/X) + (r − σ2/2) (T−t) ]
               = d1 − σ √(T−t)

C++ implementation of the Black-Scholes solution

#include<iostream>
#include<cmath>


// The cumulative normal distribution function
double CND( double X ) {

   return 0.5 * erfc(-X * M_SQRT1_2);
}


// The Black-Scholes formula: computes the price of a European style option 
double BlackScholes(char CallPutFlag, double S, double X, 
                    double T, double r, double v) {

   double d1 = (log(S/X) + (r+v*v/2)*T) / (v*sqrt(T));
   double 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);
   else return -1;
}


int main() {
   // Here is an example 
   double stock_price = 30.0;
   double strike = 32.0;
   double rate = 0.01; // annual risk-free interest rate 
   double time = 30.0/365; // 30 days 
   double v = 0.2; // 20% annual

   std::cout << "Call option price = " << 
      BlackScholes('c', stock_price, strike, time, rate, v) << std::endl;

   std::cout << "Put option price = " << 
      BlackScholes('p', stock_price, strike, time, rate, v) << std::endl;

   return 0;
}
Output:
Call option price = 0.00406919
Put option price = 1.97778

The Greeks

Delta   =   ∂V/∂S   =   N(d1) for calls,   −N(−d1) = N(d1) − 1 for puts

Gamma   =   ∂2V/∂S2   =   N'(d1) / ( Sσ √(T−t) )   for both calls and puts

Vega   =   ∂V/∂σ   =   S N'(d1) √(T−t)   for both calls and puts

Theta   =   ∂V/∂t   =   −S N'(d1) σ / (2√(T−t)) − rX e−r(T−t) N(d2)   for calls
                                   −S N'(d1) σ / (2√(T−t)) + rX e−r(T−t) N(−d2)   for puts

Rho   =   ∂V/∂r   =   X (T−t) e−r(T−t) N(d2)   for calls
                              −X (T−t) e−r(T−t) N(−d2)   for puts

In practice, rho is often reported divided by 10,000 (1 basis point rate change), vega by 100 (1 vol point change), and theta by 365 (1 day decay).

C++ implementation to compute the Greeks

// Function to compute Greeks 
void Greeks(char CallPutFlag, double S, double X, 
            double T, double r, double v, 
            double& delta, double& gamma, double& vega, 
            double& theta, double& rho) {
   
   double d1 = (log(S/X) + (r+v*v/2)*T) / (v*sqrt(T));
   double d2 = d1 - v * sqrt(T);
   
   delta = CND(d1); 
   if(CallPutFlag == 'p') delta -= 1.0;
 
   gamma = norm_pdf(d1) / (S * v *sqrt(T));

   vega = norm_pdf(d1) * S * sqrt(T);

   theta = -norm_pdf(d1) * S * v/(2*sqrt(T)) - r * X * exp(-r*T) * CND(d2);
   if(CallPutFlag == 'p') 
      theta = -norm_pdf(d1) * S * v/(2*sqrt(T)) + r * X * exp(-r*T) * CND(-d2);


   rho = X*T*exp(-r*T)*CND(d2);
   if(CallPutFlag == 'p') rho = -X*T*exp(-r*T)*CND(-d2);
}

int main() {

   double stock_price = 30.0;
   double strike = 32.0;
   double rate = 0.01; // annual risk-free interest rate 
   double time = 30.0/365; // 30 days 
   double v = 0.2; // 20% annual

  // Compute Greeks
   double delta, gamma, vega, theta, rho;
   Greeks('c', stock_price, strike, time, rate, v, 
          delta, gamma, vega, theta, rho);

   std::cout << "Call option" << std::endl;
   std::cout << "Delta = " << delta << ", Gamma = " << gamma 
             << ", Vega = " << vega << ", Theta = " << theta << ", Rho = " 
             << rho << std::endl; 

   Greeks('p', stock_price, strike, time, rate, v, 
          delta, gamma, vega, theta, rho);
   std::cout << "Put option" << std::endl;
   std::cout << "Delta = " << delta << ", Gamma = " << gamma 
             << ", Vega = " << vega << ", Theta = " << theta << ", Rho = " 
             << rho << std::endl; 

   return 0;
}
Output:
Call option
Delta = 0.139499, Gamma = 0.129079, Vega = 1.90966, Theta = -2.36408, Rho = 0.334178
Put option
Delta = -0.860501, Gamma = 0.129079, Vega = 1.90966, Theta = -2.04435, Rho = -2.2938

Resources

Go to November's log


Last modified: Mon Dec 12 17:35:32 CST 2011