コード例 #1
0
        continue
    key_date = datetime.date(evalDate.year(), evalDate.month(), evalDate.dayOfMonth())
    maturity_dates = to_dt_dates(expiration_dates)
    svi_dataset =  cal_vols, put_vols, maturity_dates, spot, rf_months
    daily_svi_dataset.update({key_date:svi_dataset})
    dividend_ts = ql.YieldTermStructureHandle(ql.FlatForward(evalDate, 0.0, daycounter))
    month_indexs = wind_data.get_contract_months(evalDate)
    params_months = []
    for i in range(4):
        nbr_month = month_indexs[i]
        data = data_months.get(i)
        logMoneynesses = data[0]
        totalvariance = data[1]
        expiration_date = data[2]
        ttm = daycounter.yearFraction(evalDate, expiration_date)
        params = svi_util.get_svi_optimal_params(data, ttm, 30)
        params_months.append(params)

    daily_params.update({key_date:params_months})
    dates.append(key_date)
    print('Finished : ',evalDate)
    print(params_months[0])
    print(params_months[1])
    print(params_months[2])
    print(params_months[3])

#print(daily_params)
timebreak1 = timeit.default_timer()
print('calibration time : ',timebreak1-start)
print('daily_params = ',daily_params)
print('daily_svi_dataset = ',daily_svi_dataset)
コード例 #2
0
            svi_data.update_data(mdate, strike, moneyness, implied_vol, ttm,
                                 totalvariance, close, open_price, spot, volum)
        svi_dataset.update({to_dt_date(evalDate): svi_data})

    calibrered_params = {}
    for mdate in svi_data.dataSet.keys():
        optimization_data = []
        data_mdate = svi_data.dataSet.get(mdate)
        logMoneynesses = data_mdate.moneyness
        totalvariance = data_mdate.totalvariance
        vol = data_mdate.volatility
        #print('vols : ',vol)
        optimization_data.append(logMoneynesses)
        optimization_data.append(data_mdate.totalvariance)
        ttm = data_mdate.ttm
        params = svi_util.get_svi_optimal_params(optimization_data, ttm, 1)
        #print('params : ',params)
        calibrered_params.update({mdate: params})
        a_star, b_star, rho_star, m_star, sigma_star = params
        x_svi = np.arange(
            min(logMoneynesses) - 0.005,
            max(logMoneynesses) + 0.02, 0.1 / 100)  # log_forward_moneyness
        tv_svi = np.multiply(
            a_star + b_star *
            (rho_star *
             (x_svi - m_star) + np.sqrt((x_svi - m_star)**2 + sigma_star**2)),
            ttm)
        vol_svi = np.sqrt(a_star + b_star *
                          (rho_star * (x_svi - m_star) + np.sqrt(
                              (x_svi - m_star)**2 + sigma_star**2)))
        #plt.figure()