Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if ival is None:
ival = {'v0': 0.1, 'kappa': 1.0, 'theta': 0.1,
'sigma': 0.5, 'rho': -.5}
process = HestonProcess(
risk_free_ts, dividend_ts, spot, ival['v0'], ival['kappa'],
ival['theta'], ival['sigma'], ival['rho'])
model = HestonModel(process)
engine = AnalyticHestonEngine(model, 64)
for option in options:
option.set_pricing_engine(engine)
om = LevenbergMarquardt(1e-8, 1e-8, 1e-8)
model.calibrate(
options, om, EndCriteria(400, 40, 1.0e-8, 1.0e-8, 1.0e-8)
)
print('model calibration results:')
print('v0: %f kappa: %f theta: %f sigma: %f rho: %f' %
(model.v0, model.kappa, model.theta, model.sigma,
model.rho))
calib_error = (1.0 / len(options)) * sum(
[pow(o.calibration_error() * 100.0, 2) for o in options])
print('SSE: %f' % calib_error)
return merge_df(df_option, options, 'Heston')
ival = {'v0': v0, 'kappa': 3.7, 'theta': v0,
'sigma': 1.0, 'rho': -.6, 'lambda': .1,
'nu': -.5, 'delta': 0.3}
process = BatesProcess(
risk_free_ts, dividend_ts, spot, ival['v0'], ival['kappa'],
ival['theta'], ival['sigma'], ival['rho'],
ival['lambda'], ival['nu'], ival['delta'])
model = BatesDetJumpModel(process)
engine = BatesDetJumpEngine(model, 64)
for option in options:
option.set_pricing_engine(engine)
om = LevenbergMarquardt()
model.calibrate(
options, om, EndCriteria(400, 40, 1.0e-8, 1.0e-8, 1.0e-8)
)
print('BatesDetJumpModel calibration:')
print('v0: %f kappa: %f theta: %f sigma: %f\nrho: %f lambda: %f nu: %f \
delta: %f\nkappaLambda: %f thetaLambda: %f' %
(model.v0, model.kappa, model.theta, model.sigma,
model.rho, model.Lambda, model.nu, model.delta,
model.kappaLambda, model.thetaLambda))
calib_error = (1.0 / len(options)) * sum(
[pow(o.calibration_error(), 2) for o in options])
print('SSE: %f' % calib_error)
ival = {'v0': v0, 'kappa': 3.7, 'theta': v0,
'sigma': 1.0, 'rho': -.6, 'lambda': .1,
'nu': -.5, 'delta': 0.3}
process = BatesProcess(
risk_free_ts, dividend_ts, spot, ival['v0'], ival['kappa'],
ival['theta'], ival['sigma'], ival['rho'],
ival['lambda'], ival['nu'], ival['delta'])
model = BatesModel(process)
engine = BatesEngine(model, 64)
for option in options:
option.set_pricing_engine(engine)
om = LevenbergMarquardt()
model.calibrate(
options, om, EndCriteria(400, 40, 1.0e-8, 1.0e-8, 1.0e-8)
)
print('model calibration results:')
print('v0: %f kappa: %f theta: %f sigma: %f\nrho: %f lambda: \
%f nu: %f delta: %f' %
(model.v0, model.kappa, model.theta, model.sigma,
model.rho, model.Lambda, model.nu, model.delta))
calib_error = (1.0 / len(options)) * sum(
[pow(o.calibration_error(), 2) for o in options])
print('SSE: %f' % calib_error)
return merge_df(df_option, options, 'Bates')
ival = {'v0': v0, 'kappa': 3.7, 'theta': v0,
'sigma': .1, 'rho': -.6, 'lambda': .1,
'nu': -.5, 'delta': 0.3}
process = HestonProcess(
risk_free_ts, dividend_ts, spot, ival['v0'], ival['kappa'],
ival['theta'], ival['sigma'], ival['rho'])
model = BatesDoubleExpDetJumpModel(process, 1.0)
engine = BatesDoubleExpDetJumpEngine(model, 64)
for option in options:
option.set_pricing_engine(engine)
om = LevenbergMarquardt()
model.calibrate(
options, om, EndCriteria(400, 40, 1.0e-8, 1.0e-8, 1.0e-8)
)
print('BatesDoubleExpDetJumpModel calibration:')
print('v0: %f kappa: %f theta: %f sigma: %f\nrho: %f lambda: %f \
nuUp: %f nuDown: %f\np: %f\nkappaLambda: %f thetaLambda: %f' %
(model.v0, model.kappa, model.theta, model.sigma,
model.rho, model.Lambda, model.nuUp, model.nuDown,
model.p, model.kappaLambda, model.thetaLambda))
calib_error = (1.0 / len(options)) * sum(
[pow(o.calibration_error(), 2) for o in options])
print('SSE: %f' % calib_error)
# initial values for parameters
if ival is None:
ival = {'v0': 0.1, 'kappa': 1.0, 'theta': 0.1,
'sigma': 0.5, 'rho': -.5}
process = HestonProcess(
risk_free_ts, dividend_ts, spot, ival['v0'], ival['kappa'],
ival['theta'], ival['sigma'], ival['rho'])
model = HestonModel(process)
engine = AnalyticHestonEngine(model, 64)
for option in options:
option.set_pricing_engine(engine)
om = LevenbergMarquardt(1e-8, 1e-8, 1e-8)
model.calibrate(
options, om, EndCriteria(400, 40, 1.0e-8, 1.0e-8, 1.0e-8)
)
print('model calibration results:')
print('v0: %f kappa: %f theta: %f sigma: %f rho: %f' %
(model.v0, model.kappa, model.theta, model.sigma,
model.rho))
calib_error = (1.0 / len(options)) * sum(
[pow(o.calibration_error() * 100.0, 2) for o in options])
print('SSE: %f' % calib_error)
# merge the fitted volatility and the input data set
return merge_df(df_option, options, 'Heston')
if ival is None:
ival = {'v0': v0, 'kappa': 3.7, 'theta': v0,
'sigma': 1.0, 'rho': -.6, 'lambda': .1,
'nu': -.5, 'delta': 0.3}
process = HestonProcess(
risk_free_ts, dividend_ts, spot, ival['v0'], ival['kappa'],
ival['theta'], ival['sigma'], ival['rho'])
model = BatesDoubleExpModel(process)
engine = BatesDoubleExpEngine(model, 64)
for option in options:
option.set_pricing_engine(engine)
om = LevenbergMarquardt()
model.calibrate(
options, om, EndCriteria(400, 40, 1.0e-8, 1.0e-8, 1.0e-8)
)
print('BatesDoubleExpModel calibration:')
print('v0: %f kappa: %f theta: %f sigma: %f\nrho: %f lambda: %f \
nuUp: %f nuDown: %f\np: %f' %
(model.v0, model.kappa, model.theta, model.sigma,
model.rho, model.Lambda, model.nuUp, model.nuDown,
model.p))
calib_error = (1.0 / len(options)) * sum(
[pow(o.calibration_error(), 2) for o in options])
print('SSE: %f' % calib_error)
ival = {'v0': v0, 'kappa': 3.7, 'theta': v0,
'sigma': 1.0, 'rho': -.6, 'lambda': .1,
'nu': -.5, 'delta': 0.3}
process = BatesProcess(
risk_free_ts, dividend_ts, spot, ival['v0'], ival['kappa'],
ival['theta'], ival['sigma'], ival['rho'],
ival['lambda'], ival['nu'], ival['delta'])
model = BatesModel(process)
engine = BatesEngine(model, 64)
for option in options:
option.set_pricing_engine(engine)
om = LevenbergMarquardt()
model.calibrate(
options, om, EndCriteria(400, 40, 1.0e-8, 1.0e-8, 1.0e-8)
)
print('model calibration results:')
print('v0: %f kappa: %f theta: %f sigma: %f\nrho: %f lambda: \
%f nu: %f delta: %f' %
(model.v0, model.kappa, model.theta, model.sigma,
model.rho, model.Lambda, model.nu, model.delta))
calib_error = (1.0 / len(options)) * sum(
[pow(o.calibration_error(), 2) for o in options])
print('SSE: %f' % calib_error)
return merge_df(df_option, options, 'Bates')