Fix Gamma and cap the number of simulations at 10M
This commit is contained in:
15
models.go
15
models.go
@@ -47,6 +47,7 @@ func (opt *Option) PriceMonteCarlo() {
|
||||
opt.Levels = make([]float64, opt.Sims)
|
||||
|
||||
tte := opt.ExpiryDate.Sub(opt.ValueDate).Hours() / (24 * 365)
|
||||
rand.Seed(time.Now().UTC().UnixNano())
|
||||
|
||||
for i = 0; i < opt.Sims; i++ {
|
||||
randNum := rand.NormFloat64()
|
||||
@@ -60,11 +61,11 @@ func (opt *Option) PriceMonteCarlo() {
|
||||
|
||||
// Gamma -- TODO: Doesn't look right
|
||||
level = gbmSimulation(opt.Spot+0.0001, opt.Rfr, opt.Vol, tte, randNum)
|
||||
opt.Gamma += math.Max((level - opt.Strike) * float64(opt.OptType), 0)
|
||||
level += gbmSimulation(opt.Spot-0.0001, opt.Rfr, opt.Vol, tte, randNum)
|
||||
opt.Gamma += math.Max((level - opt.Strike) * float64(opt.OptType), 0)
|
||||
level -= 2 * gbmSimulation(opt.Spot, opt.Rfr, opt.Vol, tte, randNum)
|
||||
opt.Gamma += math.Max((level - opt.Strike) * float64(opt.OptType), 0)
|
||||
opt.Gamma += math.Max((level-opt.Strike)*float64(opt.OptType), 0)
|
||||
level = gbmSimulation(opt.Spot-0.0001, opt.Rfr, opt.Vol, tte, randNum)
|
||||
opt.Gamma += math.Max((level-opt.Strike)*float64(opt.OptType), 0)
|
||||
level = gbmSimulation(opt.Spot, opt.Rfr, opt.Vol, tte, randNum)
|
||||
opt.Gamma -= 2 * math.Max((level-opt.Strike)*float64(opt.OptType), 0)
|
||||
|
||||
// Vega
|
||||
level = gbmSimulation(opt.Spot, opt.Rfr, opt.Vol+0.0001, tte, randNum)
|
||||
@@ -82,10 +83,10 @@ func (opt *Option) PriceMonteCarlo() {
|
||||
df := math.Exp(-opt.Rfr * tte)
|
||||
opt.FV = opt.FV / float64(opt.Sims) * df
|
||||
opt.Delta = (opt.Delta/float64(opt.Sims)*df - opt.FV) / 0.0001
|
||||
opt.Gamma = (opt.Gamma/float64(opt.Sims)*df - opt.FV) / 10000
|
||||
opt.Gamma = opt.Gamma / float64(opt.Sims) * df / 1e-8
|
||||
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.FV) / (1. / 365)
|
||||
opt.Rho = (opt.Rho/float64(opt.Sims)*math.Exp(-(opt.Rfr+0.01)*tte) - opt.FV)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user