1
0
mirror of https://github.com/bspeice/Quant.jl synced 2025-07-01 22:07:18 -04:00
Files
Quant.jl/src/blackscholes.jl
2016-03-05 17:49:30 -05:00

55 lines
1.3 KiB
Julia
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

###
# Black-Scholes model functionality for Julia.
#
# Designed to be a reference implementation of the Black-Scholes option
# pricing formula, supporting the original formula and greeks calculation
###
using StatsFuns
"""
Calculate the value of $d_1$ in the Black-Scholes Formula
"""
d1 = function(σ, T, t, S, K, r)
return (σ .* sqrt(T-t)).^-1 * (log(S ./ K) + (r + σ.^2 / 2).*(T-t))
end
d1 = function(σ, T, S, K, r)
return d1(σ, T, 0, S, K, r)
end
d2 = function(d1_val, σ, T, t)
return d1_val - σ .* sqrt(T-t)
end
d2 = function(d1_val, σ, T)
return d2(d1_val, σ, T, 0)
end
blackscholes_call = function(σ, T, t, S, K, r)
d1_val = d1(σ, T, t, S, K, r)
d2_val = d2(d1_val, σ, T, t)
return normcdf(d1_val) .* S - normcdf(d2_val) .* K .* exp(-r .* (T - t))
end
blackscholes_call = function(σ, T, S, K, r)
d1_val = d1(σ, T, S, K, r)
d2_val = d2(d1_val, σ, T)
return normcdf(d1_val) .* S - normcdf(d2_val) .* K .* exp(-r .* T)
end
blackscholes_put = function(σ, T, t, S, K, r)
d1_val = d1(σ, T, t, S, K, r)
d2_val = d2(d1_val, σ, T, t)
return normcdf(-d2_val).*K.*exp(-r.*(T-t)) - normcdf(-d1).*S
end
blackscholes_put = function(σ, T, S, K, r)
d1_val = d1(σ, T, S, K, r)
d2_val = d2(d1_val, σ, T)
return normcdf(-d2_val).*K.*exp(-r.*T) - normcdf(-d1).*S
end