MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / black_scholes

Function black_scholes

examples/financial/black_scholes_options.cpp:27–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25}
26
27static 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
51int main(int argc, char** argv) {
52 try {

Callers 1

mainFunction · 0.85

Calls 4

logFunction · 0.85
sqrtFunction · 0.85
expFunction · 0.85
cndFunction · 0.70

Tested by

no test coverage detected