Fix exported struct fields
This commit is contained in:
98
models.go
98
models.go
@@ -25,24 +25,24 @@ func (t RFC8601Time) MarshalJSON() ([]byte, error) {
|
||||
// Option struct that holds all the details of an option
|
||||
// Option details
|
||||
type Option struct {
|
||||
optType int64
|
||||
strike float64
|
||||
expiryDate RFC8601Time
|
||||
OptType int64
|
||||
Strike float64
|
||||
ExpiryDate RFC8601Time
|
||||
|
||||
// Market data
|
||||
valueDate RFC8601Time
|
||||
spot float64
|
||||
rfr float64
|
||||
vol float64
|
||||
sims int64
|
||||
ValueDate RFC8601Time
|
||||
Spot float64
|
||||
Rfr float64
|
||||
Vol float64
|
||||
Sims int64
|
||||
|
||||
// Results
|
||||
fv float64
|
||||
delta float64
|
||||
vega float64
|
||||
rho float64
|
||||
gamma float64
|
||||
theta float64
|
||||
FV float64
|
||||
Delta float64
|
||||
Vega float64
|
||||
Rho float64
|
||||
Gamma float64
|
||||
Theta float64
|
||||
}
|
||||
|
||||
// Single simulation of Geometric Brownian Motion
|
||||
@@ -62,46 +62,46 @@ func RunSimulations(opt *Option) {
|
||||
var i int64
|
||||
var level float64
|
||||
|
||||
levels := make([]float64, opt.sims)
|
||||
levels := make([]float64, opt.Sims)
|
||||
|
||||
tte := opt.expiryDate.Sub(opt.valueDate).Hours() / (24 * 365)
|
||||
tte := opt.ExpiryDate.Sub(opt.ValueDate).Hours() / (24 * 365)
|
||||
|
||||
for i = 0; i < opt.sims; i++ {
|
||||
for i = 0; i < opt.Sims; i++ {
|
||||
randNum := rand.NormFloat64()
|
||||
// Base
|
||||
levels[i] = gbmSimulation(opt.spot, opt.rfr, opt.vol, tte, randNum)
|
||||
opt.fv += math.Max((levels[i]-opt.strike)*float64(opt.optType), 0)
|
||||
levels[i] = gbmSimulation(opt.Spot, opt.Rfr, opt.Vol, tte, randNum)
|
||||
opt.FV += math.Max((levels[i]-opt.Strike)*float64(opt.OptType), 0)
|
||||
|
||||
// Delta
|
||||
level = gbmSimulation(opt.spot+0.0001, opt.rfr, opt.vol, tte, randNum)
|
||||
opt.delta += math.Max((level-opt.strike)*float64(opt.optType), 0)
|
||||
level = gbmSimulation(opt.Spot+0.0001, opt.Rfr, opt.Vol, tte, randNum)
|
||||
opt.Delta += math.Max((level-opt.Strike)*float64(opt.OptType), 0)
|
||||
|
||||
// Gamma -- TODO: Doesn't look right
|
||||
level = gbmSimulation(opt.spot+0.0001, opt.rfr, opt.vol, tte, randNum)
|
||||
level += gbmSimulation(opt.spot-0.0001, opt.rfr, opt.vol, tte, randNum)
|
||||
level -= 2 * gbmSimulation(opt.spot, 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)
|
||||
level += gbmSimulation(opt.Spot-0.0001, opt.Rfr, opt.Vol, tte, randNum)
|
||||
level -= 2 * gbmSimulation(opt.Spot, opt.Rfr, opt.Vol, tte, randNum)
|
||||
opt.Gamma += math.Max((level-opt.Strike)*float64(opt.OptType), 0)
|
||||
|
||||
// Vega
|
||||
level = gbmSimulation(opt.spot, opt.rfr, opt.vol+0.0001, tte, randNum)
|
||||
opt.vega += math.Max((level-opt.strike)*float64(opt.optType), 0)
|
||||
level = gbmSimulation(opt.Spot, opt.Rfr, opt.Vol+0.0001, tte, randNum)
|
||||
opt.Vega += math.Max((level-opt.Strike)*float64(opt.OptType), 0)
|
||||
|
||||
// Theta
|
||||
level = gbmSimulation(opt.spot, opt.rfr, opt.vol, tte-1./365, randNum)
|
||||
opt.theta += math.Max((level-opt.strike)*float64(opt.optType), 0)
|
||||
level = gbmSimulation(opt.Spot, opt.Rfr, opt.Vol, tte-1./365, randNum)
|
||||
opt.Theta += math.Max((level-opt.Strike)*float64(opt.OptType), 0)
|
||||
|
||||
// Rho -- TODO: Doesn't look right
|
||||
level = gbmSimulation(opt.spot, opt.rfr+0.0001, opt.vol, tte, randNum)
|
||||
opt.rho += math.Max((level-opt.strike)*float64(opt.optType), 0)
|
||||
level = gbmSimulation(opt.Spot, opt.Rfr+0.0001, opt.Vol, tte, randNum)
|
||||
opt.Rho += math.Max((level-opt.Strike)*float64(opt.OptType), 0)
|
||||
}
|
||||
|
||||
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.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.rho = (opt.rho/float64(opt.sims)*math.Exp(-(opt.rfr+0.01)*tte) - opt.fv)
|
||||
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.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.Rho = (opt.Rho/float64(opt.Sims)*math.Exp(-(opt.Rfr+0.01)*tte) - opt.FV)
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -138,18 +138,18 @@ func main() {
|
||||
`,
|
||||
value.Format("2006-01-02"),
|
||||
"Call", "Call",
|
||||
opt.spot, opt.spot,
|
||||
opt.Spot, opt.Spot,
|
||||
expiry.Format("2006-01-02"), expiry.Format("2006-01-02"),
|
||||
opt.strike, opt.strike,
|
||||
opt.rfr*100, opt.rfr*100,
|
||||
opt.vol*100, opt.vol*100,
|
||||
opt.fv, opt.fv,
|
||||
opt.delta, opt.delta,
|
||||
opt.gamma, opt.gamma,
|
||||
opt.vega, opt.vega,
|
||||
opt.theta, opt.theta,
|
||||
opt.rho, opt.rho,
|
||||
opt.sims)
|
||||
opt.Strike, opt.Strike,
|
||||
opt.Rfr*100, opt.Rfr*100,
|
||||
opt.Vol*100, opt.Vol*100,
|
||||
opt.FV, opt.FV,
|
||||
opt.Delta, opt.Delta,
|
||||
opt.Gamma, opt.Gamma,
|
||||
opt.Vega, opt.Vega,
|
||||
opt.Theta, opt.Theta,
|
||||
opt.Rho, opt.Rho,
|
||||
opt.Sims)
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user