| 25 | } |
| 26 | |
| 27 | static void black_scholes(array& C, array& P, const array& S, const array& X, |
| 28 | const array& R, const array& V, const array& T) { |
| 29 | // This function computes the call and put option prices based on |
| 30 | // Black-Scholes Model |
| 31 | |
| 32 | // S = Underlying stock price |
| 33 | // X = Strike Price |
| 34 | // R = Risk free rate of interest |
| 35 | // V = Volatility |
| 36 | // T = Time to maturity |
| 37 | |
| 38 | array d1 = log(S / X); |
| 39 | d1 = d1 + (R + (V * V) * 0.5) * T; |
| 40 | d1 = d1 / (V * sqrt(T)); |
| 41 | |
| 42 | array d2 = d1 - (V * sqrt(T)); |
| 43 | |
| 44 | array cnd_d1 = cnd(d1); |
| 45 | array cnd_d2 = cnd(d2); |
| 46 | |
| 47 | C = S * cnd_d1 - (X * exp((-R) * T) * cnd_d2); |
| 48 | P = X * exp((-R) * T) * (1 - cnd_d2) - (S * (1 - cnd_d1)); |
| 49 | } |
| 50 | |
| 51 | int main(int argc, char** argv) { |
| 52 | try { |