mirror of
https://github.com/bspeice/Quant.jl
synced 2025-07-04 23:35:12 -04:00
Handle array inputs to black scholes
This commit is contained in:
@ -4,7 +4,9 @@
|
||||
# Designed to be a reference implementation of the Black-Scholes option
|
||||
# pricing formula, supporting the original formula and greeks calculation
|
||||
###
|
||||
using StatsFuns
|
||||
using Distributions
|
||||
|
||||
Φ = x -> cdf(Normal(0, 1), x)
|
||||
|
||||
"""
|
||||
Calculate the value of \$d_1\$ in the Black-Scholes Formula
|
||||
@ -21,12 +23,12 @@ function blackscholes_call(S, K, σ, r, T, t=0)
|
||||
d1_val = d1(S, K, σ, r, T, t)
|
||||
d2_val = d2(d1_val, σ, T, t)
|
||||
|
||||
return normcdf(d1_val) .* S - normcdf(d2_val) .* K .* exp(-r .* (T - t))
|
||||
return Φ(d1_val) .* S - Φ(d2_val) .* K .* exp(-r .* (T - t))
|
||||
end
|
||||
|
||||
function blackscholes_put(S, K, σ, r, T, t=0)
|
||||
d1_val = d1(S, K, σ, r, T, t)
|
||||
d2_val = d2(d1_val, σ, T, t)
|
||||
|
||||
return normcdf(-d2_val).*K.*exp(-r.*(T-t)) - normcdf(-d1_val).*S
|
||||
return Φ(-d2_val).*K.*exp(-r.*(T-t)) - Φ(-d1_val).*S
|
||||
end
|
||||
|
Reference in New Issue
Block a user