Add closed form Black-Scholes model

This commit is contained in:
Kevin
2017-09-17 16:58:11 -04:00
parent f749a22300
commit af10d6e9db
3 changed files with 63 additions and 1 deletions

View File

@@ -82,7 +82,33 @@ func (opt *Option) PriceMonteCarlo() {
opt.Delta = (opt.Delta/float64(opt.Sims)*df - opt.FV) / 0.0001
opt.Gamma = (opt.Gamma/float64(opt.Sims)*df - opt.FV) / 10000
opt.Vega = (opt.Vega/float64(opt.Sims)*df - opt.FV) / 0.01
opt.Theta = (opt.Theta/float64(opt.Sims)*math.Exp(-opt.Rfr*(tte-1./365)) - opt.FV) / -(1. / 365)
opt.Theta = (opt.Theta/float64(opt.Sims)*math.Exp(-opt.Rfr*(tte-1./365)) -
opt.FV) / -(1. / 365)
opt.Rho = (opt.Rho/float64(opt.Sims)*math.Exp(-(opt.Rfr+0.01)*tte) - opt.FV)
}
func (opt *Option) PriceClosedForm() {
var d1, d2, tte float64
tte = opt.ExpiryDate.Sub(opt.ValueDate).Hours() / (24 * 365)
d1 = (math.Log(opt.Spot/opt.Strike) + tte*(opt.Rfr+math.Pow(opt.Vol, 2)/2)) /
(opt.Vol * math.Pow(tte, 0.5))
d2 = d1 - (opt.Vol * math.Pow(tte, 0.5))
opt.FV = opt.Spot*NormCDF(d1*float64(opt.OptType))*float64(opt.OptType) -
opt.Strike*math.Exp(-opt.Rfr*tte)*
NormCDF(d2*float64(opt.OptType))*float64(opt.OptType)
opt.Delta = NormCDF(d1)
if opt.OptType == -1 {
opt.Delta -= 1
}
opt.Gamma = 1 / (opt.Vol * math.Sqrt(tte) * math.Sqrt(2*math.Pi)) *
math.Exp(-d1*d1/2)
opt.Vega = opt.Spot / 100 * math.Pow(tte, 0.5) * NormPDF(d1)
opt.Rho = float64(opt.OptType) * tte * opt.Strike * math.Exp(-opt.Rfr*tte) *
NormCDF(float64(opt.OptType)*d2) / 100
opt.Theta = -float64(opt.OptType)*(opt.Rfr*opt.Strike*math.Exp(-opt.Rfr*tte)*
NormCDF(float64(opt.OptType)*d1)) - (opt.Vol/2*math.Pow(tte, 0.5))*
opt.Spot*NormPDF(float64(opt.OptType)*d1)
}