示例#1
1
def bates_calibration(df_option, ival=None):
    """
    calibrate bates' model
    """

    tmp = make_helpers(df_option)

    risk_free_ts = tmp['risk_free_rate']
    dividend_ts = tmp['dividend_rate']
    spot = tmp['spot']
    options = tmp['options']

    v0 = .02

    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 = 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')
示例#2
0
def bates_calibration(df_option, dtTrade=None, df_rates=None, ival=None):

    # array of option helpers
    hh = heston_helpers(df_option, dtTrade, df_rates, ival)
    options = hh['options']
    spot = hh['spot']

    risk_free_ts = dfToZeroCurve(df_rates['R'], dtTrade)
    dividend_ts = dfToZeroCurve(df_rates['D'], dtTrade)

    v0 = .02

    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 = 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')
示例#3
0
def bates_calibration(df_option, ival=None):

    """
    calibrate bates' model
    """

    tmp = make_helpers(df_option)

    risk_free_ts = tmp['risk_free_rate']
    dividend_ts = tmp['dividend_rate']
    spot = tmp['spot']
    options = tmp['options']

    v0 = .02

    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 = 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')
示例#4
0
def bates_calibration(df_option, dtTrade=None, df_rates=None, ival=None):

    # array of option helpers
    hh = heston_helpers(df_option, dtTrade, df_rates, ival)
    options = hh['options']
    spot = hh['spot']

    risk_free_ts = dfToZeroCurve(df_rates['R'], dtTrade)
    dividend_ts = dfToZeroCurve(df_rates['D'], dtTrade)

    v0 = .02
    
    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 = 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')
示例#5
0
    def test_batest_process(self):
        pb = BatesProcess(self.risk_free_ts, self.dividend_ts, self.s0,
                          self.v0, self.kappa, self.theta, self.sigma,
                          self.rho, self.Lambda, self.nu, self.delta)

        self.assertIsNotNone(pb)

        mb = BatesModel(pb)

        self.assertIsNotNone(mb)
示例#6
0
    def test_simulate_bates(self):

        model = BatesModel(self.bates_process)

        paths = 4
        steps = 10
        horizon = 1
        seed = 12345

        res = simulate_model(model, paths, steps, horizon, seed)

        time = res[0, :]
        time_expected = np.arange(0, 1.1, .1)
        simulations = res[1:, :].T

        np.testing.assert_array_almost_equal(time, time_expected, decimal=4)
示例#7
0
plot(time, simulations)
show()

ival = {
    'v0': v0,
    'kappa': 3.7,
    'theta': v0,
    'sigma': 1.0,
    'rho': -.6,
    'lambda': .1,
    'nu': -.5,
    'delta': 0.3
}

spot = SimpleQuote(1200)

proc_bates = BatesProcess(risk_free_ts, dividend_ts, spot, ival['v0'],
                          ival['kappa'], ival['theta'], ival['sigma'],
                          ival['rho'], ival['lambda'], ival['nu'],
                          ival['delta'])

model_bates = BatesModel(proc_bates)

res_bates = simulateBates(model_bates, paths, steps, horizon, seed)

time = res_bates[0, :]
simulations = res_bates[1:, :].T
figure()
plot(time, simulations)
show()