Пример #1
0
def batesdoubleexp_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 = df_to_zero_curve(df_rates['R'], dtTrade)
    dividend_ts = df_to_zero_curve(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 = 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)

    return merge_df(df_option, options, 'BatesDoubleExp')
Пример #2
0
def batesdoubleexp_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 = df_to_zero_curve(df_rates['R'], dtTrade)
    dividend_ts = df_to_zero_curve(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 = 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)

    return merge_df(df_option, options, 'BatesDoubleExp')
Пример #3
0
    def test_heston_process(self):

        ph = HestonProcess(self.risk_free_ts, self.dividend_ts, self.s0,
                           self.v0, self.kappa, self.theta, self.sigma,
                           self.rho)
        self.assertIsNotNone(ph)

        # constructor with default arguments
        me = BatesDoubleExpModel(ph)
        self.assertIsNotNone(me)

        # specify the arguments
        me = BatesDoubleExpModel(ph,
                                 Lambda=0.234,
                                 nuUp=0.43,
                                 nuDown=0.54,
                                 p=.6)
        self.assertIsNotNone(me)
Пример #4
0
    def test_simulate_batesDoubleExpModel(self):

        model = BatesDoubleExpModel(self.heston_process)

        paths = 4
        steps = 10
        horizon = 1
        seed = 12345
        tolerance = 1.e-3

        res = simulateBatesDoubleExpModel(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)