Created
February 11, 2015 13:17
-
-
Save aussetg/0101cbdf775d26e707b7 to your computer and use it in GitHub Desktop.
bsc.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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