Fix Gamma and cap the number of simulations at 10M

This commit is contained in:
Kevin
2017-09-17 22:42:34 -04:00
parent a80e891037
commit 6b56699280
2 changed files with 14 additions and 7 deletions

View File

@@ -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)
}

View File

@@ -21,6 +21,12 @@ func index(w http.ResponseWriter, r *http.Request) {
json.Unmarshal(body, &bsOpt)
json.Unmarshal(body, &mcOpt)
// Cap the number of simulations at 10M
if bsOpt.Sims > 1e7 || mcOpt.Sims > 1e7 {
bsOpt.Sims = 1e7
mcOpt.Sims = 1e7
}
mcOpt.PriceMonteCarlo()
bsOpt.PriceClosedForm()