Skip to content

Instantly share code, notes, and snippets.

@aussetg
Created February 11, 2015 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aussetg/0101cbdf775d26e707b7 to your computer and use it in GitHub Desktop.
Save aussetg/0101cbdf775d26e707b7 to your computer and use it in GitHub Desktop.
bsc.cpp
double bsc(double x, double T, double K,double L, double r,double sigma) {
double lambda = (r+sigma*sigma*0.5)/(sigma*sigma) ;
double x1 = log(x/L)/(sigma*sqrt(T)) + lambda * sigma * sqrt(T) ;
double y1 = log(L/x)/(sigma*sqrt(T)) + lambda * sigma * sqrt(T) ;
double d1 = ( log(x/K) + (r+sigma*sigma*0.5)*T ) / (sigma * sqrt(T)) ;
double d2 = d1 - sigma * sqrt(T) ;
double y = log(L*L/(x*K)) / (sigma * sqrt(T)) + lambda * sigma * sqrt(T) ;
double cui = x * N(x1) - K * exp(-r*T) * N(x1 - sigma * sqrt(T)) - x * pow(L/x,2*lambda) * ( N(-y) - N(-y1) ) + K * exp(-r*T) * pow(L/x,2*lambda-2) * ( N(-y+sigma*sqrt(T)) - N(-y1 + sigma*sqrt(T)) ) ;
double c = x * N(d1) - K* exp(-r*T) * N(d2) ;
return(c - cui );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment