-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathBS1.c
More file actions
34 lines (29 loc) · 907 Bytes
/
Copy pathBS1.c
File metadata and controls
34 lines (29 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "StdAfx.h"
#include "BS_HEADER.h"
CBlackScholes::CBlackScholes(void) { }
CBlackScholes::~CBlackScholes(void) { }
// Black Scholes prices
// Waissi and Rossin normal cdf approximation
double CBlackScholes::normcdf(double z) {
if (z <= -7.0)
return 0.0;
else if (z >= 7.0)
return 1.0;
else {
double pi = 3.141592653589793;
double b1 = -0.0004406;
double b2 = 0.0418198;
double b3 = 0.9;
return 1.0 / (1.0 + exp(-sqrt(pi)*(b1*pow(z,5.0) + b2*pow(z,3.0) + b3*z)));
}
}
// Black Scholes call or put price
double CBlackScholes::BSPrice(double S,double K,double r,double q,double v,double T,char PutCall) {
double d1 = (log(S/K) + (r-q+v*v/2.0)*T)/v/sqrt(T);
double d2 = d1 - v*sqrt(T);
double BSCall = S*exp(-q*T)*normcdf(d1) - K*exp(-r*T)*normcdf(d2);
if (PutCall=='C')
return BSCall;
else
return BSCall - S*exp(-q*T) + K*exp(-r*T);
}