33 " var d1 := (log(s / x) + (r + v^2 / 2) * t) / (v * sqrt(t)); " 34 " var d2 := d1 - v * sqrt(t); " 36 " if (callput_flag == 'call') " 37 " s * ncdf(d1) - x * e^(-r * t) * ncdf(d2); " 38 " else if (callput_flag == 'put') " 39 " x * e^(-r * t) * ncdf(-d2) - s * ncdf(-d1); " 54 symbol_table.add_variable(
"x",
x);
55 symbol_table.add_variable(
"t",
t);
56 symbol_table.add_variable(
"r",r);
57 symbol_table.add_variable(
"v",v);
58 symbol_table.add_constant(
"e",
e);
59 symbol_table.add_stringvar(
"callput_flag",callput_flag);
65 parser.compile(bsm_model_program,expression);
68 callput_flag =
"call";
70 T bsm = expression.value();
72 printf(
"BSM(%s,%5.3f,%5.3f,%5.3f,%5.3f,%5.3f) = %10.6f\n",
81 T bsm = expression.value();
83 printf(
"BSM(%s,%5.3f,%5.3f,%5.3f,%5.3f,%5.3f) = %10.6f\n",
92 black_scholes_merton_model<double>();